Skip to content

Commit

Permalink
Revert "Fix xp orb collection detection"
Browse files Browse the repository at this point in the history
This reverts commit e161585.
  • Loading branch information
Earthcomputer committed Dec 2, 2024
1 parent e161585 commit e2247d9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.earthcomputer.clientcommands.mixin.rngevents;

import com.llamalad7.mixinextras.sugar.Local;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.earthcomputer.clientcommands.util.MultiVersionCompat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Arrays;

@Mixin(ClientLevel.class)
public class ClientLevelMixin {
@Inject(method = "removeEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;onClientRemoval()V"))
private void onRemoveEntity(int entityId, Entity.RemovalReason reason, CallbackInfo ci, @Local Entity entity) {
if (entity instanceof ExperienceOrb) {
LocalPlayer player = Minecraft.getInstance().player;
assert player != null;
if (player.getBoundingBox().expandTowards(1.25, 0.75, 1.25).intersects(entity.getBoundingBox())) {
PlayerRandCracker.onXpOrb();
if (Arrays.stream(EquipmentSlot.values()).anyMatch(slot -> couldMendingRepair(player.getItemBySlot(slot)))) {
PlayerRandCracker.onMending();
}
}
}
}

@Unique
private boolean couldMendingRepair(ItemStack stack) {
if (!EnchantmentHelper.has(stack, EnchantmentEffectComponents.REPAIR_WITH_XP)) {
return false;
}
if (MultiVersionCompat.INSTANCE.getProtocolVersion() <= MultiVersionCompat.V1_15_2) {
return true; // xp may try to mend items even if they're fully repaired pre-1.16
}
return stack.isDamaged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

import com.mojang.authlib.GameProfile;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.earthcomputer.clientcommands.util.MultiVersionCompat;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Arrays;

@Mixin(LocalPlayer.class)
public class LocalPlayerMixin extends AbstractClientPlayer {

Expand All @@ -31,23 +22,4 @@ public LocalPlayerMixin(ClientLevel level, GameProfile profile) {
public void onDrop(boolean dropAll, CallbackInfoReturnable<ItemEntity> ci) {
PlayerRandCracker.onDropItem();
}

@Inject(method = "setExperienceValues", at = @At("HEAD"))
private void onSetExperienceValues(CallbackInfo ci) {
PlayerRandCracker.onXpOrb();
if (Arrays.stream(EquipmentSlot.values()).anyMatch(slot -> couldMendingRepair(getItemBySlot(slot)))) {
PlayerRandCracker.onMending();
}
}

@Unique
private boolean couldMendingRepair(ItemStack stack) {
if (!EnchantmentHelper.has(stack, EnchantmentEffectComponents.REPAIR_WITH_XP)) {
return false;
}
if (MultiVersionCompat.INSTANCE.getProtocolVersion() <= MultiVersionCompat.V1_15_2) {
return true; // xp may try to mend items even if they're fully repaired pre-1.16
}
return stack.isDamaged();
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.clientcommands.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"dataqueryhandler.ClientPacketListenerMixin",
"events.ClientPacketListenerMixin",
"lengthextender.ChatScreenMixin",
"rngevents.ClientLevelMixin",
"scrambletitle.MinecraftMixin",
"serverbrand.ClientCommonPacketListenerImplMixin",
"suggestionshook.ClientPacketListenerMixin"
Expand Down

0 comments on commit e2247d9

Please sign in to comment.