Armor that deals damage to entites when collided with them.

Started by KBEHAN on

Topic category: Help with modding (Java Edition)

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Armor that deals damage to entites when collided with them.

Hi, I am making a helmet that I want it to be able so when the player is wearing it and collides with any entity it will hurt that entity.  @Nuparu00 was helpful with the idea on how to code it.  This is some code that someone else gave me:

AxisAlignedBB axisalignedbb = player.getEntityBoundingBox();
List<?> list1 = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
        
if (!list1.isEmpty())
{
    Iterator<?> iterator = list1.iterator();
            
    while (iterator.hasNext())
    {
        EntityLivingBase entitylivingbase = (EntityLivingBase)iterator.next();               
        entitylivingbase.attackEntityFrom(DamageSource.causeThornsDamage(player), 36F);
    }
}
}
}
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
    {if(stack != null){
        if(stack.getItem() == mcreator_jaspersHelmet.block){
           return "JasperCHelm.png";
}
}

 

I pasted it into my code and got these 4 errors:

 

/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_jaspersCrashHelmet.java:101: error: class mcreator_jaspersHelmet is public, should be declared in a file named mcreator_jaspersHelmet.java
>public class mcreator_jaspersHelmet{
>       ^
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/TestEnvironmentMod.java:260: error: cannot find symbol
>mcreator_jaspersCrashHelmet mcreator_152 = new mcreator_jaspersCrashHelmet();
>^
>  symbol:   class mcreator_jaspersCrashHelmet
>  location: class TestEnvironmentMod
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/TestEnvironmentMod.java:260: error: cannot find symbol
>mcreator_jaspersCrashHelmet mcreator_152 = new mcreator_jaspersCrashHelmet();
>                                               ^
>  symbol:   class mcreator_jaspersCrashHelmet
>  location: class TestEnvironmentMod
>/Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_jaspersCrashHelmet.java:135: error: cannot find symbol
>AxisAlignedBB axisalignedbb = player.getEntityBoundingBox();
>                                    ^
>  symbol:   method getEntityBoundingBox()
>  location: variable player of type EntityPlayer
>Note: /Applications/MCreator 1.5.9 [1.7.10] Mac-Linux/forge/build/sources/java/mod/mcreator/mcreator_sugilitesFlail.java uses unchecked or unsafe operations.
>4 errors

 

Can anyone please help?  I will be happy to post my code if you ask me to.

Last seen on 17:47, 12. May 2018
Joined Mar 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try to find code for thorns
Mon, 12/05/2016 - 20:45

Try to find code for thorns enchantment in minecraft and replace "when being hit by entity" with "colliding with entity". And sorry, i don't know what code is for either one of them.

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:Try to find code for thorns
Mon, 12/05/2016 - 20:48

@#1 thank you! it's ok, any help is apreciated!

Last seen on 23:21, 14. Apr 2019
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
public void onArmorTickUpdate
Fri, 12/09/2016 - 23:09

public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) {
if(!world.isRemote) {
AxisAlignedBB axisalignedbb = player.boundingBox;
List<?> list1 = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
        
if (!list1.isEmpty())
{
    Iterator<?> iterator = list1.iterator();
            
    while (iterator.hasNext())
   
    {
         System.out.println("DealDamage!");

        EntityLivingBase entitylivingbase = (EntityLivingBase)iterator.next();               
        entitylivingbase.attackEntityFrom(DamageSource.causeThornsDamage(player), 36F);
    }
}
}
}
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
    {if(stack != null){
        if(stack.getItem() == mcreator_jaspersCrashHelmet.block){
           return "JasperCHelm.png";
}
}
return (String)null;
}

 

this is my code now.  I had a coder help me.  But we can't seem to figure out why it's not working.  Maybe it's the thorns code or something before it.