mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Fix some events
This commit is contained in:
@@ -71,7 +71,7 @@ public interface PlayerEvent {
|
||||
}
|
||||
|
||||
interface CraftItem {
|
||||
void craft(Player player, ItemStack smelted, Container inventory);
|
||||
void craft(Player player, ItemStack constructed, Container inventory);
|
||||
}
|
||||
|
||||
interface SmeltItem {
|
||||
|
||||
@@ -26,6 +26,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
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;
|
||||
@@ -35,9 +36,13 @@ public abstract class MixinItemEntity {
|
||||
@Shadow
|
||||
public abstract ItemStack getItem();
|
||||
|
||||
@Unique
|
||||
private ItemStack cache;
|
||||
|
||||
@Inject(method = "playerTouch",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getCount()I"), cancellable = true)
|
||||
private void prePickup(Player player, CallbackInfo ci) {
|
||||
cache = getItem().copy();
|
||||
InteractionResult canPickUp = PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(player, (ItemEntity) (Object) this, getItem());
|
||||
if (canPickUp == InteractionResult.FAIL) {
|
||||
ci.cancel();
|
||||
@@ -47,6 +52,10 @@ public abstract class MixinItemEntity {
|
||||
@Inject(method = "playerTouch",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;take(Lnet/minecraft/world/entity/Entity;I)V"))
|
||||
private void pickup(Player player, CallbackInfo ci) {
|
||||
PlayerEvent.PICKUP_ITEM_POST.invoker().pickup(player, (ItemEntity) (Object) this, getItem());
|
||||
if (cache != null) {
|
||||
PlayerEvent.PICKUP_ITEM_POST.invoker().pickup(player, (ItemEntity) (Object) this, cache);
|
||||
}
|
||||
|
||||
this.cache = null;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class MixinPlayer {
|
||||
|
||||
@Inject(method = "drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;", at = @At("RETURN"), cancellable = true)
|
||||
private void drop(ItemStack itemStack, boolean bl, boolean bl2, CallbackInfoReturnable<ItemEntity> cir) {
|
||||
if (PlayerEvent.DROP_ITEM.invoker().drop((Player) (Object) this, cir.getReturnValue()) == InteractionResult.FAIL) {
|
||||
if (cir.getReturnValue() != null && PlayerEvent.DROP_ITEM.invoker().drop((Player) (Object) this, cir.getReturnValue()) == InteractionResult.FAIL) {
|
||||
cir.setReturnValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ public class MixinMinecraft {
|
||||
@Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/chat/NarratorChatListener;clear()V"))
|
||||
private void handleLogin(Screen screen, CallbackInfo ci) {
|
||||
ClientPlayerEvent.CLIENT_PLAYER_QUIT.invoker().quit(player);
|
||||
if (player != null) {
|
||||
ClientPlayerEvent.CLIENT_PLAYER_QUIT.invoker().quit(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "startUseItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isEmpty()Z", ordinal = 1),
|
||||
|
||||
Reference in New Issue
Block a user