Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** All credits go to CoolAlias for this simple Packet Handling implemention! Minecraft 1.10, works like a charm!
- ** http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with
- */
- public class C00PacketSendSound implements IMessage{
- private String name;
- private SoundCategory category;
- private double
- x,y,z;
- private float
- volume,pitch;
- public C00PacketSendSound() {}
- public C00PacketSendSound(ImplSound sound) {
- this.name=sound.getName();
- this.category=sound.getCategory();
- this.x=sound.getX();
- this.y=sound.getY();
- this.z=sound.getZ();
- this.volume=sound.getVolume();
- this.pitch=sound.getPitch();
- }
- @Override
- public void fromBytes(ByteBuf buf) {
- this.name=ByteBufUtils.readUTF8String(buf);
- this.category=SoundCategory.getByName(ByteBufUtils.readUTF8String(buf));
- this.x=buf.readDouble();
- this.y=buf.readDouble();
- this.z=buf.readDouble();
- this.volume=buf.readFloat();
- this.pitch=buf.readFloat();
- }
- @Override
- public void toBytes(ByteBuf buf) {
- ByteBufUtils.writeUTF8String(buf, name);
- ByteBufUtils.writeUTF8String(buf, category.getName());
- buf.writeDouble(x);
- buf.writeDouble(y);
- buf.writeDouble(z);
- buf.writeFloat(volume);
- buf.writeFloat(pitch);
- }
- public static class Handler extends ClientMessageHandler<C00PacketSendSound>{
- @Override
- public IMessage handleClientMessage(EntityPlayer player, C00PacketSendSound message, MessageContext ctx) {
- Minecraft.getMinecraft().addScheduledTask(new Runnable() {
- //Just added this line to make sure the method gets called in the Minecraft thread!
- //Don't know if this is the problem solver or not, but it works now!
- @Override
- public void run() {
- SoundManager sndManager=new SoundManager();
- ImplSound sound=new ImplSound(message.name, message.category, message.volume, message.pitch, message.x, message.y, message.z);
- sndManager.playSound(sound);
- }
- });
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment