Example output
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.input.Keyboard;
@Mod(modid = "flymod", version = "1.0", clientSideOnly = true)
public class FlyMod {
private boolean isFlying = false;
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
if (event.getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntity();
if (player.equals(Minecraft.getMinecraft().player)) {
if (Keyboard.isKeyDown(Keyboard.KEY_F) && !player.capabilities.isFlying) {
startFlying(player);
} else if (!Keyboard.isKeyDown(Keyboard.KEY_F) && player.capabilities.isFlying) {
stopFlying(player);
}
}
}
}
private void startFlying(EntityPlayer player) {
isFlying = true;
player.capabilities.allowFlying = true;
player.capabilities.isFlying = true;
player.sendPlayerAbilities();
player.sendMessage(new TextComponentString("Fly mode enabled."));
}
private void stopFlying(EntityPlayer player) {
isFlying = false;
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
player.sendPlayerAbilities();
player.sendMessage(new TextComponentString("Fly mode disabled."));
}
}