Skip to content

Commit

Permalink
Fix machine gun skeletons
Browse files Browse the repository at this point in the history
This fixes the problems where all skeletons would skip their attack
delay.

Closes #1033
  • Loading branch information
rubensworks committed Jul 20, 2024
1 parent 8737ecb commit 2e8fca1
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.neoforged.neoforge.event.level.BlockEvent;
import org.cyclops.cyclopscore.helper.EnchantmentHelpers;
import org.cyclops.evilcraft.RegistryEntries;
import org.cyclops.evilcraft.core.algorithm.Wrapper;

import java.util.Random;

Expand All @@ -18,14 +19,15 @@
public class EnchantmentEffectComponentAmplifyDamage {

@SubscribeEvent(priority = EventPriority.NORMAL)
public void breakingEvent(LivingDamageEvent.Post event) {
public void livingDamage(LivingDamageEvent.Post event) {
if (!event.getEntity().getCommandSenderWorld().isClientSide() && event.getSource().getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) event.getSource().getEntity();
InteractionHand hand = entity.getUsedItemHand();
if (hand != null) {
ItemStack itemStack = entity.getItemInHand(hand);
amplifyDamage(itemStack);
entity.setItemInHand(hand, itemStack);
if (amplifyDamage(itemStack)) {
entity.setItemInHand(hand, itemStack);
}
}
}
}
Expand All @@ -36,13 +38,15 @@ public void breakingEvent(BlockEvent.BreakEvent event) {
InteractionHand hand = event.getPlayer().getUsedItemHand();
if (hand != null) {
ItemStack itemStack = event.getPlayer().getItemInHand(hand);
amplifyDamage(itemStack);
event.getPlayer().setItemInHand(hand, itemStack);
if (amplifyDamage(itemStack)) {
event.getPlayer().setItemInHand(hand, itemStack);
}
}
}
}

public void amplifyDamage(ItemStack itemStack) {
public boolean amplifyDamage(ItemStack itemStack) {
Wrapper<Boolean> applied = new Wrapper<>(false);
EnchantmentHelpers.runIterationOnItem(itemStack, (enchantment, level) -> {
int modifier = enchantment.value().effects().getOrDefault(RegistryEntries.ENCHANTMENTEFFECT_COMPONENT_AMPLIFY_DAMAGE.get(), 0);
if (modifier > 0) {
Expand All @@ -51,9 +55,11 @@ public void amplifyDamage(ItemStack itemStack) {
if(random.nextFloat() < 0.6F ? false : random.nextInt(level + 1) > 0
&& newDamage <= itemStack.getMaxDamage()) {
itemStack.setDamageValue(newDamage);
applied.set(true);
}
}
});
return applied.get();
}

}

0 comments on commit 2e8fca1

Please sign in to comment.