added player_picks_up_item and better docs on events.
This commit is contained in:
1 parent
e8b2060fb3
commit
9ca7892859
10 files changed
+415
-113
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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 static carpet.script.CarpetEventServer.Event.PLAYER_PICKS_UP_ITEM;
|
||||
|
||||
@Mixin(PlayerInventory.class)
|
||||
public abstract class PlayerInventory_scarpetEventMixin
|
||||
{
|
||||
@Shadow @Final public PlayerEntity player;
|
||||
|
||||
@Redirect(method = "insertStack(Lnet/minecraft/item/ItemStack;)Z", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/entity/player/PlayerInventory;insertStack(ILnet/minecraft/item/ItemStack;)Z"
|
||||
))
|
||||
private boolean onItemAcquired(PlayerInventory playerInventory, int slot, ItemStack stack)
|
||||
{
|
||||
if (!PLAYER_PICKS_UP_ITEM.isNeeded() || !(player instanceof ServerPlayerEntity))
|
||||
return playerInventory.insertStack(-1, stack);
|
||||
Item item = stack.getItem();
|
||||
int count = stack.getCount();
|
||||
boolean res = playerInventory.insertStack(-1, stack);
|
||||
if (res)
|
||||
{
|
||||
ItemStack diffStack = new ItemStack(item, count - stack.getCount());
|
||||
diffStack.setTag(stack.getTag());
|
||||
PLAYER_PICKS_UP_ITEM.onItemAction((ServerPlayerEntity) player, null, diffStack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user