use of net.minecraft.network.protocol.game.ServerboundInteractPacket 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.ServerboundInteractPacket in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final ServerPlayer player = phaseContext.getPacketPlayer();
final ServerboundInteractPacket useEntityPacket = phaseContext.getPacket();
final net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(player.level);
if (entity == null) {
// Something happened?
return;
}
if (entity instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entity).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, player.getUUID());
} else {
((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
}
TrackingUtil.processBlockCaptures(phaseContext);
}
use of net.minecraft.network.protocol.game.ServerboundInteractPacket in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method isPacketIgnored.
@Override
public boolean isPacketIgnored(Packet<?> packetIn, ServerPlayer packetPlayer) {
final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packetIn;
// There are cases where a player is interacting with an entity that doesn't exist on the server.
final net.minecraft.world.entity.@Nullable Entity entity = useEntityPacket.getTarget(packetPlayer.level);
return entity == null;
}
use of net.minecraft.network.protocol.game.ServerboundInteractPacket in project SpongeCommon by SpongePowered.
the class InteractAtEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext context) {
final ServerPlayer player = context.getPacketPlayer();
final ServerboundInteractPacket useEntityPacket = context.getPacket();
final net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(player.level);
if (entity == null) {
// Something happened?
return;
}
final World spongeWorld = (World) player.level;
if (entity instanceof CreatorTrackedBridge) {
((CreatorTrackedBridge) entity).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, player.getUUID());
} else {
((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
}
// TODO - Determine if we need to pass the supplier or perform some parameterized
// process if not empty method on the capture object.
TrackingUtil.processBlockCaptures(context);
}
use of net.minecraft.network.protocol.game.ServerboundInteractPacket in project SpongeCommon by SpongePowered.
the class InteractEntityPacketState method populateContext.
@Override
public void populateContext(ServerPlayer playerMP, Packet<?> packet, BasicPacketContext context) {
final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(playerMP.level);
if (entity != null) {
final ItemStack stack = ItemStackUtil.cloneDefensive(playerMP.getItemInHand(useEntityPacket.getHand()));
if (stack != null) {
context.itemUsed(stack);
}
final HandType handType = (HandType) (Object) useEntityPacket.getHand();
context.handUsed(handType);
}
}
Aggregations