Posted April 1, 201510 yr Hi, I'm currently updating a mod from 1.6.2 to 1.7. I've managed to do most things but I've recently ran into a issue with updating a packet. Basically, I need someone to explain how I update this packet and so I can use it. public class AC_PacketHandler implements IPacketHandler { @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { if(packet.channel.equals(Strings.CHANNEL_ROPE_POSITION)) { this.handleRopePosition(packet, player); } } private void handleRopePosition(Packet250CustomPayload packet, Player plyr) { DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data)); int captainId; int hookId; try { captainId = inputStream.readInt(); hookId = inputStream.readInt(); } catch(IOException e) { e.printStackTrace(); return; } WorldClient world; if(plyr instanceof EntityPlayer) { world = (WorldClient) ((EntityPlayer) plyr).worldObj; } else { return; } AC_EntityPirateHook hook = (AC_EntityPirateHook) world.getEntityByID(hookId); AC_EntityCaptain captain = (AC_EntityCaptain) world.getEntityByID(captainId); hook.setThrower(captain); captain.resetHookCooldown(); captain.setHookAirBorne(true); double rotation = (captain.rotationYaw + 70.0F) / (180.0F / Math.PI); double hookLaunchX = Math.cos(rotation); double hookLaunchY = 1.4D; double hookLaunchZ = Math.sin(rotation); for (int i = 0; i < 10; i++) { captain.worldObj.spawnParticle("smoke", captain.posX + hookLaunchX, captain.posY + hookLaunchY, captain.posZ + hookLaunchZ, (captain.getRNG().nextDouble() - 0.5D) / 5D, (captain.getRNG().nextDouble() - 0.5D) / 5D, (captain.getRNG().nextDouble() - 0.5D) / 5D); } } This is how I used it before Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = Strings.CHANNEL_ROPE_POSITION; packet.data = bos.toByteArray(); packet.length = bos.size(); ((WorldServer) this.worldObj).getEntityTracker().sendPacketToAllPlayersTrackingEntity(hook, packet); urh it messed up my formatting.
April 2, 201510 yr Author Here you go: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html Okay, I've got the classes setup but I have no idea how I'd change my old code to make it fit with this new system.
April 2, 201510 yr First, make a class implementing IMessage. Then put the packet bytestream reading/writing code into the fromBytes(read) and toBytes(write) in the class. (you should store fields like captainId and hookId in the class) and make another class implementing IMessageHandler, and in the method 'onMessage' do what you want when packet is received. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
April 2, 201510 yr For the conversion, after setting up the general system according to diesieben07's link, based on your code you need to: 1. Make your own "custom payload" message packet. In that packet you would send the first byte as a unique identifier of your mod's packets -- like maybe a 0 represents some data for an entity, 1 some data for a GUI, or whatever packet types you need. 2. Instead of byte arrays for the data use ByteBuf. Then similar to your byte array there are methods for packing data together into and out of the buffer. 3. Based on the information read out of the ByteBuf you can do whatever you want (in your code looks like you create particles and such). Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.