#Need help with area damage

17 messages · Page 1 of 1 (latest)

last coyote
#

So basically I'm making a weapon, which when right click is held is supposed damage every entities (except the player) in a specified radius every ~1sec.

I found a way to detect every entities in this radius :

public void radius(PlayerEntity player){ int maxDistanceFromPlayer = 5; Box entityBox = new Box(player.getBlockPos()).expand(maxDistanceFromPlayer); List entityList = player.getWorld().getEntitiesByClass(MobEntity.class, entityBox, e -> e.isAlive()); player.sendMessage(Text.literal(entityList.toString())); }

But I cannot find a way to damage them ??

If you could also tell me how to change the damage amount and rate of damage accordingly to damage amount and attack speed specified in in the item attributeModifier

here is the github repo : https://github.com/FROSTYTRIX/frostytrixs-random-items-mod-1.21.1

GitHub

Contribute to FROSTYTRIX/frostytrixs-random-items-mod-1.21.1 development by creating an account on GitHub.

minor quail
#

Run something like entityList.forEach((entity) -> entity.damage(source, 4f)

#

In this case, 4f would be your damage value (4) and the source would be a damage source

last coyote
# minor quail Run something like `entityList.forEach((entity) -> entity.damage(source, 4f)`

okay so i couldn't make it work with this, not sure why, but I managed to make it work like that :
for (Object entity : entityList) { if (entity instanceof MobEntity && ((MobEntity) entity).getY() >= player.getY() && ((MobEntity) entity).getY() <= (player.getY()+2)){ ((MobEntity) entity).damage(player.getDamageSources().generic(), 4f); player.sendMessage(Text.literal("Damaged :" + entity)); } }

minor quail
#

Your conditional says: I am true if my position y is greater than player position y AND if my position y is less than player position y + 2
Also, use a pattern variable
Additionally, your list should be of type entity and not object

last coyote
last coyote
minor quail
#

!!paste is probably better

cold laurelBOT
#
Using a Paste Site

When sharing a large piece of code or a log, you should use a paste site instead of uploading a file or dumping it in a large codeblock.
Dumping your code/log in a code block or a message can make it difficult for other people to read previous messages.

Paste sites and their size limits:

» GitHub Gist: 100 MiB / Requires an account
» Paste.gg: 15 MiB / Account is optional
» Mclo.gs: 10 MiB / Anonymous (designed specifically for Minecraft logs)
» Paste.ee: 1 MiB / Account is optional (raises limit to 6 MiB)
» Pastebin.com: 512 KiB / Account is optional
» Hastebin.com: 400 KiB / Anonymous

last coyote
minor quail
#

Go learn about generics
Your entitylist should be a List<MobEntity>

#

As for the condition, you’ll have to debug why it’s not working
Try hitting a mob that is one block above your feet

last coyote
last coyote