Java Code Examples for net.minecraft.network.PacketBuffer#readCompoundTag()

The following examples show how to use net.minecraft.network.PacketBuffer#readCompoundTag() . 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: TankWidget.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == 0) {
        this.lastTankCapacity = buffer.readVarInt();
    } else if (id == 1) {
        this.lastFluidInTank = null;
    } else if (id == 2) {
        NBTTagCompound fluidStackTag;
        try {
            fluidStackTag = buffer.readCompoundTag();
        } catch (IOException ignored) {
            return;
        }
        this.lastFluidInTank = FluidStack.loadFluidStackFromNBT(fluidStackTag);
    } else if (id == 3 && lastFluidInTank != null) {
        this.lastFluidInTank.amount = buffer.readVarInt();
    }

    if (id == 4) {
        ItemStack currentStack = gui.entityPlayer.inventory.getItemStack();
        int newStackSize = buffer.readVarInt();
        currentStack.setCount(newStackSize);
        gui.entityPlayer.inventory.setItemStack(currentStack);
    }
}
 
Example 2
Source File: PacketSatellite.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void readClient(ByteBuf in) {
	
	PacketBuffer packetBuffer = new PacketBuffer(in);
	NBTTagCompound nbt;
	
	//TODO: error handling
	try {
		nbt = packetBuffer.readCompoundTag();
		SatelliteBase satellite = SatelliteRegistry.createFromNBT(nbt);
		
		zmaster587.advancedRocketry.dimension.DimensionManager.getInstance().getDimensionProperties(satellite.getDimensionId()).addSatallite(satellite);
	} catch (IOException e) {
		e.printStackTrace();
		return;
	}
}
 
Example 3
Source File: PacketDurabilitySync.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static PacketDurabilitySync decode(PacketBuffer buffer) {
    CompoundNBT tag = buffer.readCompoundTag();
    ListNBT nbtList = tag.getList("list", Constants.NBT.TAG_COMPOUND);
    List<Tuple<BlockPos, Integer>> thisList = new ArrayList<>();
    for (int i = 0; i < nbtList.size(); i++) {
        CompoundNBT nbt = nbtList.getCompound(i);
        thisList.add(new Tuple<>(NBTUtil.readBlockPos(nbt.getCompound("pos")), nbt.getInt("dur")));
    }
    return new PacketDurabilitySync(thisList);
}
 
Example 4
Source File: ByteBufUtils.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static FluidStack readFluidStack(PacketBuffer buf) {
    if (!buf.readBoolean()) {
        return null;
    }
    try {
        NBTTagCompound tagCompound = buf.readCompoundTag();
        return FluidStack.loadFluidStackFromNBT(tagCompound);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 5
Source File: PhantomFluidWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == 1) {
        if (buffer.readBoolean()) {
            try {
                NBTTagCompound tagCompound = buffer.readCompoundTag();
                this.lastFluidStack = FluidStack.loadFluidStackFromNBT(tagCompound);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            this.lastFluidStack = null;
        }
    }
}
 
Example 6
Source File: MessageBookCodeData.java    From Minecoprocessors with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fromBytes(final ByteBuf buf) {
  final PacketBuffer buffer = new PacketBuffer(buf);
  try {
    nbt = buffer.readCompoundTag();
  } catch (final IOException e) {
    Minecoprocessors.proxy.logger.warn("Invalid packet received.", e);
  }
}
 
Example 7
Source File: PacketAtmSync.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@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 8
Source File: PacketDimInfo.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	PacketBuffer packetBuffer = new PacketBuffer(in);
	NBTTagCompound nbt;
	dimNumber = in.readInt();
	

	deleteDim = in.readBoolean();
	
	if(!deleteDim) {
		//TODO: error handling
		try {
			dimNBT = nbt = packetBuffer.readCompoundTag();

			int number = packetBuffer.readShort();
			for(int i = 0; i < number; i++) {
				NBTTagCompound nbt2 = packetBuffer.readCompoundTag();
				artifacts.add(new ItemStack(nbt2));
			}
			
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		dimProperties = new DimensionProperties(dimNumber);
		dimProperties.readFromNBT(nbt);
		
		short strLen = packetBuffer.readShort();
		if(strLen > 0)
		{
			dimProperties.customIcon = packetBuffer.readString(strLen);
		}
	}
}
 
Example 9
Source File: PacketStellarInfo.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	PacketBuffer packetBuffer = new PacketBuffer(in);
	NBTTagCompound nbt;
	starId = in.readInt();

	if(in.readBoolean()) {
		if(DimensionManager.getInstance().isDimensionCreated(starId)) {
			DimensionManager.getInstance().removeStar(starId);
		}
	}
	else {
		//TODO: error handling
		try {
			nbt = packetBuffer.readCompoundTag();

		} catch (IOException e) {
			e.printStackTrace();
			return;
		}

		StellarBody star;

		if((star = DimensionManager.getInstance().getStar(starId)) != null) {
			star.readFromNBT(nbt);
		} else {
			star = new StellarBody();
			star.readFromNBT(nbt);
			DimensionManager.getInstance().addStar(star);
		}
	}
}
 
Example 10
Source File: MessageOpenGui.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	try {
		_windowId = buffer.readInt();
		_data = buffer.readCompoundTag();
	} catch (Exception ex) {
		_windowId = -1;
		_data = null;
	}
}
 
Example 11
Source File: SyncableTank.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) throws IOException {
	if (stream.readBoolean()) {
		String fluidName = stream.readString(Short.MAX_VALUE);
		Fluid fluid = FluidRegistry.getFluid(fluidName);

		int fluidAmount = stream.readInt();

		this.fluid = new FluidStack(fluid, fluidAmount);
		this.fluid.tag = stream.readCompoundTag();
	} else {
		this.fluid = null;
	}
}
 
