Search in sources :

Example 1 with CPacketEntityAction

use of net.minecraft.network.play.client.CPacketEntityAction in project SpongeCommon by SpongePowered.

the class PacketPhase method setupPacketToStateMapping.

public void setupPacketToStateMapping() {
    this.packetTranslationMap.put(CPacketKeepAlive.class, packet -> General.IGNORED);
    this.packetTranslationMap.put(CPacketChatMessage.class, packet -> General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(CPacketUseEntity.class, packet -> {
        final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packet;
        final CPacketUseEntity.Action action = useEntityPacket.getAction();
        if (action == CPacketUseEntity.Action.INTERACT) {
            return General.INTERACT_ENTITY;
        } else if (action == CPacketUseEntity.Action.ATTACK) {
            return General.ATTACK_ENTITY;
        } else if (action == CPacketUseEntity.Action.INTERACT_AT) {
            return General.INTERACT_AT_ENTITY;
        } else {
            return General.INVALID;
        }
    });
    this.packetTranslationMap.put(CPacketPlayer.class, packet -> General.MOVEMENT);
    this.packetTranslationMap.put(CPacketPlayer.Position.class, packet -> General.MOVEMENT);
    this.packetTranslationMap.put(CPacketPlayer.Rotation.class, packet -> General.MOVEMENT);
    this.packetTranslationMap.put(CPacketPlayer.PositionRotation.class, packet -> General.MOVEMENT);
    this.packetTranslationMap.put(CPacketPlayerDigging.class, packet -> {
        final CPacketPlayerDigging playerDigging = (CPacketPlayerDigging) packet;
        final CPacketPlayerDigging.Action action = playerDigging.getAction();
        final IPhaseState<? extends PacketContext<?>> state = INTERACTION_ACTION_MAPPINGS.get(action);
        return state == null ? General.UNKNOWN : state;
    });
    this.packetTranslationMap.put(CPacketPlayerTryUseItemOnBlock.class, packet -> {
        // Note that CPacketPlayerTryUseItem is swapped with CPacketPlayerBlockPlacement
        final CPacketPlayerTryUseItemOnBlock blockPlace = (CPacketPlayerTryUseItemOnBlock) packet;
        final BlockPos blockPos = blockPlace.getPos();
        final EnumFacing front = blockPlace.getDirection();
        final MinecraftServer server = SpongeImpl.getServer();
        if (blockPos.getY() < server.getBuildLimit() - 1 || front != EnumFacing.UP && blockPos.getY() < server.getBuildLimit()) {
            return General.PLACE_BLOCK;
        }
        return General.INVALID;
    });
    this.packetTranslationMap.put(CPacketPlayerTryUseItem.class, packet -> General.USE_ITEM);
    this.packetTranslationMap.put(CPacketHeldItemChange.class, packet -> Inventory.SWITCH_HOTBAR_SCROLL);
    this.packetTranslationMap.put(CPacketAnimation.class, packet -> General.ANIMATION);
    this.packetTranslationMap.put(CPacketEntityAction.class, packet -> {
        final CPacketEntityAction playerAction = (CPacketEntityAction) packet;
        final CPacketEntityAction.Action action = playerAction.getAction();
        return PLAYER_ACTION_MAPPINGS.get(action);
    });
    this.packetTranslationMap.put(CPacketInput.class, packet -> General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(CPacketCloseWindow.class, packet -> General.CLOSE_WINDOW);
    this.packetTranslationMap.put(CPacketClickWindow.class, packet -> fromWindowPacket((CPacketClickWindow) packet));
    this.packetTranslationMap.put(CPacketConfirmTransaction.class, packet -> General.UNKNOWN);
    this.packetTranslationMap.put(CPacketCreativeInventoryAction.class, packet -> General.CREATIVE_INVENTORY);
    this.packetTranslationMap.put(CPacketEnchantItem.class, packet -> Inventory.ENCHANT_ITEM);
    this.packetTranslationMap.put(CPacketUpdateSign.class, packet -> General.UPDATE_SIGN);
    this.packetTranslationMap.put(CPacketPlayerAbilities.class, packet -> General.IGNORED);
    this.packetTranslationMap.put(CPacketTabComplete.class, packet -> General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(CPacketClientStatus.class, packet -> {
        final CPacketClientStatus clientStatus = (CPacketClientStatus) packet;
        final CPacketClientStatus.State status = clientStatus.getStatus();
        if (status == CPacketClientStatus.State.PERFORM_RESPAWN) {
            return General.REQUEST_RESPAWN;
        }
        return General.IGNORED;
    });
    this.packetTranslationMap.put(CPacketCustomPayload.class, packet -> General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(CPacketSpectate.class, packet -> General.IGNORED);
    this.packetTranslationMap.put(CPacketResourcePackStatus.class, packet -> General.RESOURCE_PACK);
    this.packetTranslationMap.put(CPacketPlaceRecipe.class, packet -> Inventory.PLACE_RECIPE);
}
Also used : CPacketPlayerDigging(net.minecraft.network.play.client.CPacketPlayerDigging) CPacketClientStatus(net.minecraft.network.play.client.CPacketClientStatus) CPacketClickWindow(net.minecraft.network.play.client.CPacketClickWindow) EnumFacing(net.minecraft.util.EnumFacing) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock) MinecraftServer(net.minecraft.server.MinecraftServer) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with CPacketEntityAction

use of net.minecraft.network.play.client.CPacketEntityAction in project Wurst-MC-1.10 by Wurst-Imperium.

the class ExtraElytraMod method onUpdate.

@Override
public void onUpdate() {
    updateMS();
    ItemStack chest = WMinecraft.getPlayer().getItemStackFromSlot(EntityEquipmentSlot.CHEST);
    if (chest == null || chest.getItem() != Items.ELYTRA)
        return;
    if (WMinecraft.getPlayer().isElytraFlying()) {
        if (stopInWater.isChecked() && WMinecraft.getPlayer().isInWater()) {
            WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), CPacketEntityAction.Action.START_FALL_FLYING));
            return;
        }
        if (easyFly.isChecked()) {
            if (mc.gameSettings.keyBindJump.pressed)
                WMinecraft.getPlayer().motionY += 0.08;
            else if (mc.gameSettings.keyBindSneak.pressed)
                WMinecraft.getPlayer().motionY -= 0.04;
            if (mc.gameSettings.keyBindForward.pressed && WMinecraft.getPlayer().getPosition().getY() < 256) {
                float yaw = (float) Math.toRadians(WMinecraft.getPlayer().rotationYaw);
                WMinecraft.getPlayer().motionX -= WMath.sin(yaw) * 0.05F;
                WMinecraft.getPlayer().motionZ += WMath.cos(yaw) * 0.05F;
            } else if (mc.gameSettings.keyBindBack.pressed && WMinecraft.getPlayer().getPosition().getY() < 256) {
                float yaw = (float) Math.toRadians(WMinecraft.getPlayer().rotationYaw);
                WMinecraft.getPlayer().motionX += WMath.sin(yaw) * 0.05F;
                WMinecraft.getPlayer().motionZ -= WMath.cos(yaw) * 0.05F;
            }
        }
    } else if (instantFly.isChecked() && ItemElytra.isBroken(chest) && mc.gameSettings.keyBindJump.pressed) {
        if (hasTimePassedM(1000)) {
            updateLastMS();
            WMinecraft.getPlayer().setJumping(false);
            WMinecraft.getPlayer().setSprinting(true);
            WMinecraft.getPlayer().jump();
        }
        WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), CPacketEntityAction.Action.START_FALL_FLYING));
    }
}
Also used : CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) ItemStack(net.minecraft.item.ItemStack)

Example 3 with CPacketEntityAction

use of net.minecraft.network.play.client.CPacketEntityAction in project Wurst-MC-1.12-OF by Wurst-Imperium.

the class ExtraElytraMod method onUpdate.

@Override
public void onUpdate() {
    updateMS();
    ItemStack chest = WMinecraft.getPlayer().getItemStackFromSlot(EntityEquipmentSlot.CHEST);
    if (chest == null || chest.getItem() != Items.ELYTRA)
        return;
    if (WMinecraft.getPlayer().isElytraFlying()) {
        if (stopInWater.isChecked() && WMinecraft.getPlayer().isInWater()) {
            WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), CPacketEntityAction.Action.START_FALL_FLYING));
            return;
        }
        if (easyFly.isChecked()) {
            if (mc.gameSettings.keyBindJump.pressed)
                WMinecraft.getPlayer().motionY += 0.08;
            else if (mc.gameSettings.keyBindSneak.pressed)
                WMinecraft.getPlayer().motionY -= 0.04;
            if (mc.gameSettings.keyBindForward.pressed && WMinecraft.getPlayer().getPosition().getY() < 256) {
                float yaw = (float) Math.toRadians(WMinecraft.getPlayer().rotationYaw);
                WMinecraft.getPlayer().motionX -= WMath.sin(yaw) * 0.05F;
                WMinecraft.getPlayer().motionZ += WMath.cos(yaw) * 0.05F;
            } else if (mc.gameSettings.keyBindBack.pressed && WMinecraft.getPlayer().getPosition().getY() < 256) {
                float yaw = (float) Math.toRadians(WMinecraft.getPlayer().rotationYaw);
                WMinecraft.getPlayer().motionX += WMath.sin(yaw) * 0.05F;
                WMinecraft.getPlayer().motionZ -= WMath.cos(yaw) * 0.05F;
            }
        }
    } else if (instantFly.isChecked() && ItemElytra.isBroken(chest) && mc.gameSettings.keyBindJump.pressed) {
        if (hasTimePassedM(1000)) {
            updateLastMS();
            WMinecraft.getPlayer().setJumping(false);
            WMinecraft.getPlayer().setSprinting(true);
            WMinecraft.getPlayer().jump();
        }
        WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), CPacketEntityAction.Action.START_FALL_FLYING));
    }
}
Also used : CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) ItemStack(net.minecraft.item.ItemStack)

Example 4 with CPacketEntityAction

use of net.minecraft.network.play.client.CPacketEntityAction in project Wurst-MC-1.9 by Wurst-Imperium.

the class ExtraElytraMod method onUpdate.

@Override
public void onUpdate() {
    updateMS();
    ItemStack chest = WMinecraft.getPlayer().getItemStackFromSlot(EntityEquipmentSlot.CHEST);
    if (chest == null || chest.getItem() != Items.elytra)
        return;
    if (WMinecraft.getPlayer().isFlyingWithElytra()) {
        if (stopInWater.isChecked() && WMinecraft.getPlayer().isInWater()) {
            WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), CPacketEntityAction.Action.START_FALL_FLYING));
            return;
        }
        if (easyFly.isChecked()) {
            if (mc.gameSettings.keyBindJump.pressed)
                WMinecraft.getPlayer().motionY += 0.08;
            else if (mc.gameSettings.keyBindSneak.pressed)
                WMinecraft.getPlayer().motionY -= 0.04;
            if (mc.gameSettings.keyBindForward.pressed && WMinecraft.getPlayer().getPosition().getY() < 256) {
                float yaw = (float) Math.toRadians(WMinecraft.getPlayer().rotationYaw);
                WMinecraft.getPlayer().motionX -= WMath.sin(yaw) * 0.05F;
                WMinecraft.getPlayer().motionZ += WMath.cos(yaw) * 0.05F;
            } else if (mc.gameSettings.keyBindBack.pressed && WMinecraft.getPlayer().getPosition().getY() < 256) {
                float yaw = (float) Math.toRadians(WMinecraft.getPlayer().rotationYaw);
                WMinecraft.getPlayer().motionX += WMath.sin(yaw) * 0.05F;
                WMinecraft.getPlayer().motionZ -= WMath.cos(yaw) * 0.05F;
            }
        }
    } else if (instantFly.isChecked() && ItemElytra.isBroken(chest) && mc.gameSettings.keyBindJump.pressed) {
        if (hasTimePassedM(1000)) {
            updateLastMS();
            WMinecraft.getPlayer().setJumping(false);
            WMinecraft.getPlayer().setSprinting(true);
            WMinecraft.getPlayer().jump();
        }
        WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), CPacketEntityAction.Action.START_FALL_FLYING));
    }
}
Also used : CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) ItemStack(net.minecraft.item.ItemStack)

Example 5 with CPacketEntityAction

use of net.minecraft.network.play.client.CPacketEntityAction in project Wurst-MC-1.12 by Wurst-Imperium.

the class SneakMod method afterUpdate.

@Override
public void afterUpdate() {
    if (mode.getSelected() == 1)
        return;
    WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), Action.STOP_SNEAKING));
    WConnection.sendPacket(new CPacketEntityAction(WMinecraft.getPlayer(), Action.START_SNEAKING));
}
Also used : CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction)

Aggregations

CPacketEntityAction (net.minecraft.network.play.client.CPacketEntityAction)10 ItemStack (net.minecraft.item.ItemStack)5 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 NetHandlerPlayClient (net.minecraft.client.network.NetHandlerPlayClient)1 CPacketClickWindow (net.minecraft.network.play.client.CPacketClickWindow)1 CPacketClientStatus (net.minecraft.network.play.client.CPacketClientStatus)1 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)1 CPacketPlayerDigging (net.minecraft.network.play.client.CPacketPlayerDigging)1 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)1 CPacketUseEntity (net.minecraft.network.play.client.CPacketUseEntity)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1