use of net.minecraft.network.protocol.game.ServerboundUseItemOnPacket in project SpongeCommon by SpongePowered.
the class PacketPhase method setupPacketToStateMapping.
private void setupPacketToStateMapping() {
this.packetTranslationMap.put(ServerboundKeepAlivePacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundChatPacket.class, packet -> PacketPhase.General.CHAT_COMMAND);
this.packetTranslationMap.put(ServerboundInteractPacket.class, packet -> {
final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
final ServerboundInteractPacket.Action action = useEntityPacket.getAction();
if (action == ServerboundInteractPacket.Action.INTERACT) {
return PacketPhase.General.INTERACT_ENTITY;
} else if (action == ServerboundInteractPacket.Action.ATTACK) {
return PacketPhase.General.ATTACK_ENTITY;
} else if (action == ServerboundInteractPacket.Action.INTERACT_AT) {
return PacketPhase.General.INTERACT_AT_ENTITY;
} else {
return PacketPhase.General.INVALID;
}
});
this.packetTranslationMap.put(ServerboundMovePlayerPacket.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.Pos.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.Rot.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.PosRot.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundPlayerActionPacket.class, packet -> {
final ServerboundPlayerActionPacket playerDigging = (ServerboundPlayerActionPacket) packet;
final ServerboundPlayerActionPacket.Action action = playerDigging.getAction();
final IPhaseState<? extends PacketContext<?>> state = PacketPhase.INTERACTION_ACTION_MAPPINGS.get(action);
return state == null ? PacketPhase.General.UNKNOWN : state;
});
this.packetTranslationMap.put(ServerboundUseItemOnPacket.class, packet -> {
// Note that CPacketPlayerTryUseItem is swapped with CPacketPlayerBlockPlacement
final ServerboundUseItemOnPacket blockPlace = (ServerboundUseItemOnPacket) packet;
final BlockPos blockPos = blockPlace.getHitResult().getBlockPos();
final Direction front = blockPlace.getHitResult().getDirection();
final MinecraftServer server = SpongeCommon.server();
if (blockPos.getY() < server.getMaxBuildHeight() - 1 || front != Direction.UP && blockPos.getY() < server.getMaxBuildHeight()) {
return PacketPhase.General.PLACE_BLOCK;
}
return PacketPhase.General.INVALID;
});
this.packetTranslationMap.put(ServerboundUseItemPacket.class, packet -> PacketPhase.General.USE_ITEM);
this.packetTranslationMap.put(ServerboundSetCarriedItemPacket.class, packet -> PacketPhase.Inventory.SET_CARRIED_ITEM);
this.packetTranslationMap.put(ServerboundSwingPacket.class, packet -> PacketPhase.General.ANIMATION);
this.packetTranslationMap.put(ServerboundPlayerCommandPacket.class, packet -> {
final ServerboundPlayerCommandPacket playerAction = (ServerboundPlayerCommandPacket) packet;
final ServerboundPlayerCommandPacket.Action action = playerAction.getAction();
return PacketPhase.PLAYER_ACTION_MAPPINGS.get(action);
});
this.packetTranslationMap.put(ServerboundPlayerInputPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
this.packetTranslationMap.put(ServerboundContainerClosePacket.class, packet -> PacketPhase.General.CLOSE_WINDOW);
this.packetTranslationMap.put(ServerboundContainerClickPacket.class, packet -> PacketPhase.fromWindowPacket((ServerboundContainerClickPacket) packet));
this.packetTranslationMap.put(ServerboundContainerAckPacket.class, packet -> PacketPhase.General.UNKNOWN);
this.packetTranslationMap.put(ServerboundSetCreativeModeSlotPacket.class, packet -> PacketPhase.General.CREATIVE_INVENTORY);
this.packetTranslationMap.put(ServerboundContainerButtonClickPacket.class, packet -> PacketPhase.Inventory.ENCHANT_ITEM);
this.packetTranslationMap.put(ServerboundSignUpdatePacket.class, packet -> PacketPhase.General.UPDATE_SIGN);
this.packetTranslationMap.put(ServerboundPlayerAbilitiesPacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundCommandSuggestionPacket.class, packet -> PacketPhase.General.TAB_COMPLETE);
this.packetTranslationMap.put(ServerboundClientCommandPacket.class, packet -> {
final ServerboundClientCommandPacket clientStatus = (ServerboundClientCommandPacket) packet;
final ServerboundClientCommandPacket.Action status = clientStatus.getAction();
if (status == ServerboundClientCommandPacket.Action.PERFORM_RESPAWN) {
return PacketPhase.General.REQUEST_RESPAWN;
}
return PacketPhase.General.IGNORED;
});
this.packetTranslationMap.put(ServerboundCustomPayloadPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
this.packetTranslationMap.put(ServerboundTeleportToEntityPacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundResourcePackPacket.class, packet -> PacketPhase.General.RESOURCE_PACK);
this.packetTranslationMap.put(ServerboundPlaceRecipePacket.class, packet -> PacketPhase.Inventory.PLACE_RECIPE);
}
use of net.minecraft.network.protocol.game.ServerboundUseItemOnPacket in project SpongeCommon by SpongePowered.
the class PlaceBlockPacketState method populateContext.
@Override
public void populateContext(final net.minecraft.server.level.ServerPlayer playerMP, final Packet<?> packet, final BasicPacketContext context) {
final ServerboundUseItemOnPacket placeBlock = (ServerboundUseItemOnPacket) packet;
final net.minecraft.world.item.ItemStack itemUsed = playerMP.getItemInHand(placeBlock.getHand());
final ItemStack itemstack = ItemStackUtil.cloneDefensive(itemUsed);
context.itemUsed(itemstack);
final HandType handType = (HandType) (Object) placeBlock.getHand();
context.handUsed(handType);
}
Aggregations