Jump to content

Recommended Posts

Posted

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.

Posted

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);

 

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.