Java Code Examples for net.minecraft.nbt.NBTTagCompound#getShort()
The following examples show how to use
net.minecraft.nbt.NBTTagCompound#getShort() .
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: EntityStationDeployedRocket.java From AdvancedRocketry with MIT License | 6 votes |
@Override public void useNetworkData(EntityPlayer player, Side side, byte id, NBTTagCompound nbt) { if(id == PacketType.MENU_CHANGE.ordinal()) { DimensionProperties props = DimensionManager.getEffectiveDimId(world, this.getPosition()); if(props.isGasGiant()) { gasId = nbt.getShort("gas"); if(gasId < 0) gasId = (short)(props.getHarvestableGasses().size() - 1); else if(gasId > props.getHarvestableGasses().size() - 1) gasId = 0; if(!world.isRemote) PacketHandler.sendToNearby(new PacketEntity(this, (byte) PacketType.MENU_CHANGE.ordinal()), world.provider.getDimension(), (int)posX, (int)posY, (int)posZ, 64d); else atmText.setText(props.getHarvestableGasses().get(gasId).getLocalizedName(new FluidStack(AtmosphereRegister.getInstance().getHarvestableGasses().get(gasId),1))); } } else super.useNetworkData(player, side, id, nbt); }
Example 2
Source File: ModuleVanilla.java From OpenPeripheral-Integration with MIT License | 6 votes |
public static Object listEnchantments(NBTTagList ench) { List<Map<String, Object>> response = Lists.newArrayList(); for (int i = 0; i < ench.tagCount(); ++i) { NBTTagCompound enchTag = ench.getCompoundTagAt(i); short id = enchTag.getShort("id"); short lvl = enchTag.getShort("lvl"); final Enchantment enchantment = Enchantment.enchantmentsList[id]; if (enchantment != null) { Map<String, Object> entry = Maps.newHashMap(); entry.put("name", enchantment.getName()); entry.put("level", lvl); entry.put("fullName", enchantment.getTranslatedName(lvl)); response.add(entry); } } return response; }
Example 3
Source File: ItemAirUtils.java From AdvancedRocketry with MIT License | 6 votes |
public boolean isStackValidAirContainer(ItemStack stack) { if(stack == null) return false; //Check for enchantment boolean isEnchanted = false; NBTTagList enchList = stack.getEnchantmentTagList(); if(enchList != null) { for(int i = 0 ; i < enchList.tagCount(); i++) { NBTTagCompound compound = enchList.getCompoundTagAt(i); isEnchanted = compound.getShort("id") == Enchantment.getEnchantmentID(AdvancedRocketryAPI.enchantmentSpaceProtection); if(isEnchanted) break; } } return isEnchanted; }
Example 4
Source File: PlacementProperties.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
public int getPropertyValue(UUID uuid, ItemType itemType, String key, Integer valueType) { NBTTagCompound tag = this.getPropertyTag(uuid, itemType); if (tag != null) { switch (valueType) { case Constants.NBT.TAG_BYTE: return ((int) tag.getByte(key)) & 0xFF; case Constants.NBT.TAG_SHORT: return ((int) tag.getShort(key)) & 0xFFFF; case Constants.NBT.TAG_INT: return tag.getInteger(key); } } return 0; }
Example 5
Source File: EntityItemAbducted.java From AdvancedRocketry with MIT License | 6 votes |
/** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound p_70037_1_) { this.age = p_70037_1_.getShort("Age"); NBTTagCompound nbttagcompound1 = p_70037_1_.getCompoundTag("Item"); this.setEntityItemStack(new ItemStack(nbttagcompound1)); ItemStack item = (ItemStack)(this.getDataManager().get(ITEM)); if (item == null || item.getCount() <= 0) { this.setDead(); } if (p_70037_1_.hasKey("Lifespan")) { lifespan = p_70037_1_.getInteger("Lifespan"); } }
Example 6
Source File: EntityREP.java From WirelessRedstone with MIT License | 5 votes |
public void readEntityFromNBT(NBTTagCompound tag) { xTileREP = tag.getShort("xTile"); yTileREP = tag.getShort("yTile"); zTileREP = tag.getShort("zTile"); inTileREP = Block.getBlockById(tag.getShort("inTile") & 0xFFFF); shakeREP = tag.getByte("shake") & 0xff; inGroundREP = tag.getByte("inGround") == 1; }
Example 7
Source File: EntityLaser.java From Electro-Magic-Tools with GNU General Public License v3.0 | 5 votes |
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { this.xTile = par1NBTTagCompound.getShort("xTile"); this.yTile = par1NBTTagCompound.getShort("yTile"); this.zTile = par1NBTTagCompound.getShort("zTile"); this.inTile = Block.getBlockById(par1NBTTagCompound.getByte("inTile") & 255); this.inData = par1NBTTagCompound.getByte("inData") & 255; this.inGround = par1NBTTagCompound.getByte("inGround") == 1; }
Example 8
Source File: TileEntityCompostBin.java From GardenCollection with MIT License | 5 votes |
@Override public void readFromNBT (NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList tagList = tag.getTagList("Items", 10); compostItemStacks = new ItemStack[getSizeInventory()]; for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound itemTag = tagList.getCompoundTagAt(i); byte slot = itemTag.getByte("Slot"); if (slot >= 0 && slot < compostItemStacks.length) compostItemStacks[slot] = ItemStack.loadItemStackFromNBT(itemTag); } binDecomposeTime = tag.getShort("DecompTime"); currentItemSlot = tag.getByte("DecompSlot"); itemDecomposeCount = tag.getByte("DecompCount"); if (currentItemSlot >= 0) currentItemDecomposeTime = getItemDecomposeTime(compostItemStacks[currentItemSlot]); else currentItemDecomposeTime = 0; if (tag.hasKey("CustomName", 8)) customName = tag.getString("CustomName"); }
Example 9
Source File: DataConverter.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 10
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * NBT item loading function with support for stack sizes > 32K */ public static void readItemStacksFromTag(ItemStack[] items, NBTTagList tagList) { for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = tagList.getCompoundTagAt(i); int b = tag.getShort("Slot"); items[b] = ItemStack.loadItemStackFromNBT(tag); if (tag.hasKey("Quantity")) items[b].stackSize = ((NBTBase.NBTPrimitive) tag.getTag("Quantity")).getInt(); } }
Example 11
Source File: TileStationOrientationControl.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); numRotationsPerHour[0] = nbt.getShort("numRotationsX"); progress[0] = numRotationsPerHour[0] + getTotalProgress(0)/2; numRotationsPerHour[1] = nbt.getShort("numRotationsX"); progress[1] = numRotationsPerHour[1] + getTotalProgress(1)/2; numRotationsPerHour[2] = nbt.getShort("numRotationsX"); progress[2] = numRotationsPerHour[2] + getTotalProgress(2)/2; }
Example 12
Source File: PacketAtmSync.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void readClient(ByteBuf in) { NBTTagCompound nbt = new NBTTagCompound(); PacketBuffer packetBuffer = new PacketBuffer(in); try { nbt = packetBuffer.readCompoundTag(); type = nbt.getString("type"); pressure = nbt.getShort("pressure"); } catch (IOException e) { e.printStackTrace(); } }
Example 13
Source File: EntityShip.java From archimedes-ships with MIT License | 4 votes |
@Override protected void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); byte[] ab = compound.getByteArray("chunk"); ByteArrayInputStream bais = new ByteArrayInputStream(ab); DataInputStream in = new DataInputStream(bais); try { ChunkIO.read(in, shipChunk); in.close(); } catch (IOException e) { e.printStackTrace(); } if (compound.hasKey("seat")) { short s = compound.getShort("seat"); seatX = s & 0xF; seatY = s >>> 4 & 0xF; seatZ = s >>> 8 & 0xF; frontDirection = s >>> 12 & 3; } else { seatX = compound.getByte("seatX") & 0xFF; seatY = compound.getByte("seatY") & 0xFF; seatZ = compound.getByte("seatZ") & 0xFF; frontDirection = compound.getByte("front") & 3; } NBTTagList tileentities = compound.getTagList("tileent", 10); if (tileentities != null) { for (int i = 0; i < tileentities.tagCount(); i++) { NBTTagCompound comp = tileentities.getCompoundTagAt(i); TileEntity tileentity = TileEntity.createAndLoadEntity(comp); shipChunk.setTileEntity(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, tileentity); } } info = new ShipInfo(); info.shipName = compound.getString("name"); if (compound.hasKey("owner")) { info.shipName = compound.getString("owner"); } }
Example 14
Source File: TypeRW.java From OpenModsLib with MIT License | 4 votes |
@Override public Short readFromNBT(NBTTagCompound tag, String name) { return tag.getShort(name); }
Example 15
Source File: SyncableShort.java From OpenModsLib with MIT License | 4 votes |
@Override public void readFromNBT(NBTTagCompound tag, String name) { value = tag.getShort(name); }
Example 16
Source File: TileStationAltitudeController.java From AdvancedRocketry with MIT License | 4 votes |
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); gravity = nbt.getShort("numRotations"); }
Example 17
Source File: SyncableFlags.java From OpenModsLib with MIT License | 4 votes |
@Override public void readFromNBT(NBTTagCompound tag, String name) { value = tag.getShort(name); }
Example 18
Source File: TileEntityLargePot.java From GardenCollection with MIT License | 4 votes |
@Override public void readFromNBT (NBTTagCompound tag) { super.readFromNBT(tag); carving = tag.hasKey("Carv") ? tag.getShort("Carv") : 0; }
Example 19
Source File: TileObservatory.java From AdvancedRocketry with MIT License | 4 votes |
@Override public void useNetworkData(EntityPlayer player, Side side, byte id, NBTTagCompound nbt) { super.useNetworkData(player, side, id, nbt); if(id == -1) storeData(-1); else if(id == TAB_SWITCH && !world.isRemote) { tabModule.setTab(nbt.getShort("tab")); player.openGui(LibVulpes.instance, GuiHandler.guiId.MODULARNOINV.ordinal(), getWorld(), pos.getX(), pos.getY(), pos.getZ()); } else if(id == BUTTON_PRESS && !world.isRemote) { lastButton = nbt.getShort("button"); lastType = buttonType.get(lastButton - LIST_OFFSET); markDirty(); world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 2); player.openGui(LibVulpes.instance, GuiHandler.guiId.MODULARNOINV.ordinal(), getWorld(), pos.getX(), pos.getY(), pos.getZ()); } else if(id == SEED_CHANGE) { if(extractData(dataConsumedPerRefresh, DataType.DISTANCE, EnumFacing.UP, false) >= dataConsumedPerRefresh) { lastSeed = world.getTotalWorldTime()/100; lastButton = -1; lastType = ""; extractData(dataConsumedPerRefresh, DataType.DISTANCE, EnumFacing.UP, true); world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 2); markDirty(); player.openGui(LibVulpes.instance, GuiHandler.guiId.MODULARNOINV.ordinal(), getWorld(), pos.getX(), pos.getY(), pos.getZ()); } } else if(id == PROCESS_CHIP && !world.isRemote) { if(inv.getStackInSlot(2).isEmpty() && isOpen && hasEnergy(500) && lastButton != -1) { ItemStack stack = inv.decrStackSize(1, 1); if(stack != null && stack.getItem() instanceof ItemAsteroidChip) { ((ItemAsteroidChip)(stack.getItem())).setUUID(stack, lastSeed); ((ItemAsteroidChip)(stack.getItem())).setType(stack, lastType); ((ItemAsteroidChip)(stack.getItem())).setMaxData(stack, 1000); inv.setInventorySlotContents(2, stack); extractData(1000, DataType.COMPOSITION, EnumFacing.UP, true); extractData(1000, DataType.MASS, EnumFacing.UP, true); useEnergy(500); } } } }
Example 20
Source File: BackpackManager.java From SkyblockAddons with MIT License | 4 votes |
public static Backpack getFromItem(ItemStack stack) { if (stack == null) return null; SkyblockAddons main = SkyblockAddons.getInstance(); String id = ItemUtils.getSkyBlockItemID(stack); if (id != null) { NBTTagCompound extraAttributes = stack.getTagCompound().getCompoundTag("ExtraAttributes"); Matcher matcher = BACKPACK_ID_PATTERN.matcher(id); boolean matches = matcher.matches(); boolean isCakeBag = main.getConfigValues().isEnabled(Feature.CAKE_BAG_PREVIEW) && "NEW_YEAR_CAKE_BAG".equals(id) && EnumUtils.InventoryType.getCurrentInventoryType() != EnumUtils.InventoryType.BAKER; // If it's a backpack OR it's a cake bag and they have the setting enabled. if (matches || isCakeBag) { byte[] bytes = null; for (String key : extraAttributes.getKeySet()) { if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { bytes = extraAttributes.getByteArray(key); break; } } try { int length = 0; if (matches) { String backpackType = matcher.group(1); switch (backpackType) { // because sometimes the size of the tag is not updated (etc. when you upcraft it) case "SMALL": length = 9; break; case "MEDIUM": length = 18; break; case "LARGE": length = 27; break; case "GREATER": length = 36; break; } } ItemStack[] items = new ItemStack[length]; if (bytes != null) { NBTTagCompound nbtTagCompound = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); NBTTagList list = nbtTagCompound.getTagList("i", Constants.NBT.TAG_COMPOUND); if (list.tagCount() > length) { length = list.tagCount(); items = new ItemStack[length]; } for (int i = 0; i < length; i++) { NBTTagCompound item = list.getCompoundTagAt(i); // This fixes an issue in Hypixel where enchanted potatoes have the wrong id (potato block instead of item). short itemID = item.getShort("id"); if (itemID == 142) { // Potato Block -> Potato Item item.setShort("id", (short) 392); } else if (itemID == 141) { // Carrot Block -> Carrot Item item.setShort("id", (short) 391); } ItemStack itemStack = ItemStack.loadItemStackFromNBT(item); items[i] = itemStack; } } BackpackColor color = BackpackColor.WHITE; if (extraAttributes.hasKey("backpack_color")) { try { color = BackpackColor.valueOf(extraAttributes.getString("backpack_color")); } catch (IllegalArgumentException ignored) {} } return new Backpack(items, TextUtils.stripColor(stack.getDisplayName()), color); } catch (IOException ex) { ex.printStackTrace(); } } } return null; }