Java Code Examples for net.minecraft.nbt.NBTTagCompound#getTag()

The following examples show how to use net.minecraft.nbt.NBTTagCompound#getTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(ItemTooltipEvent e) {
    if (e.toolTip.size() > 0 && e.itemStack.hasTagCompound()) {
        if (e.itemStack.stackTagCompound.getBoolean("isStickyJar")) {
            e.toolTip.add(1, "\u00a7a" + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
        }
    }

    if(e.toolTip.size() > 0 && NBTHelper.hasPersistentData(e.itemStack)) {
        NBTTagCompound compound = NBTHelper.getPersistentData(e.itemStack);
        if(compound.hasKey("disguise")) {
            NBTBase base = compound.getTag("disguise");
            String lore;
            if(base instanceof NBTTagCompound) {
                ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base);
                lore = String.format(StatCollector.translateToLocal("gadomancy.lore.disguise.item"), EnumChatFormatting.getTextWithoutFormattingCodes(stack.getDisplayName()));
            } else {
                lore = StatCollector.translateToLocal("gadomancy.lore.disguise.none");
            }
            e.toolTip.add("\u00a7a" + lore);
        }
    }
}
 
Example 2
Source File: SellSign.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Override
public boolean isTileValid(TileEntitySign te) {
    if (!te.signText[0].startsWith(Sign.IDENTIFIER)) {
        return false;
    }

    try {
        NBTTagCompound rootTag = SignClassTransformer.getMyEssentialsDataValue(te);
        if (rootTag == null)
            return false;

        if (!rootTag.getString("Type").equals(SellSignType.instance.getTypeID()))
            return false;

        NBTBase data = rootTag.getTag("Value");
        if (!(data instanceof NBTTagCompound))
            return false;

        NBTTagCompound signData = (NBTTagCompound) data;

        MyTownUniverse.instance.getOrMakeResident(UUID.fromString(signData.getString("Owner")));
        return true;
    } catch (Exception ex) {
        return false;
    }
}
 
Example 3
Source File: ItemArmourStand.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void merge(NBTTagCompound nbt, NBTTagCompound other) {
	Iterator<String> iterator = other.func_150296_c().iterator();

	while (iterator.hasNext()) {
		String s = iterator.next();
		NBTBase nbtbase = other.getTag(s);

		if (nbtbase.getId() == 10) {
			if (nbt.hasKey(s, 10)) {
				NBTTagCompound nbttagcompound1 = nbt.getCompoundTag(s);
				merge(nbttagcompound1, (NBTTagCompound) nbtbase);
			} else
				nbt.setTag(s, nbtbase.copy());
		} else
			nbt.setTag(s, nbtbase.copy());
	}
}
 
Example 4
Source File: LPRoutedFluid.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
public static LPRoutedFluid readFromNBT(NBTTagCompound compound, TileGenericPipe holder) {
	double x = compound.getDouble("posX");
	double y = compound.getDouble("posY");
	double z = compound.getDouble("posZ");
	UUID id = compound.getUniqueId("UID");
	FluidStack content = FluidStack.loadFluidStackFromNBT(compound.getCompoundTag("inventory"));
	int ticks = compound.getInteger("ticks");
	Deque<EnumFacing> routingInfo = new ArrayDeque<>();
	NBTTagList routeList = (NBTTagList) compound.getTag("route");
	for(Iterator<NBTBase> i = routeList.iterator(); i.hasNext();) {
		NBTTagCompound node = (NBTTagCompound) i.next();
		EnumFacing nodeTuple = EnumFacing.values()[node.getInteger("heading")];
		routingInfo.add(nodeTuple);
	}
	LPRoutedFluid item = new LPRoutedFluid(x, y, z, content, ticks, id);
	item.setHeading(EnumFacing.VALUES[compound.getInteger("heading")]);
	item.setHolding(holder);
	item.route = routingInfo;
	return item;
}
 
Example 5
Source File: MappingRegistry.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
private boolean isStackLayout(NBTTagCompound nbt) {
	return nbt.hasKey("id") &&
			nbt.hasKey("Count") &&
			nbt.hasKey("Damage") &&
			nbt.getTag("id") instanceof NBTTagShort &&
			nbt.getTag("Count") instanceof NBTTagByte &&
			nbt.getTag("Damage") instanceof NBTTagShort;
}
 
