From 4ee2c878327fdf4f4446aacb4a51da7fe2672a8f Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 17 Sep 2022 08:43:56 +0200 Subject: [PATCH] fix item throttle to actually only effect items and not all entities (#113) * fix item throttle to actually only effect items and not all entities * spotlessApply (#114) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../mixins/minecraft/MixinEntityPlayer.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/minecraft/MixinEntityPlayer.java b/src/main/java/com/mitchej123/hodgepodge/mixins/minecraft/MixinEntityPlayer.java index a1a54be0..f94f4ac1 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/minecraft/MixinEntityPlayer.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/minecraft/MixinEntityPlayer.java @@ -1,19 +1,44 @@ package com.mitchej123.hodgepodge.mixins.minecraft; import com.mitchej123.hodgepodge.Hodgepodge; -import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityPlayer.class) -public class MixinEntityPlayer { +public abstract class MixinEntityPlayer { + + private int hodgepodge$itemEntityCounter; + + @Shadow + protected abstract void collideWithPlayer(Entity p_71044_1_); + + @Inject( + method = "onLivingUpdate", + at = + @At( + value = "INVOKE", + target = + "Lnet/minecraft/world/World;getEntitiesWithinAABBExcludingEntity(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/AxisAlignedBB;)Ljava/util/List;", + shift = At.Shift.AFTER)) + public void hodgepodge$resetItemCounter(CallbackInfo ci) { + hodgepodge$itemEntityCounter = 0; + } @Redirect( method = "onLivingUpdate", - at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", remap = false), + at = + @At( + value = "INVOKE", + target = + "Lnet/minecraft/entity/player/EntityPlayer;collideWithPlayer(Lnet/minecraft/entity/Entity;)V"), slice = @Slice( from = @@ -21,7 +46,14 @@ public class MixinEntityPlayer { value = "INVOKE", target = "Lnet/minecraft/world/World;getEntitiesWithinAABBExcludingEntity(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/AxisAlignedBB;)Ljava/util/List;"))) - public int hodgepodge$ThrottleItemPickupEvent(List instance) { - return Math.min(Hodgepodge.config.itemStacksPickedUpPerTick, instance.size()); + public void hodgepodge$ThrottleItemPickupEvent(EntityPlayer instance, Entity entity) { + if (entity instanceof EntityItem) { + if (hodgepodge$itemEntityCounter < Hodgepodge.config.itemStacksPickedUpPerTick) { + this.collideWithPlayer(entity); + } + hodgepodge$itemEntityCounter++; + return; + } + this.collideWithPlayer(entity); } }