2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.common.network;
|
2013-12-06 08:11:03 +00:00
|
|
|
|
2014-01-16 14:14:26 +00:00
|
|
|
import java.io.IOException;
|
2017-07-13 04:50:28 +00:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2017-05-18 20:47:13 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-01-16 14:14:26 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.PacketBuffer;
|
2017-05-18 20:47:13 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2017-06-19 22:02:18 +00:00
|
|
|
import net.minecraftforge.registries.ForgeRegistry;
|
|
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
|
|
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
|
|
|
import net.minecraftforge.registries.RegistryManager;
|
|
|
|
|
2013-12-06 08:11:03 +00:00
|
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2017-01-11 23:17:56 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-05-18 20:47:13 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2017-01-11 23:17:56 +00:00
|
|
|
|
2014-01-16 14:14:26 +00:00
|
|
|
/**
|
|
|
|
* Utilities for interacting with {@link ByteBuf}.
|
|
|
|
* @author cpw
|
|
|
|
*
|
|
|
|
*/
|
2013-12-06 08:11:03 +00:00
|
|
|
public class ByteBufUtils {
|
2017-05-18 20:47:13 +00:00
|
|
|
|
2014-01-20 22:29:17 +00:00
|
|
|
public static String getContentDump(ByteBuf buffer)
|
|
|
|
{
|
|
|
|
int currentLength = buffer.readableBytes();
|
|
|
|
StringBuffer returnString = new StringBuffer((currentLength * 3) + // The
|
|
|
|
// hex
|
|
|
|
(currentLength) + // The ascii
|
|
|
|
(currentLength / 4) + // The tabs/\n's
|
|
|
|
30); // The text
|
|
|
|
|
|
|
|
// returnString.append("Buffer contents:\n");
|
|
|
|
int i, j; // Loop variables
|
|
|
|
for (i = 0; i < currentLength; i++)
|
|
|
|
{
|
|
|
|
if ((i != 0) && (i % 16 == 0))
|
|
|
|
{
|
|
|
|
// If it's a multiple of 16 and i isn't null, show the ascii
|
|
|
|
returnString.append('\t');
|
|
|
|
for (j = i - 16; j < i; j++)
|
|
|
|
{
|
|
|
|
if (buffer.getByte(j) < 0x20 || buffer.getByte(j) > 0x7F)
|
|
|
|
returnString.append('.');
|
|
|
|
else
|
|
|
|
returnString.append((char) buffer.getByte(j));
|
|
|
|
}
|
|
|
|
// Add a linefeed after the string
|
|
|
|
returnString.append("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
returnString.append(Integer.toString((buffer.getByte(i) & 0xF0) >> 4, 16) + Integer.toString((buffer.getByte(i) & 0x0F) >> 0, 16));
|
|
|
|
returnString.append(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add padding spaces if it's not a multiple of 16
|
|
|
|
if (i != 0 && i % 16 != 0)
|
|
|
|
{
|
|
|
|
for (j = 0; j < ((16 - (i % 16)) * 3); j++)
|
|
|
|
{
|
|
|
|
returnString.append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add the tab for alignment
|
|
|
|
returnString.append('\t');
|
|
|
|
|
2016-03-23 14:34:48 +00:00
|
|
|
// Add final characters at right, after padding
|
2014-01-20 22:29:17 +00:00
|
|
|
|
|
|
|
// If it was at the end of a line, print out the full line
|
|
|
|
if (i > 0 && (i % 16) == 0)
|
|
|
|
{
|
|
|
|
j = i - 16;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
j = (i - (i % 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i >= 0 && j < i; j++)
|
|
|
|
{
|
|
|
|
if (buffer.getByte(j) < 0x20 || buffer.getByte(j) > 0x7F)
|
|
|
|
returnString.append('.');
|
|
|
|
else
|
|
|
|
returnString.append((char) buffer.getByte(j));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, tidy it all up with a newline
|
|
|
|
returnString.append('\n');
|
|
|
|
returnString.append("Length: " + currentLength);
|
|
|
|
|
|
|
|
return returnString.toString();
|
|
|
|
|
|
|
|
}
|
2013-12-06 08:11:03 +00:00
|
|
|
}
|