Example 6
Source File: RenderEventHandler.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void renderEntityPre(RenderLivingEvent.Pre event) {
    if(event.entity instanceof EntityPlayer) {
        EntityPlayer p = (EntityPlayer) event.entity;
        if(((DataAchromatic)SyncDataHolder.getDataClient("AchromaticData")).isAchromatic((EntityPlayer) event.entity)) {
            current = p;
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.15F);
            GL11.glDepthMask(false);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F);
        }

        armor = p.inventory.armorInventory;
        p.inventory.armorInventory = new ItemStack[armor.length];
        System.arraycopy(armor, 0, p.inventory.armorInventory, 0, armor.length);

        boolean changed = false;
        for(int i = 0; i < armor.length; i++) {
            if(armor[i] != null && NBTHelper.hasPersistentData(armor[i])) {
                NBTTagCompound compound = NBTHelper.getPersistentData(armor[i]);
                if(compound.hasKey("disguise")) {
                    NBTBase base = compound.getTag("disguise");
                    if(base instanceof NBTTagCompound) {
                        p.inventory.armorInventory[i] = ItemStack.loadItemStackFromNBT((NBTTagCompound) base);
                    } else {
                        p.inventory.armorInventory[i] = null;
                    }
                    changed = true;
                }
            }
        }

        if(!changed) {
            p.inventory.armorInventory = armor;
            armor = null;
        }
    }
}
 
Example 7
Source File: DataConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Reads an unknown object withPriority a known name from NBT
 * @param tag - tag to read the value from
 * @param key - name of the value
 * @return object or suggestionValue if nothing is found
 */
public Object load(NBTTagCompound tag, String key) {
	if (tag != null && key != null) {
		NBTBase saveTag = tag.getTag(key);

		if (saveTag instanceof NBTTagFloat) {
			return tag.getFloat(key);
		} else if (saveTag instanceof NBTTagDouble) {
			return tag.getDouble(key);
		} else if (saveTag instanceof NBTTagInt) {
			return tag.getInteger(key);
		} else if (saveTag instanceof NBTTagString) {
			if (tag.getBoolean(key + "::nova.isBigInteger")) {
				return new BigInteger(tag.getString(key));
			} else if (tag.getBoolean(key + "::nova.isBigDecimal")) {
				return new BigDecimal(tag.getString(key));
			} else {
				return tag.getString(key);
			}
		} else if (saveTag instanceof NBTTagShort) {
			return tag.getShort(key);
		} else if (saveTag instanceof NBTTagByte) {
			if (tag.getBoolean(key + "::nova.isBoolean")) {
				return tag.getBoolean(key);
			} else {
				return tag.getByte(key);
			}
		} else if (saveTag instanceof NBTTagLong) {
			return tag.getLong(key);
		} else if (saveTag instanceof NBTTagByteArray) {
			return tag.getByteArray(key);
		} else if (saveTag instanceof NBTTagIntArray) {
			return tag.getIntArray(key);
		} else if (saveTag instanceof NBTTagCompound) {
			NBTTagCompound innerTag = tag.getCompoundTag(key);
			return toNova(innerTag);
		}
	}
	return null;
}
 
Example 8
Source File: DataConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Reads an unknown object withPriority a known name from NBT
 * @param tag - tag to read the value from
 * @param key - name of the value
 * @return object or suggestionValue if nothing is found
 */
@Nullable
public Object load(@Nullable NBTTagCompound tag, @Nullable String key) {
	if (tag != null && key != null) {
		NBTBase saveTag = tag.getTag(key);

		if (saveTag instanceof NBTTagFloat) {
			return tag.getFloat(key);
		} else if (saveTag instanceof NBTTagDouble) {
			return tag.getDouble(key);
		} else if (saveTag instanceof NBTTagInt) {
			return tag.getInteger(key);
		} else if (saveTag instanceof NBTTagString) {
			return tag.getString(key);
		} else if (saveTag instanceof NBTTagShort) {
			return tag.getShort(key);
		} else if (saveTag instanceof NBTTagByte) {
			if (tag.getBoolean("isBoolean")) {
				return tag.getBoolean(key);
			} else {
				return tag.getByte(key);
			}
		} else if (saveTag instanceof NBTTagLong) {
			return tag.getLong(key);
		} else if (saveTag instanceof NBTTagByteArray) {
			return tag.getByteArray(key);
		} else if (saveTag instanceof NBTTagIntArray) {
			return tag.getIntArray(key);
		} else if (saveTag instanceof NBTTagCompound) {
			NBTTagCompound innerTag = tag.getCompoundTag(key);
			return toNova(innerTag);
		}
	}
	return null;
}
 
Example 9
Source File: TileEntityCoordTransporter.java    From ModdingTutorials with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);
	
	teleports = new ArrayList<CoordEntry>();
	
	NBTTagList entryList = (NBTTagList) compound.getTag("teleports");
	for(int i = 0; i < entryList.tagCount(); i++)
	{
		NBTTagCompound entryCompound = entryList.getCompoundTagAt(i);
		CoordEntry entry = CoordEntry.readEntryFromNBT(entryCompound);
		teleports.add(entry);
	}
}
 
