net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket Java Examples

The following examples show how to use net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoTotem.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	if (mc.player.getOffHandStack().getItem() == Items.TOTEM_OF_UNDYING) return;
	
	/* Inventory */
	for (int i = 9; i < 44; i++) {
		if (mc.player.inventory.getStack(i).getItem() == Items.TOTEM_OF_UNDYING) {
			mc.interactionManager.clickSlot(0, 0, i, SlotActionType.PICKUP, mc.player);
			mc.interactionManager.clickSlot(1, 0, 45, SlotActionType.PICKUP, mc.player);
			return;
		}
	}
	
	/* Hotbar */
	for (int i = 0; i < 8; i++) {
		if (mc.player.inventory.getStack(i).getItem() == Items.TOTEM_OF_UNDYING) {
			//int oldSlot = mc.player.inventory.currentItem;
			mc.player.inventory.selectedSlot = i;
			mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(
					Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
			//mc.player.inventory.currentItem = oldSlot;
			return;
		}
	}
}
 
Example #2
Source File: AutoTotem.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	if (mc.player.getOffHandStack().getItem() == Items.TOTEM_OF_UNDYING) return;
	
	/* Inventory */
	for (int i = 9; i < 44; i++) {
		if (mc.player.inventory.getInvStack(i).getItem() == Items.TOTEM_OF_UNDYING) {
			mc.interactionManager.clickSlot(0, 0, i, SlotActionType.PICKUP, mc.player);
			mc.interactionManager.clickSlot(1, 0, 45, SlotActionType.PICKUP, mc.player);
			return;
		}
	}
	
	/* Hotbar */
	for (int i = 0; i < 8; i++) {
		if (mc.player.inventory.getInvStack(i).getItem() == Items.TOTEM_OF_UNDYING) {
			//int oldSlot = mc.player.inventory.currentItem;
			mc.player.inventory.selectedSlot = i;
			mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(
					Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN));
			//mc.player.inventory.currentItem = oldSlot;
			return;
		}
	}
}
 
Example #3
Source File: FastBreakHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBlockBreakingProgress(BlockBreakingProgressEvent event)
{
	if(legitMode.isChecked())
		return;
	
	IClientPlayerInteractionManager im = IMC.getInteractionManager();
	
	if(im.getCurrentBreakingProgress() >= 1)
		return;
	
	Action action = PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK;
	BlockPos blockPos = event.getBlockPos();
	Direction direction = event.getDirection();
	im.sendPlayerActionC2SPacket(action, blockPos, direction);
}
 
Example #4
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;processBlockBreakingAction(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/network/packet/c2s/play/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V",
        shift = At.Shift.BEFORE
))
private void onClicked(PlayerActionC2SPacket packet, CallbackInfo ci)
{
    if (packet.getAction() == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK)
        PLAYER_CLICKS_BLOCK.onBlockAction(player, packet.getPos(), packet.getDirection());
}
 
Example #5
Source File: ClientPlayerInteractionManagerMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Shadow
private void sendPlayerAction(
	PlayerActionC2SPacket.Action playerActionC2SPacket$Action_1,
	BlockPos blockPos_1, Direction direction_1)
{
	
}
 
Example #6
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerEntity;dropSelectedItem(Z)Z",
        ordinal = 1,
        shift = At.Shift.BEFORE
))
private void onCtrlQItem(PlayerActionC2SPacket playerActionC2SPacket_1, CallbackInfo ci)
{
    PLAYER_DROPS_STACK.onPlayerEvent(player);
}
 
Example #7
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerEntity;dropSelectedItem(Z)Z",
        ordinal = 0,
        shift = At.Shift.BEFORE
))
private void onQItem(PlayerActionC2SPacket playerActionC2SPacket_1, CallbackInfo ci)
{
    PLAYER_DROPS_ITEM.onPlayerEvent(player);
}
 
Example #8
Source File: ServerPlayNetworkHandler_interactionUpdatesMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target ="Lnet/minecraft/server/network/ServerPlayerInteractionManager;processBlockBreakingAction(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/network/packet/c2s/play/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V",
        shift = At.Shift.AFTER
))
private void afterBlockBroken(PlayerActionC2SPacket packet, CallbackInfo ci)
{
    if (!CarpetSettings.interactionUpdates)
        CarpetSettings.impendingFillSkipUpdates = false;
}
 
