Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.rettichlp.ucutils.mixin;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -17,28 +19,30 @@
import static de.rettichlp.ucutils.UCUtils.storage;
import static net.minecraft.world.item.Items.GLASS_BOTTLE;

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

@Unique
private final static List<Vec3> SHOP_LOCATIONS = List.of(
new Vec3(47, 69, 203),
new Vec3(1027, 69, 275)
);

@Inject(method = "drop", at = @At("RETURN"), cancellable = true)
private void ucutils$dropHead(ItemStack itemStack, boolean randomly, boolean thrownFromHand, CallbackInfoReturnable<ItemEntity> cir) {
public LocalPlayerMixin(ClientLevel level, GameProfile gameProfile) {
super(level, gameProfile);
}

@Inject(method = "drop", at = @At("HEAD"), cancellable = true)
private void ucutils$dropHead(boolean all, CallbackInfoReturnable<Boolean> cir) {
if (!storage.isUnicaCity()) {
return;
}

if (cir.getReturnValue() == null) {
return;
}
ItemStack selectedItem = getInventory().getSelectedItem();

if (player.getMainHandItem().is(GLASS_BOTTLE) && isNearShop()) {
if (selectedItem.is(GLASS_BOTTLE) && isNearShop()) {
// cancel drop
cir.setReturnValue(null);
cir.cancel();

// execute command
commandService.sendCommand("sell pfand");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/ucutils.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"EntityHitboxDebugRendererMixin",
"EntityRendererMixin",
"GuiMixin",
"LivingEntityMixin",
"LocalPlayerMixin",
"PauseScreenMixin",
"PlayerTabOverlayMixin"
]
Expand Down