Example 10
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
public void readEntityFromNBT(NBTTagCompound root) {
  super.readEntityFromNBT(root);
  if(!root.hasKey("cats")) {
    return;
  }
  NBTTagList catsList = (NBTTagList) root.getTag("cats");
  loadedCats = new ArrayList<NBTTagCompound>(catsList.tagCount());
  for (int i = 0; i < catsList.tagCount(); i++) {
    NBTTagCompound catRoot = catsList.getCompoundTagAt(i);
    if(catRoot != null) {
      loadedCats.add(catRoot);
    }
  }
}
 
Example 11
Source File: CommandNbt.java    From AgriCraft with MIT License 5 votes vote down vote up
private void getNbt(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull NBTTagCompound tag, @Nonnull String key) throws CommandException {
    if (tag.hasKey(key)) {
        final NBTBase entry = tag.getTag(key);
        final String type = NBTBase.NBT_TYPES[entry.getId()];
        MessageUtil.messagePlayer(player, "`l`3{0}`r `b{1}`r: `2{2}`r", type, key, entry);
    } else {
        throw new CommandException("Active player stack does not have NBT tag: \"%s\"!", key);
    }
}
 
Example 12
Source File: TerminalUtils.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
public static Long extractGuid(NBTTagCompound tag) {
	NBTBase guidTag = tag.getTag("guid");
	if (guidTag instanceof NBTTagString) {
		String value = ((NBTTagString)guidTag).func_150285_a_();
		return Long.parseLong(value.toLowerCase(), 36);
	} else if (guidTag instanceof NBTTagLong) return ((NBTPrimitive)guidTag).func_150291_c();

	return null;
}
 
Example 13
Source File: TileEntityBackpack.java    From WearableBackpacks with MIT License 5 votes vote down vote up
public void readNBT(NBTTagCompound compound, boolean isClient) {
	_age = (!isClient ? compound.getInteger(TAG_AGE) : 0);
	facing = EnumFacing.byIndex(NbtUtils.get(compound, (byte)0, TAG_FACING) + 2);
	
	_stack = NbtUtils.readItem(compound.getCompoundTag(TAG_STACK));
	if (_stack.isEmpty() || isClient) { _data = null; return; }
	
	_data = BackpackHelper.getBackpackType(_stack).createBackpackData(_stack);
	NBTBase dataTag = compound.getTag(TAG_DATA);
	if (dataTag != null) _data.deserializeNBT(dataTag);
	
	_despawnTimer = (compound.hasKey(TAG_DESPAWN_TIMER)
		? compound.getInteger(TAG_DESPAWN_TIMER) : -1);
}
 
Example 14
Source File: BackpackCapability.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound compound) {
	backpack.stack = NbtUtils.readItem(compound.getCompoundTag(TAG_STACK));
	
	IBackpackType type;
	if (backpack.stack.isEmpty()) {
		if (!compound.hasKey(TAG_TYPE, NbtType.STRING)) return;
		// If the backpack has its type saved, restore it.
		// This is the case when the backpack stack is equipped in
		// the chest armor slot, which has not yet been loaded. :'(
		String id = compound.getString(TAG_TYPE);
		backpack.lastType = type = BackpackHelper.getBackpackType(MiscUtils.getItemFromName(id));
		if (type == null) return;
	} else type = BackpackHelper.getBackpackType(backpack.stack);
	
	if (type == null) {
		WearableBackpacks.LOG.error("Backpack type was null when deserializing backpack capability");
		return;
	}
	
	backpack.data = type.createBackpackData(backpack.getStack());
	NBTBase dataTag = compound.getTag(TAG_DATA);
	if ((backpack.data != null) && (dataTag != null))
		backpack.data.deserializeNBT(dataTag);
	
	backpack.mayDespawn = compound.getBoolean(TAG_MAY_DESPAWN);
}
 
Example 15
Source File: MappingRegistry.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
public void scanAndTranslateStacksToRegistry(NBTTagCompound nbt) {
	// First, check if this nbt is itself a stack

	if (isStackLayout(nbt)) {
		stackToRegistry(nbt);
	}

	// Then, look at the nbt compound contained in this nbt (even if it's a
	// stack) and checks for stacks in it.
	for (Object keyO : nbt.func_150296_c()) {
		String key = (String) keyO;

		if (nbt.getTag(key) instanceof NBTTagCompound) {
			scanAndTranslateStacksToRegistry(nbt.getCompoundTag(key));
		}

		if (nbt.getTag(key) instanceof NBTTagList) {
			NBTTagList list = (NBTTagList) nbt.getTag(key);

			if (list.func_150303_d() == Constants.NBT.TAG_COMPOUND) {
				for (int i = 0; i < list.tagCount(); ++i) {
					scanAndTranslateStacksToRegistry(list.getCompoundTagAt(i));
				}
			}
		}
	}
}
 
