Why does this code not work propely?

Started by Notify2468 on

Topic category: General discussion

Last seen on 05:03, 23. Oct 2020
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Why does this code not work propely?

I have this code which activates when the entity is right-clicked. But it doesn't work properly for some reason. What happens is that the first part of the code activates but when the "Tamed" double becomes true the if statement still activates the first part of the code. And the else if part of the code does not function. Am I doing something wrong with the code or is it just a bug. If it is a bug is there any way I can go around this bug? I think the problem is that the "Tamed" part is not turning to true, but I can't find the reason.

The code goes like this;

double Tamed = false;
        if (((Tamed) == false)) {
            if ((((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
                    .getItem() == new ItemStack(Items.DIAMOND, (int) (1)).getItem())) {
                if (entity instanceof EntityPlayer)
                    ((EntityPlayer) entity).inventory.clearMatchingItems(new ItemStack(Items.DIAMOND, (int) (1)).getItem(), -1, (int) 1, null);
                if (world instanceof WorldServer)
                    ((WorldServer) world).spawnParticle(EnumParticleTypes.HEART, x, y, z, (int) 10, 1, 3, 1, 1, new int[0]);
                if (entity instanceof EntityLivingBase) {
                    ((EntityLivingBase) entity).swingArm(EnumHand.MAIN_HAND);
                }
                Tamed = (double) true;
            }
        } else if (((Tamed) == true)) {
            if ((((entity instanceof EntityLivingBase) ? ((EntityLivingBase) entity).getHeldItemMainhand() : ItemStack.EMPTY)
                    .getItem() == new ItemStack(ItemLapisPowder.block, (int) (1)).getItem())) {
                if (entity instanceof EntityLivingBase)
                    ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, (int) 1, (int) 1));
                if (entity instanceof EntityPlayer)
                    ((EntityPlayer) entity).inventory.clearMatchingItems(new ItemStack(ItemLapisPowder.block, (int) (1)).getItem(), -1, (int) 1,
                            null);
                if (world instanceof WorldServer)
                    ((WorldServer) world).spawnParticle(EnumParticleTypes.HEART, x, y, z, (int) 10, 1, 3, 1, 1, new int[0]);
                if (entity instanceof EntityLivingBase) {
                    ((EntityLivingBase) entity).swingArm(EnumHand.MAIN_HAND);
                }
            }
        }
    }
}

 

 

Last seen on 14:12, 3. Jun 2023
Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Double variables are numbers…
Mon, 04/20/2020 - 13:56

Double variables are numbers, not true/false. You might want to use "boolean" instead