Example #9
Source File: ServerPlayNetworkHandler_interactionUpdatesMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;processBlockBreakingAction(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/network/packet/c2s/play/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V",
        shift = At.Shift.BEFORE
))
private void beforeBlockBroken(PlayerActionC2SPacket packet, CallbackInfo ci)
{
    if (!CarpetSettings.interactionUpdates)
        CarpetSettings.impendingFillSkipUpdates = true;
}
 
Example #10
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
void inactiveTick(ServerPlayerEntity player, Action action)
{
    EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
    if (ap.currentBlock == null) return;
    player.world.setBlockBreakingInfo(-1, ap.currentBlock, -1);
    player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.server.getWorldHeight());
    ap.currentBlock = null;
}
 
Example #11
Source File: OffhandCrash.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	for (int i = 0; i < getSettings().get(0).toSlider().getValue(); i++) {
		mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.UP));
		if (getSettings().get(1).toToggle().state) mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket(true));
	}
}
 
Example #12
Source File: PlayerActionC2SPacketMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Accessor("action")
void setAction(PlayerActionC2SPacket.Action action);
 
Example #13
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Override
boolean execute(ServerPlayerEntity player, Action action) {
    HitResult hit = getTarget(player);
    switch (hit.getType()) {
        case ENTITY: {
            EntityHitResult entityHit = (EntityHitResult) hit;
            player.attack(entityHit.getEntity());
            player.resetLastAttackedTicks();
            player.updateLastActionTime();
            player.swingHand(Hand.MAIN_HAND);
            return true;
        }
        case BLOCK: {
            EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
            if (ap.blockHitDelay > 0)
            {
                ap.blockHitDelay--;
                return false;
            }
            BlockHitResult blockHit = (BlockHitResult) hit;
            BlockPos pos = blockHit.getBlockPos();
            Direction side = blockHit.getSide();
            // rather should be canNotMine
            if (player.canMine(player.world, pos, player.interactionManager.getGameMode())) return false;
            if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
            {
                ap.currentBlock = null;
                return false;
            }
            BlockState state = player.world.getBlockState(pos);
            boolean blockBroken = false;
            if (player.interactionManager.getGameMode().isCreative())
            {
                player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
                ap.blockHitDelay = 5;
                blockBroken = true;
            }
            else  if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
            {
                if (ap.currentBlock != null)
                {
                    player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.server.getWorldHeight());
                }
                player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
                boolean notAir = !state.isAir();
                if (notAir && ap.curBlockDamageMP == 0)
                {
                    state.onBlockBreakStart(player.world, pos, player);
                }
                if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
                {
                    ap.currentBlock = null;
                    //instamine??
                    blockBroken = true;
                }
                else
                {
                    ap.currentBlock = pos;
                    ap.curBlockDamageMP = 0;
                }
            }
            else
            {
                ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.world, pos);
                if (ap.curBlockDamageMP >= 1)
                {
                    player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.server.getWorldHeight());
                    ap.currentBlock = null;
                    ap.blockHitDelay = 5;
                    blockBroken = true;
                }
                player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));

            }
            player.updateLastActionTime();
            player.swingHand(Hand.MAIN_HAND);
            return blockBroken;
        }
    }
    return false;
}
 
Example #14
Source File: BowBot.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	if (!(mc.player.getMainHandStack().getItem() instanceof RangedWeaponItem) || !mc.player.isUsingItem()) return;
	
	if (getSettings().get(0).toToggle().state && BowItem.getPullProgress(mc.player.getItemUseTime()) > getSettings().get(1).toSlider().getValue()) {
		mc.player.stopUsingItem();
		mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.UP));
	}
	
	// skidded from wurst no bully pls
	if (getSettings().get(2).toToggle().state) {
		List<Entity> targets = Streams.stream(mc.world.getEntities())
				.filter(e -> e instanceof LivingEntity && e != mc.player)
				.sorted((a, b) -> Float.compare(a.distanceTo(mc.player), b.distanceTo(mc.player))).collect(Collectors.toList());
		
		if (targets.isEmpty()) return;
		
		LivingEntity target = (LivingEntity) targets.get(0);
		
		// set velocity
		float velocity = (72000 - mc.player.getItemUseTimeLeft()) / 20F;
		velocity = (velocity * velocity + velocity * 2) / 3;
		
		if (velocity > 1) velocity = 1;
		
		// set position to aim at
		double d = mc.player.getPos().add(0, mc.player.getEyeHeight(mc.player.getPose()), 0)
			.distanceTo(target.getBoundingBox().getCenter());
		double x = target.getX() + (target.getX() - target.prevX) * d
			- mc.player.getX();
		double y = target.getY() + (target.getY() - target.prevY) * d
			+ target.getHeight() * 0.5 - mc.player.getY()
			- mc.player.getEyeHeight(mc.player.getPose());
		double z = target.getZ() + (target.getZ() - target.prevZ) * d
			- mc.player.getZ();
		
		// set yaw
		mc.player.yaw = (float) Math.toDegrees(Math.atan2(z, x)) - 90;
		
		// calculate needed pitch
		double hDistance = Math.sqrt(x * x + z * z);
		double hDistanceSq = hDistance * hDistance;
		float g = 0.006F;
		float velocitySq = velocity * velocity;
		float velocityPow4 = velocitySq * velocitySq;
		float neededPitch = (float)-Math.toDegrees(Math.atan((velocitySq - Math
			.sqrt(velocityPow4 - g * (g * hDistanceSq + 2 * y * velocitySq)))
			/ (g * hDistance)));
		
		// set pitch
		if (Float.isNaN(neededPitch)) EntityUtils.facePos(target.getX(), target.getY() + target.getHeight() / 2, target.getZ());
		else mc.player.pitch = neededPitch;
	}
}
 
