Posted July 15, 20178 yr I'm using forge 1.8.9. I have an item, where, in a certain mode, if you click it, it enables/disables flying in survival. Here's the code for the part of the event handler in question: @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (curMode==6 && !player.isSneaking()) { if(!player.worldObj.isRemote) { player.capabilities.allowFlying = !player.capabilities.allowFlying; player.capabilities.isFlying = player.capabilities.allowFlying; player.addChatMessage(new ChatComponentText("Fly mode: " + Boolean.toString(player.capabilities.allowFlying))); } I know the inside of the if statement is being called, in fact the chat message even shows up saying "Fly mode: True" and "Fly Mode: False". So I know player.capabilities.allowFlying is being changed. And yet, it seems to have no effect. It doesn't disable/enable flying. I tried changing player.capabilities.isFlying too, it has the same problem. Here's the full code of the "Magic Wand" if you are interested, it cycles through different modes and in every case but the flying, summons an entity which does the grunt work: Spoiler package com.mister.magic.items; import java.util.Arrays; import java.util.List; import com.mister.magic.entities.EntityMagic; import com.mister.magic.init.InitItems; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChatComponentText; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class MagicWand extends Item { private static int curMode; List<String> modeNames = Arrays.asList("Explode", "Damage","Fire","Teleport","Stun","Confuse","Fly"); public MagicWand() { setCreativeTab(CreativeTabs.tabCombat); setMaxStackSize(1); setMaxDamage(0); } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (itemStack.getTagCompound()!=null) { curMode=itemStack.getTagCompound().getInteger("magicMode"); } if (curMode==6 && !player.isSneaking()) { if(!player.worldObj.isRemote) { player.capabilities.allowFlying = !player.capabilities.allowFlying; player.capabilities.isFlying = player.capabilities.allowFlying; player.addChatMessage(new ChatComponentText("Fly mode: " + Boolean.toString(player.capabilities.allowFlying))); } }else { if (player.isSneaking()) { if (itemStack.getTagCompound()==null) { itemStack.setTagCompound(new NBTTagCompound()); itemStack.getTagCompound().setInteger("magicMode", 0); curMode=0; } NBTTagCompound nbt=itemStack.getTagCompound(); nbt.setInteger("magicMode",shuffle(nbt.getInteger("magicMode")+1)); if(!player.worldObj.isRemote) { player.addChatMessage(new ChatComponentText("Switched to " + modeNames.get(itemStack.getTagCompound().getInteger("magicMode")) + " mode")); } curMode=nbt.getInteger("magicMode"); } else if ((player.capabilities.isCreativeMode || player.inventory.consumeInventoryItem(InitItems.magic_essence)) && !player.isSneaking()) { player.swingItem(); if (!world.isRemote) { world.spawnEntityInWorld(new EntityMagic(world, player)); } } } return itemStack; } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) { if (stack.getTagCompound()!=null) { tooltip.add(modeNames.get(stack.getTagCompound().getInteger("magicMode"))); } } public Integer shuffle(int toParse) { if(toParse>(modeNames.size())-1) { toParse=0; } return toParse; } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { return true; } @Override public boolean hitEntity(ItemStack itemStack, EntityLivingBase hitReceiever, EntityLivingBase hitter) { hitReceiever.addPotionEffect(new PotionEffect(2, 150, 10)); hitReceiever.attackEntityFrom(DamageSource.magic, 5); return true; } public static int getMode() { return curMode; } } Edited July 15, 20178 yr by Mister_
July 15, 20178 yr Author Is this a possible bug, or am I just using outdated code? Can anyone reproduce this?
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.