Skip to content

Commit

Permalink
Fix lightning-struck villagers always becoming werewolves
Browse files Browse the repository at this point in the history
Closes #1052
  • Loading branch information
rubensworks committed Sep 1, 2024
1 parent 92ea763 commit a084dbc
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void empowerItem(EntityStruckByLightningEvent event) {
}

private LightningBolt lastLightningBolt;
private Set<Villager> affectedVillagers;
private Set<Integer> affectedVillagers;

private void transformVillager(EntityStruckByLightningEvent event) {
if (event.getEntity() instanceof Villager) {
Expand All @@ -55,16 +55,17 @@ private void transformVillager(EntityStruckByLightningEvent event) {
lastLightningBolt = event.getLightning();
affectedVillagers = new HashSet<>();
}
if(!affectedVillagers.add(entity)) {
if(!affectedVillagers.add(entity.getId())) {
// The same lightning bolt will strike multiple times. Only count the first time it hits any entity
event.setCanceled(true);
return;
}
if(entity.getLevel().random.nextBoolean()) {
event.setCanceled(true); // 50% chance that they become a witch like vanilla does
return;
event.setCanceled(false);
return; // 50% chance that they become a witch like vanilla does
}
if(entity.getVillagerData().getProfession() != RegistryEntries.VILLAGER_PROFESSION_WEREWOLF) {
event.setCanceled(true);
EntityWerewolf.initializeWerewolfVillagerData(entity);
}
}
Expand Down

0 comments on commit a084dbc

Please sign in to comment.