Zyke
-
Posts
7 -
Joined
-
Last visited
Posts posted by Zyke
-
-
You don't understand how overrides work.
Just because a function has the same name doesn't mean it's going to be called in the same instances as the original function, but magically pull additional parameters. The @Override annotation does nothing but throw errors when the function you have isn't actually overriding anything.
Because that's what it is. An annotation. A clue to the IDE that "hey, error check this in this special way please."
In any case, you actually don't need a reference to the player there. If you open up ItemStack.java and look at that function, you'll find the only thing it needs the player for is to prevent item damage while in creative mode. If you pass null, the item will work and take damage JUST FINE.
Do you mean itemInteractionForEntity is going to be the same, even if I add another parameter like World?
Also, passing null for the itemStack damage crashes the game, when in survival and creative. I don't know if it is my fault or null just cannot be used.
-
setDead() works fine, but in this case, I think that the whole method is not working because I didn't override it. Doing that would not allow me to use EntityPlayer as a parameter. Any ideas on how I can use entityPlayer in the method?
@Override public boolean itemInteractionForEntity(ItemStack itemStack, EntityLiving entityLiving /*, EntityPlayer entityPlayer*/) { entityLiving.setDead(); itemStack.damageItem(1, entityPlayer); << I need entityPlayer return true; }
-
Try using world.removeEntity(Entity par1);
Doesn't seem to work either.
If removeEntity says this:
public void removeEntity(Entity par1Entity) { if (par1Entity.riddenByEntity != null) { par1Entity.riddenByEntity.mountEntity((Entity)null); } if (par1Entity.ridingEntity != null) { par1Entity.mountEntity((Entity)null); } par1Entity.setDead(); if (par1Entity instanceof EntityPlayer) { this.playerEntities.remove(par1Entity); this.updateAllPlayersSleepingFlag(); } }
then basically is doing the same as setDead(), but being just a bit more specific about what the entity is doing, right?
-
I'm trying to kill a mob on right-click with an item, but without "hurting" the mob because that would make it drop items (and I don't want that as you can probably guess).
entityLiving.setDead() and entityLiving.kill() don't seem to work. Any ideas?
public boolean itemInteractionForEntity(ItemStack itemStack, EntityLiving entityLiving, EntityPlayer entityPlayer) { entityLiving.kill(); itemStack.damageItem(1, entityPlayer); return true; }
-
Although that didn't answer my question, thanks for the clarification.
-
I'm trying to make an item that, when right clicking, destroys obsidian instantly. This is the code in the item class I made (not all of it):
//@Override < I read somewhere that I needed to override, but adding that gives me another error public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z) { System.out.println("Something happened!"); if(!world.isRemote) { if (world.getBlockId(x, y, z) == Block.obsidian.blockID) { itemStack.damageItem(1, entityPlayer); world.destroyBlock(x, y, z, true); } } return true; }
The problem is that nothing is happening when I right click on anything. Nothing gets printed out. What am I doing wrong? Do I have to use onGameTick or sometihng?
Edit: Apparently this seems to do the job:
public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { int blockId = world.getBlockId(x, y, z); if (blockId == Block.obsidian.blockID) { itemStack.damageItem(1, player); world.destroyBlock(x, y, z, true); return !world.isRemote; } return false; }
[1.5] Instakill an entity
in Modder Support
Posted
Thanks everyone for the help Everything works as it should, except the item getting damaged. I was probably going to make it a one-use item anyway.