GiantNuker Posted September 7, 2017 Posted September 7, 2017 Hi, my problem is when I call my method public static void setFlightState(FlightState state) { EntityPlayer p = Minecraft.getMinecraft().player; if (getStateForPlayer(p) != state) { WingsPacketHandler.INSTANCE.sendToServer(new PacketFlightStateChange(state)); if (state == FlightState.GLIDING) { p.capabilities.isFlying = false; try { setFlagMethod.invoke(Minecraft.getMinecraft().player, 7, true); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); FMLCommonHandler.instance().exitJava(1, false); } } else { try { setFlagMethod.invoke(Minecraft.getMinecraft().player, 7, false); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); FMLCommonHandler.instance().exitJava(1, false); } if (state == FlightState.HOVERING) { p.capabilities.isFlying = true; } else { p.capabilities.isFlying = false; } } tsc = 5; } } it should sent a packet to the server import io.netty.buffer.ByteBuf; import mods.giantnuker.wings.FlightState; import mods.giantnuker.wings.ItemDetatchableWings; import mods.giantnuker.wings.WingsCapability; import mods.giantnuker.wings.WingsMod; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class PacketFlightStateChange implements IMessage { FlightState s = FlightState.NOT_FLYING; public PacketFlightStateChange() {} public PacketFlightStateChange(FlightState f) { s = f; } @Override public void fromBytes(ByteBuf arg0) { s = FlightState.fromInt(arg0.readInt()); } @Override public void toBytes(ByteBuf arg0) { arg0.writeInt(s.toInt()); } public static class Handler implements IMessageHandler<PacketFlightStateChange, IMessage> { @Override public IMessage onMessage(PacketFlightStateChange arg0, MessageContext arg1) { EntityPlayerMP player = arg1.getServerHandler().player; WingsCapability cap = player.getCapability(WingsCapability.Provider.WINGS_CAP, null); //if (cap.hasWings() || player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() == WingsMod.wings && ItemDetatchableWings.isUsable(player.getItemStackFromSlot(EntityEquipmentSlot.CHEST))) { FlightState state = arg0.s; if (state.equals(FlightState.GLIDING)) { player.capabilities.isFlying = false; try { WingsMod.setFlagMethod.invoke(Minecraft.getMinecraft().player, 7, true); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); FMLCommonHandler.instance().exitJava(1, false); } } else { try { WingsMod.setFlagMethod.invoke(Minecraft.getMinecraft().player, 7, false); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); FMLCommonHandler.instance().exitJava(1, false); } if (state.equals(FlightState.HOVERING)) { player.capabilities.isFlying = true; } else { player.capabilities.isFlying = false; } } System.out.println(state); //} return null; } } } the change happens on the client but not the server. It does NOT print the flight state & when I log out and back in again - I am falling out of the sky. Quote
GiantNuker Posted September 7, 2017 Author Posted September 7, 2017 My Eyes Broke... INSTANCE.registerMessage(PacketFlightStateChange.Handler.class, PacketFlightStateChange.class, 0, Side.CLIENT); should be INSTANCE.registerMessage(PacketFlightStateChange.Handler.class, PacketFlightStateChange.class, 0, Side.SERVER); Quote
Recommended Posts
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.