Skip to content

Commit

Permalink
fix item throttle to actually only effect items and not all entities (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
Alexdoru and github-actions[bot] authored Sep 17, 2022
1 parent a7546e3 commit 4ee2c87
Showing 1 changed file with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
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 =
@At(
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);
}
}

0 comments on commit 4ee2c87

Please sign in to comment.