use of net.minecraft.nbt.NBTBase in project LogisticsPipes by RS485.
the class LogisticsSecurityTileEntity method handleListPacket.
public void handleListPacket(NBTTagCompound tag) {
excludedCC.clear();
NBTTagList list = tag.getTagList("list", 3);
while (list.tagCount() > 0) {
NBTBase base = list.removeTag(0);
excludedCC.add(((NBTTagInt) base).func_150287_d());
}
}
use of net.minecraft.nbt.NBTBase in project PneumaticCraft by MineMaarten.
the class NBTToJsonConverter method getObject.
private JsonObject getObject(NBTTagCompound tag) {
Set<String> keys = tag.func_150296_c();
JsonObject jsonRoot = new JsonObject();
for (String key : keys) {
JsonObject keyObject = new JsonObject();
jsonRoot.add(key, keyObject);
NBTBase nbt = tag.getTag(key);
keyObject.addProperty("type", nbt.getId());
if (nbt instanceof NBTTagCompound) {
keyObject.add("value", getObject((NBTTagCompound) nbt));
} else if (nbt instanceof NBTPrimitive) {
keyObject.addProperty("value", ((NBTPrimitive) nbt).func_150286_g());
} else if (nbt instanceof NBTTagString) {
keyObject.addProperty("value", ((NBTTagString) nbt).func_150285_a_());
} else if (nbt instanceof NBTTagList) {
JsonArray array = new JsonArray();
NBTTagList tagList = (NBTTagList) nbt;
for (int i = 0; i < tagList.tagCount(); i++) {
array.add(getObject(tagList.getCompoundTagAt(i)));
}
keyObject.add("value", array);
} else if (nbt instanceof NBTTagIntArray) {
JsonArray array = new JsonArray();
NBTTagIntArray intArray = (NBTTagIntArray) nbt;
for (int i : intArray.func_150302_c()) {
array.add(new JsonPrimitive(i));
}
keyObject.add("value", array);
} else {
throw new IllegalArgumentException("NBT to JSON converter doesn't support the nbt tag: " + NBTBase.NBTTypes[nbt.getId()] + ", tag: " + nbt);
}
}
return jsonRoot;
}
use of net.minecraft.nbt.NBTBase in project MinecraftForge by MinecraftForge.
the class GameRegistry method makeItemStack.
/**
* Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
* <p/>
* Will return null if the item doesn't exist (because it's not from a loaded mod for example)
* Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
*
* @param itemName a registry name reference
* @param meta the meta
* @param stackSize the stack size
* @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
* @return a new itemstack
*/
@Nonnull
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) {
if (itemName == null) {
throw new IllegalArgumentException("The itemName cannot be null");
}
Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
if (item == null) {
FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
return ItemStack.EMPTY;
}
ItemStack is = new ItemStack(item, stackSize, meta);
if (!Strings.isNullOrEmpty(nbtString)) {
NBTBase nbttag = null;
try {
nbttag = JsonToNBT.getTagFromJson(nbtString);
} catch (NBTException e) {
FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
throw Throwables.propagate(e);
}
if (!(nbttag instanceof NBTTagCompound)) {
FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
throw new RuntimeException("Invalid NBT JSON");
} else {
is.setTagCompound((NBTTagCompound) nbttag);
}
}
return is;
}
use of net.minecraft.nbt.NBTBase in project RFToolsDimensions by McJty.
the class NBTMatchingRecipe method checkMatch.
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting inventoryCrafting, int x, int y, boolean reversed) {
for (int col = 0; col < 3; ++col) {
for (int row = 0; row < 3; ++row) {
int i1 = col - x;
int j1 = row - y;
ItemStack itemstack = ItemStackTools.getEmptyStack();
String[] nbt = null;
if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight) {
int idx;
if (reversed) {
idx = this.recipeWidth - i1 - 1 + j1 * this.recipeWidth;
} else {
idx = i1 + j1 * this.recipeWidth;
}
itemstack = this.recipeItems[idx];
nbt = this.matchingNBTs[idx];
}
ItemStack itemstack1 = inventoryCrafting.getStackInRowAndColumn(col, row);
if (ItemStackTools.isValid(itemstack1) || ItemStackTools.isValid(itemstack)) {
if (ItemStackTools.isEmpty(itemstack1) || ItemStackTools.isEmpty(itemstack)) {
return false;
}
if (itemstack.getItem() != itemstack1.getItem()) {
return false;
}
if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage()) {
return false;
}
NBTTagCompound compound = itemstack.getTagCompound();
NBTTagCompound compound1 = itemstack1.getTagCompound();
if (nbt != null) {
if (compound == null && compound1 != null) {
return false;
}
if (compound != null && compound1 == null) {
return false;
}
if (compound != null) {
for (String tagName : nbt) {
NBTBase tag = compound.getTag(tagName);
NBTBase tag1 = compound1.getTag(tagName);
if (tag == null && tag1 != null) {
return false;
}
if (tag != null && tag1 == null) {
return false;
}
if (tag != null) {
if (!tag.equals(tag1)) {
return false;
}
}
}
}
}
}
}
}
return true;
}
use of net.minecraft.nbt.NBTBase in project ImmersiveEngineering by BluSunrize.
the class CapabilityShader method register.
public static void register() {
CapabilityManager.INSTANCE.register(ShaderWrapper.class, new Capability.IStorage<ShaderWrapper>() {
@Override
public NBTBase writeNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side) {
NBTTagCompound nbt = new NBTTagCompound();
ItemStack shader = instance.getShaderItem();
if (shader != null)
shader.writeToNBT(nbt);
else
nbt.setString("IE:NoShader", "");
nbt.setString("IE:ShaderType", instance.getShaderType());
return nbt;
}
@Override
public void readNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side, NBTBase nbt) {
NBTTagCompound tags = (NBTTagCompound) nbt;
instance.setShaderType(tags.getString("IE:ShaderType"));
if (!tags.hasKey("IE:NoShader"))
instance.setShaderItem(ItemStack.loadItemStackFromNBT(tags));
}
}, new Callable<ShaderWrapper>() {
@Override
public ShaderWrapper call() throws Exception {
return new ShaderWrapper_Direct("");
}
});
}
Aggregations