Topic category: Help with Minecraft modding (Java Edition)
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.
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.
@#1 thank you! it's ok, any help is apreciated!
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.