Example 16
Source File: GolemUpgrade.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected T getUpgradeData(NBTTagCompound compound) {
    if(compound.hasKey(UPGRADE_COMPOUND)) {
        NBTTagCompound upgrades = compound.getCompoundTag(UPGRADE_COMPOUND);
        try {
            return (T) upgrades.getTag(getTagName());
        } catch (ClassCastException ignored) {}
    }
    return null;
}
 
Example 17
Source File: SpellData.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound nbt) {
	for (String key : nbt.getKeySet()) {
		DataField<?> field = availableFields.get(key);
		if (field != null) {
			NBTBase nbtType = nbt.getTag(key);
			data.put(field, field.getDataTypeProcess().deserialize(nbtType));
		}
	}
}
 
Example 18
Source File: NBTHelper.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean hasPersistentData(NBTTagCompound base) {
    NBTBase modData = base.getTag(Gadomancy.MODID);
    return modData != null && modData instanceof NBTTagCompound;
}
 
Example 19
Source File: CyberwareUserDataImpl.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound tag)
{
	powerBuffer = readMap((NBTTagList) tag.getTag("powerBuffer"));
	powerCap = tag.getInteger("powerCap");
	powerBufferLast = readMap((NBTTagList) tag.getTag("powerBufferLast"));

	storedPower = tag.getInteger("storedPower");
	if (tag.hasKey("essence"))
	{
		missingEssence = getMaxEssence() - tag.getInteger("essence");
	}
	else
	{
		missingEssence = tag.getInteger("missingEssence");
	}
	hudData = tag.getCompoundTag("hud");
	hasOpenedRadialMenu = tag.getBoolean("hasOpenedRadialMenu");
	NBTTagList essentialList = (NBTTagList) tag.getTag("discard");
	for (int i = 0; i < essentialList.tagCount(); i++)
	{
		this.missingEssentials[i] = ((NBTTagByte) essentialList.get(i)).getByte() > 0;
	}
	
	NBTTagList list = (NBTTagList) tag.getTag("cyberware");
	for (int i = 0; i < list.tagCount(); i++)
	{
		EnumSlot slot = EnumSlot.values()[i];
		
		NBTTagList list2 = (NBTTagList) list.get(i);
		ItemStack[] cyberware = new ItemStack[LibConstants.WARE_PER_SLOT];

		for (int j = 0; j < list2.tagCount() && j < cyberware.length; j++)
		{
			
			cyberware[j] = ItemStack.loadItemStackFromNBT(list2.getCompoundTagAt(j));
		}
		
		setInstalledCyberware(null, slot, cyberware);
	}
	
	int color = 0x00FFFF;

	if (tag.hasKey("color"))
	{
		color = tag.getInteger("color");
	}
	this.setHudColor(color);


	updateCapacity();
}
 
Example 20
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void on(TickEvent.WorldTickEvent event) {
    if(event.phase == TickEvent.Phase.START && !event.world.isRemote && event.world.getTotalWorldTime() % 10 == 0) {

        Iterator<Map.Entry<EntityItem, Long>> iterator = trackedItems.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry<EntityItem, Long> entry = iterator.next();
            EntityItem entity = entry.getKey();

            if(event.world == entity.worldObj) {
                if(entity.isDead || !isDisguised(entity.getEntityItem())) {
                    iterator.remove();
                    continue;
                }

                int x = MathHelper.floor_double(entity.posX);
                int y = MathHelper.floor_double(entity.posY);
                int z = MathHelper.floor_double(entity.posZ);

                if(entity.delayBeforeCanPickup <= 0 && entity.worldObj.getTotalWorldTime() - entry.getValue() > 0) {
                    if(ConfigBlocks.blockFluidPure == event.world.getBlock(x, y, z)
                            && event.world.getBlockMetadata(x, y, z) == 0) {
                        NBTTagCompound compound = NBTHelper.getPersistentData(entity.getEntityItem());
                        NBTBase base = compound.getTag("disguise");
                        if(base instanceof NBTTagCompound) {
                            ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base);
                            EntityItem newEntity = new EntityItem(event.world, entity.posX, entity.posY, entity.posZ, stack);
                            ItemUtils.applyRandomDropOffset(newEntity, event.world.rand);
                            event.world.spawnEntityInWorld(newEntity);
                        }
                        compound.removeTag("disguise");
                        if(compound.hasNoTags()) {
                            NBTHelper.removePersistentData(entity.getEntityItem());
                            if(entity.getEntityItem().getTagCompound().hasNoTags()) {
                                entity.getEntityItem().setTagCompound(null);
                            }
                        }
                        event.world.setBlockToAir(x, y, z);
                    }
                } else {
                    Gadomancy.proxy.spawnBubbles(event.world, (float)entity.posX, (float)entity.posY, (float)entity.posZ, 0.2f);
                }
            }
        }
    }
}