Skip to content

Commit

Permalink
make attacker immune to sword lightning bolt
Browse files Browse the repository at this point in the history
  • Loading branch information
SiverDX authored and TheBv committed Dec 25, 2023
1 parent aac4453 commit 29bad7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,9 @@ public void onVillagerTrades(VillagerTradesEvent event) {

@SubscribeEvent
public void onLightningHit(final EntityStruckByLightningEvent event) {
// TODO :: Set owner UUID in the tags as well to prevent damage to them?
if (event.getLightning().getTags().contains(BOLT_DONT_DESTROY_LOOT) && (event.getEntity() instanceof ItemEntity || event.getEntity() instanceof ExperienceOrb)) {
if ((event.getEntity() instanceof ItemEntity || event.getEntity() instanceof ExperienceOrb) && event.getLightning().getTags().contains(BOLT_DONT_DESTROY_LOOT)) {
event.setCanceled(true);
} else if (event.getLightning().getTags().contains(event.getEntity().getStringUUID())) {
event.setCanceled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ default void hurtEnemy(T item, ItemStack stack, LivingEntity target, LivingEntit
if (!attacker.level.isClientSide && flag) {
LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(target.level);
lightningboltentity.getTags().add(ServerEvents.BOLT_DONT_DESTROY_LOOT);
lightningboltentity.getTags().add(attacker.getStringUUID());
lightningboltentity.moveTo(target.position());
if (!target.level.isClientSide) {
target.level.addFreshEntity(lightningboltentity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public boolean hurtEnemy(@NotNull ItemStack stack, @NotNull LivingEntity target,
if (!attacker.level.isClientSide && flag) {
LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(target.level);
lightningboltentity.getTags().add(ServerEvents.BOLT_DONT_DESTROY_LOOT);
lightningboltentity.getTags().add(attacker.getStringUUID());
lightningboltentity.moveTo(target.position());
if (!target.level.isClientSide) {
target.level.addFreshEntity(lightningboltentity);
Expand Down

0 comments on commit 29bad7e

Please sign in to comment.