Java Code Examples for net.minecraft.nbt.NBTTagCompound#getByteArray()
The following examples show how to use
net.minecraft.nbt.NBTTagCompound#getByteArray() .
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: SpongeSchematic.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected boolean readBlocksFromTag(NBTTagCompound tag) { if (tag.hasKey("Palette", Constants.NBT.TAG_COMPOUND) && tag.hasKey("BlockData", Constants.NBT.TAG_BYTE_ARRAY) && isSizeValid(this.getSize())) { NBTTagCompound paletteTag = tag.getCompoundTag("Palette"); byte[] blockData = tag.getByteArray("BlockData"); int paletteSize = paletteTag.getKeySet().size(); this.blockContainer = LitematicaBlockStateContainerFull.createContainer(paletteSize, blockData, this.getSize()); if (this.blockContainer == null) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.sponge.failed_to_read_blocks"); return false; } return this.readPaletteFromTag(paletteTag, this.blockContainer.getPalette()); } return false; }
Example 2
Source File: TileGravityController.java From AdvancedRocketry with MIT License | 6 votes |
@Override public void useNetworkData(EntityPlayer player, Side side, byte id, NBTTagCompound nbt) { super.useNetworkData(player, side, id, nbt); if(id == 3) { setProgress(0, nbt.getShort("progress")); setProgress(1, nbt.getShort("radius")); } else if(id == 4) { byte bytes[] = nbt.getByteArray("bytes"); for(int i = 0; i < 6; i++) sideSelectorModule.setStateForSide(i, bytes[i]); } else if(id == 5) { state = RedstoneState.values()[nbt.getByte("redstoneState")]; redstoneControl.setRedstoneState(state); } }
Example 3
Source File: QueryableShipData.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void readFromNBT(NBTTagCompound nbt) { long start = System.currentTimeMillis(); Kryo kryo = ValkyrienSkiesMod.INSTANCE.getKryo(); Input input = new Input(nbt.getByteArray(NBT_STORAGE_KEY)); try { allShips = kryo.readObject(input, ConcurrentIndexedCollection.class); } catch (Exception e) { // Error reading allShips from memory, just make a new empty one. e.printStackTrace(); allShips = new ConcurrentIndexedCollection<>(); } if (allShips == null) { // This should NEVER EVER happen! So I don't feel bad crashing the game, for now. throw new IllegalStateException( "Kryo read allships as null! Making a new empty allships instance"); } System.out.println("Price of read: " + (System.currentTimeMillis() - start) + "ms"); }
Example 4
Source File: TileRocketLoader.java From AdvancedRocketry with MIT License | 6 votes |
@Override public void useNetworkData(EntityPlayer player, Side side, byte id, NBTTagCompound nbt) { state = RedstoneState.values()[nbt.getByte("state")]; inputstate = RedstoneState.values()[nbt.getByte("inputstate")]; byte bytes[] = nbt.getByteArray("bytes"); for(int i = 0; i < 6; i++) sideSelectorModule.setStateForSide(i, bytes[i]); if(rocket == null) setRedstoneState(state == RedstoneState.INVERTED); markDirty(); world.markChunkDirty(getPos(), this); }
Example 5
Source File: TileRocketFluidLoader.java From AdvancedRocketry with MIT License | 6 votes |
@Override public void useNetworkData(EntityPlayer player, Side side, byte id, NBTTagCompound nbt) { state = RedstoneState.values()[nbt.getByte("state")]; inputstate = RedstoneState.values()[nbt.getByte("inputstate")]; byte bytes[] = nbt.getByteArray("bytes"); for(int i = 0; i < 6; i++) sideSelectorModule.setStateForSide(i, bytes[i]); if(rocket == null) setRedstoneState(state == RedstoneState.INVERTED); markDirty(); world.markChunkDirty(getPos(), this); }
Example 6
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 7
Source File: SyncedTileEntity.java From OpenModsLib with MIT License | 5 votes |
private void applyInitializationData(NBTTagCompound tag) { if (tag.hasKey(TAG_SYNC_INIT, Constants.NBT.TAG_BYTE_ARRAY)) { final byte[] syncInit = tag.getByteArray(TAG_SYNC_INIT); final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer()); tmp.writeBytes(syncInit); try { getSyncMap().readIntializationData(tmp); } catch (IOException e) { throw new RuntimeException(e); } } }
Example 8
Source File: HexUpdateHandler.java From TFC2 with GNU General Public License v3.0 | 5 votes |
@SubscribeEvent public void handle(HexUpdateEvent event) { NBTTagCompound nbt = event.centerToUpdate.getCustomNBT(); if(nbt.hasKey("TFC2_Data")) { NBTTagCompound data = nbt.getCompoundTag("TFC2_Data"); if(data.hasKey("CropData")) { NBTTagCompound cropData = data.getCompoundTag("CropData"); long lastRegenTick = cropData.getLong("lastRegenTick"); if(lastRegenTick + Timekeeper.ticksInPeriod < Timekeeper.getInstance().getTotalTicks()) { cropData.setLong("lastRegenTick", lastRegenTick + Timekeeper.ticksInPeriod); float nutrients = cropData.getFloat("nutrients"); float maxNutrients = TileCrop.GetMaxNutrients(event.map); cropData.setFloat("nutrients", Math.min(maxNutrients, nutrients + maxNutrients/4)); } } if(data.hasKey("hydration")) { byte[] hydrationArray = data.getByteArray("hydration"); int waterLevel = 0; for(int i = 0; i < 64; i++) { hydrationArray[i] = (byte)Math.max(0, hydrationArray[i]-5); waterLevel += hydrationArray[i]; } if(waterLevel > 0) data.setByteArray("hydration", hydrationArray); else data.removeTag("hydration"); } } }
Example 9
Source File: LostLuggage.java From qcraft-mod with Apache License 2.0 | 5 votes |
private void readFromNBT( NBTTagCompound nbt ) { m_luggage.clear(); NBTTagList luggageList = nbt.getTagList( "luggage", 10 ); for( int i=0; i<luggageList.tagCount(); ++i ) { NBTTagCompound luggageTag = luggageList.getCompoundTagAt( i ); Luggage luggage = new Luggage(); luggage.m_timeStamp = luggageTag.getLong( "timeStamp" ); if( luggageTag.hasKey( "originIP" ) && luggageTag.hasKey( "originPort" ) ) { luggage.m_origin = new Address( luggageTag.getString( "originIP" ) + ":" + luggageTag.getInteger( "originPort" ) ); } else if( luggageTag.hasKey( "originAddress" ) ) { luggage.m_origin = new Address( luggageTag.getString( "originAddress" ) ); } if( luggageTag.hasKey( "destinationIP" ) && luggageTag.hasKey( "destinationPort" ) ) { luggage.m_destination = new Address( luggageTag.getString( "destinationIP" ) + ":" + luggageTag.getInteger( "destinationPort" ) ); } else if( luggageTag.hasKey( "destinationAddress" ) ) { luggage.m_destination = new Address( luggageTag.getString( "destinationAddress" ) ); } luggage.m_luggage = luggageTag.getByteArray( "luggage" ); m_luggage.add( luggage ); } }
Example 10
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 11
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 */ @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 12
Source File: ShipTransform.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Nullable public static ShipTransform readFromNBT(NBTTagCompound compound, String name) { byte[] localToGlobalAsBytes = compound.getByteArray(name); if (localToGlobalAsBytes.length == 0) { log.error("Loading from the ShipTransform has failed, now we are forced to fallback on " + "Vanilla MC positions. This probably won't go well at all!"); return null; } double[] localToGlobalInternalArray = ValkyrienNBTUtils.toDoubleArray(localToGlobalAsBytes); return new ShipTransform(localToGlobalInternalArray); }
Example 13
Source File: SyncedTileEntityBase.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { NBTTagCompound updateTag = pkt.getNbtCompound(); NBTTagList tagList = updateTag.getTagList("d", NBT.TAG_COMPOUND); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound entryTag = tagList.getCompoundTagAt(i); int discriminator = entryTag.getInteger("i"); byte[] updateData = entryTag.getByteArray("d"); ByteBuf backedBuffer = Unpooled.copiedBuffer(updateData); receiveCustomData(discriminator, new PacketBuffer(backedBuffer)); } }
Example 14
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; }
Example 15
Source File: SchematicaSchematic.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") protected boolean readBlocksFromTag(NBTTagCompound tag) { // This method was implemented based on // https://minecraft.gamepedia.com/Schematic_file_format // as it was on 2018-04-18. Vec3i size = this.getSize(); final int sizeX = size.getX(); final int sizeY = size.getY(); final int sizeZ = size.getZ(); final byte[] blockIdsByte = tag.getByteArray("Blocks"); final byte[] metaArr = tag.getByteArray("Data"); final int numBlocks = blockIdsByte.length; final int layerSize = sizeX * sizeZ; if (numBlocks != (sizeX * sizeY * sizeZ)) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.schematic.invalid_block_array_size", numBlocks, sizeX, sizeY, sizeZ); return false; } if (numBlocks != metaArr.length) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.schematic.invalid_metadata_array_size", numBlocks, metaArr.length); return false; } if (this.readPaletteFromTag(tag) == false) { InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.palette.failed_to_read"); return false; } if (tag.hasKey("AddBlocks", Constants.NBT.TAG_BYTE_ARRAY)) { return this.readBlocks12Bit(tag, blockIdsByte, metaArr, sizeX, layerSize); } // Old Schematica format else if (tag.hasKey("Add", Constants.NBT.TAG_BYTE_ARRAY)) { // FIXME is this array 4 or 8 bits per block? InfoUtils.printErrorMessage("litematica.message.error.schematic_read.schematica.old_schematica_format_not_supported"); return false; } // No palette, use the registry IDs directly else { ILitematicaBlockStateContainer container = this.blockContainer; Block[] palette = this.palette; for (int i = 0; i < numBlocks; i++) { Block block = palette[blockIdsByte[i] & 0xFF]; int x = i % sizeX; int y = i / layerSize; int z = (i % layerSize) / sizeX; container.setBlockState(x, y, z, block.getStateFromMeta(metaArr[i])); } } return true; }
Example 16
Source File: SyncedTileEntityBase.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void handleUpdateTag(NBTTagCompound tag) { byte[] updateData = tag.getByteArray("d"); ByteBuf backedBuffer = Unpooled.copiedBuffer(updateData); receiveInitialSyncData(new PacketBuffer(backedBuffer)); }
Example 17
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 18
Source File: TypeRW.java From OpenModsLib with MIT License | 4 votes |
@Override public byte[] readFromNBT(NBTTagCompound tag, String name) { return tag.getByteArray(name); }
Example 19
Source File: SyncableByteArray.java From OpenModsLib with MIT License | 4 votes |
@Override public void readFromNBT(NBTTagCompound nbt, String name) { nbt.getByteArray(name); }