Jump to content

Entity Packets from 1.6 TO 1.7


Lua

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.