Java tutorial
/** * This work is licensed under the Creative Commons * Attribution-ShareAlike 3.0 Unported License. To view a copy of this * license, visit http://creativecommons.org/licenses/by-sa/3.0/. */ package nxminetilities.network; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import nxminetilities.modules.lighting.TileEntityMultilight; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import cpw.mods.fml.relauncher.Side; public class MultilightPacket extends MinetilitiesPacket { private int x, y, z; private double lightColourRed, lightColourGreen, lightColourBlue; private boolean lightEnabled; public MultilightPacket(int x, int y, int z, ItemStack is) { this.x = x; this.y = y; this.z = z; lightColourRed = is.stackTagCompound.getDouble("lightColourRed"); lightColourGreen = is.stackTagCompound.getDouble("lightColourGreen"); lightColourBlue = is.stackTagCompound.getDouble("lightColourBlue"); lightEnabled = is.stackTagCompound.getBoolean("lightEnabled"); } public MultilightPacket() { } @Override public void write(ByteArrayDataOutput out) { out.writeInt(x); out.writeInt(y); out.writeInt(z); out.writeDouble(lightColourRed); out.writeDouble(lightColourGreen); out.writeDouble(lightColourBlue); out.writeBoolean(lightEnabled); } @Override public void read(ByteArrayDataInput in) throws ProtocolException { x = in.readInt(); y = in.readInt(); z = in.readInt(); lightColourRed = in.readDouble(); lightColourGreen = in.readDouble(); lightColourBlue = in.readDouble(); lightEnabled = in.readBoolean(); } @Override public void execute(EntityPlayer player, Side side) throws ProtocolException { TileEntity tile = player.worldObj.getBlockTileEntity(x, y, z); if (tile != null && tile instanceof TileEntityMultilight) { TileEntityMultilight teLight = (TileEntityMultilight) tile; teLight.lightColourRed = lightColourRed; teLight.lightColourGreen = lightColourGreen; teLight.lightColourBlue = lightColourBlue; teLight.lightEnabled = lightEnabled; } player.worldObj.markBlockForUpdate(x, y, z); player.worldObj.updateAllLightTypes(x, y, z); player.worldObj.markBlockForRenderUpdate(x, y, z); } }