-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
a7546e3
commit 4ee2c87
Showing
1 changed file
with
37 additions
and
5 deletions.
There are no files selected for viewing
42 changes: 37 additions & 5 deletions
42
src/main/java/com/mitchej123/hodgepodge/mixins/minecraft/MixinEntityPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |