Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package advancedscience.core;
- import java.io.ByteArrayInputStream;
- import java.io.DataInputStream;
- import java.io.IOException;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.network.INetworkManager;
- import net.minecraft.network.packet.Packet250CustomPayload;
- import net.minecraft.world.World;
- import advancedscience.research.TileEntityResearchTable;
- 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) {
- if (packet.channel.equals("DanielScienceGui")) {
- handleGui(packet, player);
- }
- }
- private void handleGui(Packet250CustomPayload packet, Player player) {
- DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
- EntityPlayer entityPlayer = (EntityPlayer) player;
- World world = entityPlayer.worldObj;
- if(world.isRemote) System.out.println("@World is remote.");
- if(!world.isRemote) System.out.println("@World is not remote.");
- int xCoord;
- int yCoord;
- int zCoord;
- String action;
- try {
- xCoord = inputStream.readInt();
- yCoord = inputStream.readInt();
- zCoord = inputStream.readInt();
- action = inputStream.readUTF();
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- System.out.println(xCoord + " " + yCoord + " " + zCoord + " " + action);
- System.out.println(action.substring(0, 5));
- if(action.substring(0, 5).equals("rsach")){
- TileEntityResearchTable tileEntity = (TileEntityResearchTable)world.getBlockTileEntity(xCoord, yCoord, zCoord);
- tileEntity.recieveResearchCommand(Integer.parseInt(action.substring(action.length() - 3, action.length())));
- }
- if(!world.isRemote){
- PacketDispatcher.sendPacketToServer(packet);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement