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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
{
|
||||
@Shadow public ServerPlayerEntity player;
|
||||
|
||||
@Inject(method = "onPlayerInput", at = @At(value = "RETURN"))
|
||||
@Inject(method = "onPlayerInput", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;method_14218(FFZZ)V"))
|
||||
private void checkMoves(PlayerInputC2SPacket p, CallbackInfo ci)
|
||||
{
|
||||
if (PLAYER_RIDES.isNeeded() && (p.getSideways() != 0.0F || p.getForward() != 0.0F || p.isJumping() || p.isSneaking()))
|
||||
|
||||
@@ -50,8 +50,7 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
||||
if (PLAYER_FINISHED_USING_ITEM.isNeeded())
|
||||
{
|
||||
Hand hand = getActiveHand();
|
||||
ItemStack stack = getActiveItem().copy();
|
||||
PLAYER_FINISHED_USING_ITEM.onItemAction((ServerPlayerEntity) (Object)this, hand, stack);
|
||||
PLAYER_FINISHED_USING_ITEM.onItemAction((ServerPlayerEntity) (Object)this, hand, getActiveItem());
|
||||
// do vanilla
|
||||
super.consumeItem();
|
||||
}
|
||||
|
||||
@@ -416,7 +416,21 @@ public class CarpetEventServer
|
||||
), player::getCommandSource);
|
||||
}
|
||||
};
|
||||
// todo PlayerInventory.insertStack... for definite item inventory pickup, when result protocol has be set
|
||||
public static final Event PLAYER_PICKS_UP_ITEM = new Event("player_picks_up_item", 2, false)
|
||||
{
|
||||
@Override
|
||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack) {
|
||||
handler.call( () ->
|
||||
{
|
||||
//ItemStack itemstack = player.getStackInHand(enumhand);
|
||||
return Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> ListValue.fromItemStack(itemstack))
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Event PLAYER_ATTACKS_ENTITY = new Event("player_attacks_entity", 2, false)
|
||||
{
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user