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

The following examples show how to use net.minecraft.network.PacketBuffer#readByte() . 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: CoverBehaviorUIFactory.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected CoverBehavior readHolderFromSyncData(PacketBuffer syncData) {
    BlockPos blockPos = syncData.readBlockPos();
    EnumFacing attachedSide = EnumFacing.VALUES[syncData.readByte()];
    TileEntity tileEntity = Minecraft.getMinecraft().world.getTileEntity(blockPos);
    ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null);
    if (coverable != null) {
        return coverable.getCoverAtSide(attachedSide);
    }
    return null;
}
 
Example 3
Source File: SimpleMachineMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveInitialSyncData(PacketBuffer buf) {
    super.receiveInitialSyncData(buf);
    this.outputFacing = EnumFacing.VALUES[buf.readByte()];
    this.autoOutputItems = buf.readBoolean();
    this.autoOutputFluids = buf.readBoolean();
}
 
Example 4
Source File: SimpleMachineMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
    super.receiveCustomData(dataId, buf);
    if (dataId == 100) {
        this.outputFacing = EnumFacing.VALUES[buf.readByte()];
        getHolder().scheduleChunkForRenderUpdate();
    } else if (dataId == 101) {
        this.autoOutputItems = buf.readBoolean();
        getHolder().scheduleChunkForRenderUpdate();
    } else if (dataId == 102) {
        this.autoOutputFluids = buf.readBoolean();
        getHolder().scheduleChunkForRenderUpdate();
    }
}
 
Example 5
Source File: RecipeLogicSteam.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
    super.receiveCustomData(dataId, buf);
    if (dataId == 2) {
        this.needsVenting = buf.readBoolean();
    } else if (dataId == 3) {
        this.ventingSide = EnumFacing.VALUES[buf.readByte()];
        getMetaTileEntity().getHolder().scheduleChunkForRenderUpdate();
    } else if (dataId == 4) {
        this.ventingStuck = buf.readBoolean();
    }
}
 
Example 6
Source File: RecipeLogicSteam.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveInitialData(PacketBuffer buf) {
    super.receiveInitialData(buf);
    this.ventingSide = EnumFacing.VALUES[buf.readByte()];
    this.needsVenting = buf.readBoolean();
    this.ventingStuck = buf.readBoolean();
}
 
Example 7
Source File: PlayerInventoryUIFactory.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
protected PlayerInventoryHolder readHolderFromSyncData(PacketBuffer syncData) {
    EntityPlayer entityPlayer = Minecraft.getMinecraft().player;
    EnumHand enumHand = EnumHand.values()[syncData.readByte()];
    ItemStack itemStack;
    try {
        itemStack = syncData.readItemStack();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
    return new PlayerInventoryHolder(entityPlayer, enumHand, itemStack);
}
 
Example 8
Source File: MetaTileEntityBlockBreaker.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
    super.receiveCustomData(dataId, buf);
    if (dataId == 100) {
        this.outputFacing = EnumFacing.VALUES[buf.readByte()];
        getHolder().scheduleChunkForRenderUpdate();
    }
}
 
Example 9
Source File: MetaTileEntityBlockBreaker.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void receiveInitialSyncData(PacketBuffer buf) {
    super.receiveInitialSyncData(buf);
    this.outputFacing = EnumFacing.VALUES[buf.readByte()];
}
 
Example 10
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 11
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public Byte readFromStream(PacketBuffer input) {
	return input.readByte();
}
 
Example 12
Source File: SyncableByte.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) {
	value = stream.readByte();
}
 
Example 13
Source File: SyncableFlags.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) {
	value = stream.readByte();
}