Skip to content

Commit

Permalink
Fix pixie-applied wither effect not actually causing any damage
Browse files Browse the repository at this point in the history
Fixes #4724 and also helps with potential cyclic dependency issues involving static initializers of multiple mods.
  • Loading branch information
TheRealWormbo committed Jul 20, 2024
1 parent 686633b commit 26fb971
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.Util;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EquipmentSlot;
Expand All @@ -30,9 +29,11 @@
import vazkii.botania.common.item.equipment.armor.elementium.ElementiumHelmItem;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;

Expand All @@ -50,12 +51,12 @@ private PixieHandler() {}
m.put(EquipmentSlot.OFFHAND, UUID.fromString("34f62de8-f652-4fe7-899f-a8fc938c4940"));
});

private static final MobEffect[] potions = {
MobEffects.BLINDNESS,
MobEffects.WITHER,
MobEffects.MOVEMENT_SLOWDOWN,
MobEffects.WEAKNESS
};
private static final List<Supplier<MobEffectInstance>> effectSuppliers = List.of(
() -> new MobEffectInstance(MobEffects.BLINDNESS, 40, 0),
() -> new MobEffectInstance(MobEffects.WITHER, 50, 0),
() -> new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 0),
() -> new MobEffectInstance(MobEffects.WEAKNESS, 40, 0)
);

public static void registerAttribute(BiConsumer<Attribute, ResourceLocation> r) {
r.accept(PIXIE_SPAWN_CHANCE, prefix("pixie_spawn_chance"));
Expand All @@ -78,7 +79,7 @@ public static void onDamageTaken(Player player, DamageSource source) {
pixie.setPos(player.getX(), player.getY() + 2, player.getZ());

if (((ElementiumHelmItem) BotaniaItems.elementiumHelm).hasArmorSet(player)) {
pixie.setApplyPotionEffect(new MobEffectInstance(potions[player.level().random.nextInt(potions.length)], 40, 0));
pixie.setApplyPotionEffect(effectSuppliers.get(player.level().random.nextInt(effectSuppliers.size())).get());
}

float dmg = 4;
Expand Down

0 comments on commit 26fb971

Please sign in to comment.