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

The following examples show how to use net.minecraft.network.PacketBuffer#readShort() . 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: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void receiveInitialSyncData(PacketBuffer buf) {
    this.frontFacing = EnumFacing.VALUES[buf.readByte()];
    this.paintingColor = buf.readInt();
    int amountOfTraits = buf.readShort();
    for (int i = 0; i < amountOfTraits; i++) {
        int traitNetworkId = buf.readVarInt();
        MTETrait trait = mteTraits.stream().filter(otherTrait -> otherTrait.getNetworkID() == traitNetworkId).findAny().get();
        trait.receiveInitialData(buf);
    }
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        int coverId = buf.readVarInt();
        if (coverId != -1) {
            CoverDefinition coverDefinition = CoverDefinition.getCoverByNetworkId(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readInitialSyncData(buf);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }
    this.isFragile = buf.readBoolean();
}
 
Example 2
Source File: LongItemStack.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static LongItemStack readItemStack(PacketBuffer packetBuffer) {
    int itemId = packetBuffer.readShort();
    if (itemId < 0) {
        return new LongItemStack(ItemStack.EMPTY);
    } else {
        int stackSize = packetBuffer.readVarInt();
        int metadata = packetBuffer.readShort();
        ItemStack itemStack = new ItemStack(Item.getItemById(itemId), stackSize, metadata);
        try {
            itemStack.getItem().readNBTShareTag(itemStack, packetBuffer.readCompoundTag());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return new LongItemStack(itemStack);
    }
}
 
Example 3
Source File: CoverFacade.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readInitialSyncData(PacketBuffer packetBuffer) {
    super.readInitialSyncData(packetBuffer);
    Item item = Item.getItemById(packetBuffer.readShort());
    int itemDamage = packetBuffer.readShort();
    this.facadeStack = new ItemStack(item, 1, itemDamage);
    updateFacadeState();
}
 
Example 4
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 5
Source File: PacketChangeColor.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static PacketChangeColor decode(PacketBuffer buffer) {
    return new PacketChangeColor(buffer.readShort(), buffer.readShort(), buffer.readShort(), buffer.readShort(), buffer.readShort(), buffer.readShort());
}
 
Example 6
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 7
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public Short readFromStream(PacketBuffer input) {
	return input.readShort();
}
 
Example 8
Source File: SyncableShort.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) {
	value = stream.readShort();
}
 
Example 9
Source File: SyncableFlags.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) {
	value = stream.readShort();
}