Created
January 7, 2014 16:56
-
-
Save IamRob-/8302422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package untitled.network; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.DataOutputStream; | |
| import java.io.IOException; | |
| import net.minecraft.entity.player.EntityPlayer; | |
| import net.minecraft.network.INetworkManager; | |
| import net.minecraft.network.packet.Packet250CustomPayload; | |
| import net.minecraft.tileentity.TileEntity; | |
| import untitled.ModInfo; | |
| import untitled.tileentities.TileEntityPoster; | |
| import com.google.common.io.ByteArrayDataInput; | |
| import com.google.common.io.ByteStreams; | |
| import cpw.mods.fml.common.network.IPacketHandler; | |
| import cpw.mods.fml.common.network.PacketDispatcher; | |
| import cpw.mods.fml.common.network.Player; | |
| public class PacketHandler implements IPacketHandler{ | |
| @Override | |
| public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { | |
| ByteArrayDataInput reader = ByteStreams.newDataInput(packet.data); | |
| byte packetId = reader.readByte(); | |
| EntityPlayer entityPlayer = (EntityPlayer) player; | |
| switch(packetId){ | |
| case 0: | |
| int x = reader.readInt(); | |
| int y = reader.readInt(); | |
| int z = reader.readInt(); | |
| float r = reader.readFloat(); | |
| float g = reader.readFloat(); | |
| float b = reader.readFloat(); | |
| // System.out.println("Packet Recieved"); | |
| TileEntity tileEntity = entityPlayer.worldObj.getBlockTileEntity(x, y, z); | |
| if (tileEntity != null && tileEntity instanceof TileEntityPoster) { | |
| TileEntityPoster te = (TileEntityPoster) tileEntity; | |
| te.setRGB(r, g, b); | |
| // entityPlayer.worldObj.markBlockForRenderUpdate(x, y, z); | |
| } | |
| } | |
| } | |
| public static void sendPosterColor(TileEntityPoster te, float r, float g, float b) { | |
| ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); | |
| DataOutputStream dataStream = new DataOutputStream(byteStream); | |
| System.out.println("Sending Packet"); | |
| try { | |
| dataStream.writeByte((byte) 0); | |
| dataStream.writeInt(te.xCoord); | |
| dataStream.writeInt(te.yCoord); | |
| dataStream.writeInt(te.zCoord); | |
| dataStream.writeFloat(r); | |
| dataStream.writeFloat(g); | |
| dataStream.writeFloat(b); | |
| PacketDispatcher.sendPacketToAllPlayers(PacketDispatcher.getPacket(ModInfo.Channel, byteStream.toByteArray())); | |
| } catch (IOException e) { | |
| System.err.append("Failed to send poster color packet"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment