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

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 by Mister_

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

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.