Example #15
Source File: BowBot.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	if (!(mc.player.getMainHandStack().getItem() instanceof RangedWeaponItem) || !mc.player.isUsingItem()) return;
	
	if (getSettings().get(0).toToggle().state && BowItem.getPullProgress(mc.player.getItemUseTime()) > getSettings().get(1).toSlider().getValue()) {
		mc.player.stopUsingItem();
		mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.UP));
	}
	
	// skidded from wurst no bully pls
	if (getSettings().get(2).toToggle().state) {
		List<Entity> targets = Streams.stream(mc.world.getEntities())
				.filter(e -> e instanceof LivingEntity && e != mc.player)
				.sorted((a, b) -> Float.compare(a.distanceTo(mc.player), b.distanceTo(mc.player))).collect(Collectors.toList());
		
		if (targets.isEmpty()) return;
		
		LivingEntity target = (LivingEntity) targets.get(0);
		
		// set velocity
		float velocity = (72000 - mc.player.getItemUseTimeLeft()) / 20F;
		velocity = (velocity * velocity + velocity * 2) / 3;
		
		if (velocity > 1) velocity = 1;
		
		// set position to aim at
		double d = mc.player.getPos().add(0, mc.player.getEyeHeight(mc.player.getPose()), 0)
			.distanceTo(target.getBoundingBox().getCenter());
		double x = target.getX() + (target.getX() - target.prevX) * d
			- mc.player.getX();
		double y = target.getY() + (target.getY() - target.prevY) * d
			+ target.getHeight() * 0.5 - mc.player.getY()
			- mc.player.getEyeHeight(mc.player.getPose());
		double z = target.getZ() + (target.getZ() - target.prevZ) * d
			- mc.player.getZ();
		
		// set yaw
		mc.player.yaw = (float) Math.toDegrees(Math.atan2(z, x)) - 90;
		
		// calculate needed pitch
		double hDistance = Math.sqrt(x * x + z * z);
		double hDistanceSq = hDistance * hDistance;
		float g = 0.006F;
		float velocitySq = velocity * velocity;
		float velocityPow4 = velocitySq * velocitySq;
		float neededPitch = (float)-Math.toDegrees(Math.atan((velocitySq - Math
			.sqrt(velocityPow4 - g * (g * hDistanceSq + 2 * y * velocitySq)))
			/ (g * hDistance)));
		
		// set pitch
		if (Float.isNaN(neededPitch)) EntityUtils.facePos(target.getX(), target.getY() + target.getHeight() / 2, target.getZ());
		else mc.player.pitch = neededPitch;
	}
}
 
Example #16
Source File: IClientPlayerInteractionManager.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
public void sendPlayerActionC2SPacket(PlayerActionC2SPacket.Action action,
BlockPos blockPos, Direction direction);
 
Example #17
Source File: OffhandCrash.java    From bleachhack-1.14 with GNU General Public License v3.0 votes vote down vote up
@Subscribe
public void onTick(EventTick event) {
	for (int i = 0; i < getSettings().get(0).toSlider().getValue(); i++) {
		mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.UP));
		if (getSettings().get(1).toToggle().state) mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket(true));
	}
}