Example 12
Source File: PacketStationUpdate.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	stationNumber = in.readInt();
	spaceObject = SpaceObjectManager.getSpaceManager().getSpaceStation(stationNumber);
	type = Type.values()[in.readInt()];


	switch(type) {
	case DEST_ORBIT_UPDATE:
		spaceObject.setDestOrbitingBody(in.readInt());
		break;
	case ORBIT_UPDATE:
		spaceObject.setOrbitingBody(in.readInt());
		break;
	case FUEL_UPDATE:
		if(spaceObject instanceof SpaceObject)
			((SpaceObject)spaceObject).setFuelAmount(in.readInt());
		break;
	case ROTANGLE_UPDATE:
		spaceObject.setRotation(in.readDouble(), EnumFacing.EAST);
		spaceObject.setRotation(in.readDouble(), EnumFacing.UP);
		spaceObject.setRotation(in.readDouble(), EnumFacing.NORTH);
		spaceObject.setDeltaRotation(in.readDouble(), EnumFacing.EAST);
		spaceObject.setDeltaRotation(in.readDouble(), EnumFacing.UP);
		spaceObject.setDeltaRotation(in.readDouble(), EnumFacing.NORTH);
		break;
	case SIGNAL_WHITE_BURST:
		PlanetEventHandler.runBurst(Minecraft.getMinecraft().world.getTotalWorldTime() + 20, 20);
		break;
	case ALTITUDE_UPDATE:
		spaceObject.setOrbitalDistance(in.readFloat());
		break;
	case DIM_PROPERTY_UPDATE:
		PacketBuffer packetBuffer = new PacketBuffer(in);
		NBTTagCompound nbt;
		try {
			nbt = packetBuffer.readCompoundTag();

		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		spaceObject.getProperties().readFromNBT(nbt);
		break;
	}	
}
 
Example 13
Source File: PacketSpaceStationInfo.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	PacketBuffer packetBuffer = new PacketBuffer(in);
	NBTTagCompound nbt;
	stationNumber = in.readInt();

	//Is dimension being deleted
	if(in.readBoolean()) {
		if(DimensionManager.getInstance().isDimensionCreated(stationNumber)) {
			DimensionManager.getInstance().deleteDimension(stationNumber);
		}
	}
	else {
		//TODO: error handling
		int direction;
		String clazzId;
		int fuelAmt;
		try {
			clazzId = packetBuffer.readString(127);
			nbt = packetBuffer.readCompoundTag();
			fuelAmt = packetBuffer.readInt();
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		
		boolean hasWarpCores = in.readBoolean();
		
		direction = in.readInt();
		
		
		ISpaceObject iObject = SpaceObjectManager.getSpaceManager().getSpaceStation(stationNumber);
		
		
		
		//TODO: interface
		spaceObject = (SpaceObject)iObject;
		
		//Station needs to be created
		if( iObject == null ) {
			ISpaceObject object = SpaceObjectManager.getSpaceManager().getNewSpaceObjectFromIdentifier(clazzId);
			object.readFromNbt(nbt);
			object.setProperties(DimensionProperties.createFromNBT(stationNumber, nbt));
			((SpaceObject)object).setForwardDirection(EnumFacing.values()[direction]);
			
			SpaceObjectManager.getSpaceManager().registerSpaceObjectClient(object, object.getOrbitingPlanetId(), stationNumber);
			((SpaceObject)object).setFuelAmount(fuelAmt);
			((SpaceObject)object).hasWarpCores = hasWarpCores;
		}
		else {
			iObject.readFromNbt(nbt);
			//iObject.setProperties(DimensionProperties.createFromNBT(stationNumber, nbt));
			((SpaceObject)iObject).setForwardDirection(EnumFacing.values()[direction]);
			((SpaceObject)iObject).setFuelAmount(fuelAmt);
			((SpaceObject)iObject).hasWarpCores = hasWarpCores;
		}
	}
}
 
Example 14
Source File: StorageChunk.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public void readFromNetwork(ByteBuf in) {
	PacketBuffer buffer = new PacketBuffer(in);

	this.sizeX = buffer.readByte();
	this.sizeY = buffer.readByte();
	this.sizeZ = buffer.readByte();
	short numTiles = buffer.readShort();

	this.blocks = new Block[sizeX][sizeY][sizeZ];
	this.metas = new short[sizeX][sizeY][sizeZ];

	for(int x = 0; x < sizeX; x++) {
		for(int y = 0; y < sizeY; y++) {
			for(int z = 0; z < sizeZ; z++) {
				this.blocks[x][y][z] = Block.getBlockById(buffer.readInt());
				this.metas[x][y][z] = buffer.readShort();
			}
		}
	}

	for(short i = 0; i < numTiles; i++) {
		try {
			NBTTagCompound nbt = buffer.readCompoundTag();

			TileEntity tile = ZUtils.createTile(nbt);
			tile.setWorld(world);
			tileEntities.add(tile);

			if(isInventoryBlock(tile)) {
				inventoryTiles.add(tile);
			}

			if(isLiquidContainerBlock(tile))
				liquidTiles.add(tile);
			tile.setWorld(world);

		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	//We are now ready to render
	finalized = true;
}
 
Example 15
Source File: MessageSyncSettings.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	try { _data = buffer.readCompoundTag(); }
	catch (Exception ex) { _data = null; }
}
 
Example 16
Source File: SyncableNBT.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) throws IOException {
	this.tag = stream.readCompoundTag();

}