Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.