added player_picks_up_item and better docs on events.

This commit is contained in:
gnembon committed 2020-09-23 03:26:39 -03:00
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
@@ -14,7 +14,7 @@ __on_player_deploys_elytra(player) -> (
__on_player_wakes_up(player) -> (
print('');
print('__on_player_wakes_up(player)');
print('Player '+player+' wakes up. Lemme know when this starts working')
print('Player '+player+' wakes up')
);
__on_player_rides(player, forward, strafe, jumping, sneaking) ->
@@ -271,9 +271,18 @@ __on_player_swaps_hands(player) -> (
print(' Player '+player+' swaps hands.')
);
__on_player_collides_with_entity(player, entity) ->
// too much spam
//__on_player_collides_with_entity(player, entity) ->
//(
// print('');
// print('__on_player_collides_with_entity(player, entity)');
// print(' Player '+player+' collides with '+entity);
//);
__on_player_picks_up_item(player, item) ->
(
print('');
print('__on_player_collides_with_entity(player, entity)');
print(' Player '+player+' collides with '+entity);
)
print('__on_player_picks_up_item(player, item)');
print(' Player '+player+' injects '+item);
);
+1
View File
@@ -163,6 +163,7 @@
"FallingBlockEntity_scarpetEventsMixin",
"BlockItem_scarpetEventMixin",
"PlayerManager_scarpetEventsMixin",
"PlayerInventory_scarpetEventMixin",
"ChunkTicketManager_scarpetMixin",
"StatType_scarpetMixin",