@Override public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) { if(stack.getTagCompound() != null && stack.getTagCompound().hasKey(TAG_ITEMS)) { NBTTagList oldData = stack.getTagCompound().getTagList(TAG_ITEMS, Constants.NBT.TAG_COMPOUND); IItemHandler newInv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(newInv, null, oldData); stack.getTagCompound().removeTag(TAG_ITEMS); if(stack.getTagCompound().getSize() == 0) stack.setTagCompound(null); } }
@Override public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) { if(stack.getTagCompound() != null && stack.getTagCompound().hasKey(TAG_ITEMS)) { NBTTagList oldData = stack.getTagCompound().getTagList(TAG_ITEMS, Constants.NBT.TAG_COMPOUND); IItemHandler newInv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(newInv, null, oldData); stack.getTagCompound().removeTag(TAG_ITEMS); if(stack.getTagCompound().getSize() == 0) stack.setTagCompound(null); } }
if(logic.spawnData.getNbt().getSize() == 1 && logic.spawnData.getNbt().hasKey("id", 8) && entity instanceof EntityLiving) { if(!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entityliving, logic.getSpawnerWorld(), (float) entity.posX, (float) entity.posY, (float) entity.posZ)) ((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData) null);
@Override public boolean isNull(ValueNbt a) { return a.getRawValue().getSize() == 0; }
@Override public ValueTypeString.ValueString get(int index) throws EvaluationException { if (index < tag.getSize()) { return ValueTypeString.ValueString.of(Iterables.get(tag.getKeySet(), index)); } return null; }
public static boolean hasTagCompund(ItemStack held) { return held.hasTagCompound() && held.getTagCompound().getSize() > 0; } }
/** * Returns a normalized NBT tag compound for information from a source. * * @param informationNbt a source NBT compound * @return normalized information NBT compound */ private static final NBTTagCompound sortInformationTag(NBTTagCompound informationNbt) { ArrayList<Pair<String, Long>> sortedInformationList = new ArrayList<>(informationNbt.getSize()); for (String key : informationNbt.getKeySet()) { sortedInformationList.add( Pair.of(key, FixedPointUtils.getFixedFromNBT(informationNbt, key)) ); } Collections.sort(sortedInformationList, (o1, o2) -> o1.getKey().compareTo(o2.getKey())); NBTTagCompound newInformationTag = new NBTTagCompound(); for( Pair<String, Long> entry : sortedInformationList ) { FixedPointUtils.setFixedToNBT(newInformationTag, entry.getKey(), entry.getValue()); } return newInformationTag; }
if (input.getTagCompound().getSize() == 0) {