XpNoCooldown and combineXpOrbs refactor (#1149)

* - Fix xpNoCooldown to work as it did in 1.17-
- Remove XPcombine
- Use vanilla merge methods

* Remove debug code

* fix: rollback sort carpet.mixins.json

* rework: nerf xp cooldown absorption a little

* remove: combineXpOrbs
fix: xpCooldown

* revert renames

* fix newlines

* fix: wrong implementation for absorption

* add missing `private` keyword

* fix: player xp cooldown set wrongly

* fix: injection point to be within condition
This commit is contained in:
Crec0 authored and GitHub committed 2021-11-28 23:39:13 +01:00
1 parent 4af1d66450
commit 28a5e7acf1
6 files changed
+54 -204

No files matched your search

@@ -1,87 +1,44 @@
package carpet.mixins;
import carpet.CarpetSettings;
import carpet.fakes.ExperienceOrbInterface;
import carpet.helpers.XPcombine;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
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.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.Map;
@Mixin(ExperienceOrbEntity.class)
public abstract class ExperienceOrbEntityMixin implements ExperienceOrbInterface
{
@Shadow private int amount;
public abstract class ExperienceOrbEntityMixin {
@Shadow
private int pickingCount;
@Shadow private int pickingCount;
@Shadow
private int amount;
@Shadow protected abstract int getMendingRepairCost(int repairAmount);
@Shadow
protected abstract int repairPlayerGears(PlayerEntity player, int amount);
@Shadow protected abstract int getMendingRepairAmount(int experienceAmount);
public void setAmount(int amount) { this.amount = amount; }
public int combineDelay = 50;
public int getCombineDelay() { return combineDelay; }
public void setCombineDelay(int what) { combineDelay = what; }
@Inject(method = "tick",
@Inject(
method = "onPlayerCollision",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/ExperienceOrbEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V",
shift = At.Shift.AFTER
))
void checkCombineAtTick(CallbackInfo ci)
{
if (CarpetSettings.combineXPOrbs)
{
if (getCombineDelay() > 0)
{
setCombineDelay(getCombineDelay()-1);
value = "FIELD",
target = "net/minecraft/entity/player/PlayerEntity.experiencePickUpDelay:I",
ordinal = 0
)
)
private void addXP(PlayerEntity player, CallbackInfo ci) {
if (CarpetSettings.xpNoCooldown) {
player.experiencePickUpDelay = 0;
// reducing the count to 1 and leaving vanilla to deal with it
while (this.pickingCount > 1) {
int remainder = this.repairPlayerGears(player, this.amount);
if (remainder > 0) {
player.addExperience(remainder);
}
this.pickingCount--;
}
if (getCombineDelay() == 0)
{
XPcombine.searchForOtherXPNearby((ExperienceOrbEntity) (Object) this);
}
}
}
@Override
public int getCount() {
return pickingCount;
}
@Override
public void setCount(int i) {
pickingCount = i;
}
@Inject(method = "onPlayerCollision", at = @At("HEAD"))
void removeDelay(PlayerEntity playerEntity_1, CallbackInfo ci)
{
if (CarpetSettings.xpNoCooldown)
playerEntity_1.experiencePickUpDelay = 0;
}
@Redirect(method = "onPlayerCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addExperience(I)V"))
void addXP(PlayerEntity playerEntity, int experience)
{
playerEntity.addExperience(experience);
if (CarpetSettings.xpNoCooldown) while(pickingCount > 1)
{
pickingCount --;
playerEntity.addExperience(experience);
}
}
}
@@ -0,0 +1,28 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
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.Redirect;
import java.util.List;
@Mixin(PlayerEntity.class)
public abstract class PlayerEntity_xpNoCooldownMixin {
@Shadow
protected abstract void collideWithEntity(Entity entity);
@Redirect(method = "tickMovement",at = @At(value = "INVOKE", target = "java/util/List.add(Ljava/lang/Object;)Z"))
public boolean processXpOrbCollisions(List<Entity> instance, Object e) {
Entity entity = (Entity) e;
if (CarpetSettings.xpNoCooldown) {
this.collideWithEntity(entity);
return true;
}
return instance.add(entity);
}
}