use of net.minecraft.nbt.NBTTagByte in project LogisticsPipes by RS485.
the class DebugHelper method addNBTToTree.
private void addNBTToTree(NBTBase nbt, DefaultMutableTreeNode node) throws SecurityException, IllegalArgumentException {
if (nbt == null) {
return;
}
if (nbt instanceof NBTTagByte) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByte");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagByte) nbt).getByte()));
node.add(type);
} else if (nbt instanceof NBTTagByteArray) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByteArray");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
int i = 0;
for (byte byt : ((NBTTagByteArray) nbt).getByteArray()) {
content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
i++;
}
node.add(content);
node.add(type);
} else if (nbt instanceof NBTTagDouble) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagDouble");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagDouble) nbt).getDouble()));
node.add(type);
} else if (nbt instanceof NBTTagFloat) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagFloat");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagFloat) nbt).getFloat()));
node.add(type);
} else if (nbt instanceof NBTTagInt) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagInt");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagInt) nbt).getInt()));
node.add(type);
} else if (nbt instanceof NBTTagIntArray) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagIntArray");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
int i = 0;
for (int byt : ((NBTTagIntArray) nbt).getIntArray()) {
content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
i++;
}
type.add(content);
node.add(type);
} else if (nbt instanceof NBTTagList) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagList");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
int i = 0;
for (NBTBase object : (NBTTagList) nbt) {
DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode("[" + i + "]");
addNBTToTree(object, nbtNode);
content.add(nbtNode);
i++;
}
type.add(content);
node.add(type);
} else if (nbt instanceof NBTTagCompound) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagCompound");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
for (String key : ((NBTTagCompound) nbt).getKeySet()) {
NBTBase value = ((NBTTagCompound) nbt).getTag(key);
DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode(key);
addNBTToTree(value, nbtNode);
content.add(nbtNode);
}
type.add(content);
node.add(type);
} else if (nbt instanceof NBTTagLong) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagLong");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagLong) nbt).getLong()));
node.add(type);
} else if (nbt instanceof NBTTagShort) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagShort");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagShort) nbt).getShort()));
node.add(type);
} else if (nbt instanceof NBTTagString) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagString");
type.add(new DefaultMutableTreeNode("Data: '" + ((NBTTagString) nbt).getString() + "'"));
node.add(type);
} else {
throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
}
}
use of net.minecraft.nbt.NBTTagByte in project LogisticsPipes by RS485.
the class ItemIdentifier method getNBTBaseAsMap.
@SuppressWarnings("rawtypes")
public static Map<Object, Object> getNBTBaseAsMap(NBTBase nbt) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
if (nbt == null) {
return null;
}
if (nbt instanceof NBTTagByte) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagByte");
map.put("value", ((NBTTagByte) nbt).func_150290_f());
return map;
} else if (nbt instanceof NBTTagByteArray) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagByteArray");
map.put("value", ItemIdentifier.getArrayAsMap(((NBTTagByteArray) nbt).func_150292_c()));
return map;
} else if (nbt instanceof NBTTagDouble) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagDouble");
map.put("value", ((NBTTagDouble) nbt).func_150286_g());
return map;
} else if (nbt instanceof NBTTagFloat) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagFloat");
map.put("value", ((NBTTagFloat) nbt).func_150288_h());
return map;
} else if (nbt instanceof NBTTagInt) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagInt");
map.put("value", ((NBTTagInt) nbt).func_150287_d());
return map;
} else if (nbt instanceof NBTTagIntArray) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagIntArray");
map.put("value", ItemIdentifier.getArrayAsMap(((NBTTagIntArray) nbt).func_150302_c()));
return map;
} else if (nbt instanceof NBTTagList) {
List internal = ((NBTTagList) nbt).tagList;
HashMap<Integer, Object> content = new HashMap<>();
int i = 1;
for (Object object : internal) {
if (object instanceof NBTBase) {
content.put(i, ItemIdentifier.getNBTBaseAsMap((NBTBase) object));
}
i++;
}
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagList");
map.put("value", content);
return map;
} else if (nbt instanceof NBTTagCompound) {
Map internal = ((NBTTagCompound) nbt).tagMap;
HashMap<Object, Object> content = new HashMap<>();
HashMap<Integer, Object> keys = new HashMap<>();
int i = 1;
for (Object object : internal.entrySet()) {
Entry e = (Entry) object;
if (e.getValue() instanceof NBTBase) {
content.put(e.getKey(), ItemIdentifier.getNBTBaseAsMap((NBTBase) e.getValue()));
keys.put(i, e.getKey());
}
i++;
}
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagCompound");
map.put("value", content);
map.put("keys", keys);
return map;
} else if (nbt instanceof NBTTagLong) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagLong");
map.put("value", ((NBTTagLong) nbt).func_150291_c());
return map;
} else if (nbt instanceof NBTTagShort) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagShort");
map.put("value", ((NBTTagShort) nbt).func_150287_d());
return map;
} else if (nbt instanceof NBTTagString) {
HashMap<Object, Object> map = new HashMap<>();
map.put("type", "NBTTagString");
map.put("value", ((NBTTagString) nbt).func_150285_a_());
return map;
} else {
throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
}
}
use of net.minecraft.nbt.NBTTagByte in project LogisticsPipes by RS485.
the class DebugHelper method addNBTToTree.
@SuppressWarnings("rawtypes")
private void addNBTToTree(NBTBase nbt, DefaultMutableTreeNode node) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
if (nbt == null) {
return;
}
if (nbt instanceof NBTTagByte) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByte");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagByte) nbt).func_150290_f()));
node.add(type);
} else if (nbt instanceof NBTTagByteArray) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByteArray");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
int i = 0;
for (byte byt : ((NBTTagByteArray) nbt).func_150292_c()) {
content.add(new DefaultMutableTreeNode("[" + i + "]: " + Byte.toString(byt)));
i++;
}
node.add(content);
node.add(type);
} else if (nbt instanceof NBTTagDouble) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagDouble");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagDouble) nbt).func_150286_g()));
node.add(type);
} else if (nbt instanceof NBTTagFloat) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagFloat");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagFloat) nbt).func_150288_h()));
node.add(type);
} else if (nbt instanceof NBTTagInt) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagInt");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagInt) nbt).func_150287_d()));
node.add(type);
} else if (nbt instanceof NBTTagIntArray) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagIntArray");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
int i = 0;
for (int byt : ((NBTTagIntArray) nbt).func_150302_c()) {
content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
i++;
}
type.add(content);
node.add(type);
} else if (nbt instanceof NBTTagList) {
List internal = ((NBTTagList) nbt).tagList;
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagList");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
int i = 0;
for (Object object : internal) {
if (object instanceof NBTBase) {
DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode("[" + i + "]");
addNBTToTree((NBTBase) object, nbtNode);
content.add(nbtNode);
i++;
}
}
type.add(content);
node.add(type);
} else if (nbt instanceof NBTTagCompound) {
Map internal = ((NBTTagCompound) nbt).tagMap;
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagCompound");
DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
for (Object objectKey : internal.keySet()) {
if (internal.get(objectKey) instanceof NBTBase) {
DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode(objectKey);
addNBTToTree((NBTBase) internal.get(objectKey), nbtNode);
content.add(nbtNode);
}
}
type.add(content);
node.add(type);
} else if (nbt instanceof NBTTagLong) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagLong");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagLong) nbt).func_150291_c()));
node.add(type);
} else if (nbt instanceof NBTTagShort) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagShort");
type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagShort) nbt).func_150289_e()));
node.add(type);
} else if (nbt instanceof NBTTagString) {
DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagString");
type.add(new DefaultMutableTreeNode("Data: '" + ((NBTTagString) nbt).func_150285_a_() + "'"));
node.add(type);
} else {
throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
}
}
use of net.minecraft.nbt.NBTTagByte in project SpongeCommon by SpongePowered.
the class NbtTranslator method fromTagBase.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object fromTagBase(NBTBase base, byte type) {
switch(type) {
case NbtDataUtil.TAG_BYTE:
return ((NBTTagByte) base).getByte();
case NbtDataUtil.TAG_SHORT:
return (((NBTTagShort) base)).getShort();
case NbtDataUtil.TAG_INT:
return ((NBTTagInt) base).getInt();
case NbtDataUtil.TAG_LONG:
return ((NBTTagLong) base).getLong();
case NbtDataUtil.TAG_FLOAT:
return ((NBTTagFloat) base).getFloat();
case NbtDataUtil.TAG_DOUBLE:
return ((NBTTagDouble) base).getDouble();
case NbtDataUtil.TAG_BYTE_ARRAY:
return ((NBTTagByteArray) base).getByteArray();
case NbtDataUtil.TAG_STRING:
return ((NBTTagString) base).getString();
case NbtDataUtil.TAG_LIST:
NBTTagList list = (NBTTagList) base;
byte listType = (byte) list.getTagType();
int count = list.tagCount();
List objectList = Lists.newArrayListWithCapacity(count);
for (int i = 0; i < list.tagCount(); i++) {
objectList.add(fromTagBase(list.get(i), listType));
}
return objectList;
case NbtDataUtil.TAG_COMPOUND:
return getViewFromCompound((NBTTagCompound) base);
case NbtDataUtil.TAG_INT_ARRAY:
return ((NBTTagIntArray) base).getIntArray();
default:
return null;
}
}
use of net.minecraft.nbt.NBTTagByte in project Charset by CharsetMC.
the class FluidDyedWater method appendDye.
@Nullable
public FluidStack appendDye(FluidStack stack, EnumDyeColor color) {
FluidStack newStack;
if (stack.getFluid() == FluidRegistry.WATER) {
newStack = new FluidStack(this, stack.amount);
} else if (stack.getFluid() == this) {
newStack = stack.copy();
} else {
return null;
}
if (newStack.tag == null) {
newStack.tag = new NBTTagCompound();
}
NBTTagList dyes = newStack.tag.hasKey("dyes", Constants.NBT.TAG_LIST) ? ((NBTTagList) newStack.tag.getTag("dyes")) : new NBTTagList();
if (dyes.tagCount() >= 8) {
return null;
}
dyes.appendTag(new NBTTagByte((byte) color.getMetadata()));
newStack.tag.setTag("dyes", dyes);
return newStack;
}
Aggregations