Java源码示例:net.minecraft.network.play.client.CPacketPlayerDigging
示例1
@Listener
public void sendPacket(EventSendPacket event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if (event.getPacket() instanceof CPacketPlayerDigging) {
final Minecraft mc = Minecraft.getMinecraft();
final CPacketPlayerDigging packet = (CPacketPlayerDigging) event.getPacket();
if (packet.getAction() == CPacketPlayerDigging.Action.RELEASE_USE_ITEM) {
if (mc.player.inventory.getCurrentItem().getItem() instanceof ItemBow && mc.player.getItemInUseMaxCount() >= 20) {
if (!mc.player.onGround) {
mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY - 0.1f, mc.player.posZ, false));
mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY - 10000f, mc.player.posZ, true));
}
}
}
}
}
}
示例2
@SubscribeEvent
public void onPlayerDamageBlock(WPlayerDamageBlockEvent event)
{
try
{
float progress = PlayerControllerUtils.getCurBlockDamageMP()
+ BlockUtils.getHardness(event.getPos());
if(progress >= 1)
return;
}catch(ReflectiveOperationException e)
{
setEnabled(false);
throw new RuntimeException(e);
}
WMinecraft.getPlayer().connection.sendPacket(new CPacketPlayerDigging(
CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, event.getPos(),
event.getFacing()));
}
示例3
@Listener
public void sendPacket(EventSendPacket event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if (this.send) {
this.send = false;
return;
}
if (event.getPacket() instanceof CPacketPlayerDigging && this.silent.getValue()) {
final CPacketPlayerDigging packet = (CPacketPlayerDigging) event.getPacket();
if (packet.getAction() == CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK) {
this.position = packet.getPosition();
this.facing = packet.getFacing();
if (this.position != null && this.facing != null) {
final int slot = getToolInventory(packet.getPosition());
if (slot != -1) {
event.setCanceled(true);
Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().player.inventoryContainer.windowId, slot, Minecraft.getMinecraft().player.inventory.currentItem, ClickType.SWAP, Minecraft.getMinecraft().player);
send = true;
Minecraft.getMinecraft().player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, this.position, this.facing));
Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().player.inventoryContainer.windowId, slot, Minecraft.getMinecraft().player.inventory.currentItem, ClickType.SWAP, Minecraft.getMinecraft().player);
} else {
final int hotbar = getToolHotbar(packet.getPosition());
if (hotbar != -1) {
event.setCanceled(true);
Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().player.inventoryContainer.windowId, hotbar, Minecraft.getMinecraft().player.inventory.currentItem, ClickType.SWAP, Minecraft.getMinecraft().player);
send = true;
Minecraft.getMinecraft().player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, this.position, this.facing));
Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().player.inventoryContainer.windowId, hotbar, Minecraft.getMinecraft().player.inventory.currentItem, ClickType.SWAP, Minecraft.getMinecraft().player);
}
}
}
}
}
}
}
示例4
@Listener
public void onWalkingUpdate(EventUpdateWalkingPlayer event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
final Minecraft mc = Minecraft.getMinecraft();
final Entity target = findTarget();
if (target != null) {
final float[] angle = MathUtil.calcAngle(mc.player.getPositionEyes(mc.getRenderPartialTicks()), target.getPositionEyes(mc.getRenderPartialTicks()));
Seppuku.INSTANCE.getRotationManager().setPlayerRotations(angle[0], angle[1]);
final float ticks = 20.0f - Seppuku.INSTANCE.getTickRateManager().getTickRate();
final boolean canAttack = this.coolDown.getValue() ? (mc.player.getCooledAttackStrength(this.sync.getValue() ? -ticks : 0.0f) >= 1) : true;
final ItemStack stack = mc.player.getHeldItem(EnumHand.OFF_HAND);
//TODO interp
if (this.teleport.getValue()) {
Seppuku.INSTANCE.getPositionManager().setPlayerPosition(target.posX, target.posY, target.posZ);
}
if (canAttack) {
if (stack != null && stack.getItem() == Items.SHIELD) {
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, mc.player.getHorizontalFacing()));
}
mc.player.connection.sendPacket(new CPacketUseEntity(target));
mc.player.swingArm(EnumHand.MAIN_HAND);
mc.player.resetCooldown();
}
}
}
}
示例5
@Listener
public void onWalkingUpdate(EventUpdateWalkingPlayer event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
final Minecraft mc = Minecraft.getMinecraft();
if(mc.player.inventory.getCurrentItem().getItem() instanceof ItemBow) {
if(mc.player.isHandActive() && mc.player.getItemInUseMaxCount() >= 3) {
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, mc.player.getHorizontalFacing()));
mc.player.connection.sendPacket(new CPacketPlayerTryUseItem(mc.player.getActiveHand()));
mc.player.stopActiveHand();
}
}
}
}
示例6
@Listener
public void onUpdate(EventPlayerUpdate event) {
if (event.getStage() == EventStageable.EventStage.PRE) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.player.isHandActive()) {
if (mc.player.getHeldItem(mc.player.getActiveHand()).getItem() instanceof ItemShield) {
if (mc.player.movementInput.moveStrafe != 0 || mc.player.movementInput.moveForward != 0 && mc.player.getItemInUseMaxCount() >= 8) {
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, mc.player.getHorizontalFacing()));
}
}
}
if (this.cobweb.getValue()) {
mc.player.isInWeb = false;
if (mc.player.getRidingEntity() != null) {
mc.player.getRidingEntity().isInWeb = false;
}
}
if (this.ice.getValue()) {
if (mc.player.getRidingEntity() != null) {
Blocks.ICE.setDefaultSlipperiness(0.98f);
Blocks.FROSTED_ICE.setDefaultSlipperiness(0.98f);
Blocks.PACKED_ICE.setDefaultSlipperiness(0.98f);
} else {
Blocks.ICE.setDefaultSlipperiness(0.45f);
Blocks.FROSTED_ICE.setDefaultSlipperiness(0.45f);
Blocks.PACKED_ICE.setDefaultSlipperiness(0.45f);
}
}
}
}
示例7
public static void breakBlocksPacketSpam(Iterable<BlockPos> blocks)
{
Vec3d eyesPos = RotationUtils.getEyesPos();
NetHandlerPlayClient connection = WMinecraft.getPlayer().connection;
for(BlockPos pos : blocks)
{
Vec3d posVec = new Vec3d(pos).addVector(0.5, 0.5, 0.5);
double distanceSqPosVec = eyesPos.squareDistanceTo(posVec);
for(EnumFacing side : EnumFacing.values())
{
Vec3d hitVec =
posVec.add(new Vec3d(side.getDirectionVec()).scale(0.5));
// check if side is facing towards player
if(eyesPos.squareDistanceTo(hitVec) >= distanceSqPosVec)
continue;
// break block
connection.sendPacket(new CPacketPlayerDigging(
Action.START_DESTROY_BLOCK, pos, side));
connection.sendPacket(new CPacketPlayerDigging(
Action.STOP_DESTROY_BLOCK, pos, side));
break;
}
}
}
示例8
@Listener
public void damageBlock(EventPlayerDamageBlock event) {
Minecraft.getMinecraft().player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, event.getPos(), event.getFace()));
}
示例9
@Override
public void onTick() {
if (counter++ % (TPS * MULTIPLIER) == 0) {
if (isPlaced()) {
getNetworkManager()
.sendPacket(
new CPacketPlayerDigging(
CPacketPlayerDigging.Action.START_DESTROY_BLOCK,
getBlockBelow(),
EnumFacing.UP));
swingHand();
return;
}
LocalPlayerInventory.InvItem item =
LocalPlayerInventory.getHotbarInventory()
.stream()
.filter(itm -> itm.getItemStack().getItem() instanceof ItemRedstone)
.findAny()
.orElse(LocalPlayerInventory.InvItem.EMPTY);
if (item.isNull()) {
return;
}
RayTraceResult result = getTraceBelow();
if (result == null) {
return;
}
if (!Blocks.REDSTONE_WIRE.canPlaceBlockAt(getWorld(), result.getBlockPos())) {
return; // can't place block
}
ResetFunction func = LocalPlayerInventory.setSelected(item);
LocalPlayerInventory.syncSelected();
getNetworkManager()
.sendPacket(
new CPacketPlayerTryUseItemOnBlock(
result.getBlockPos(),
EnumFacing.UP,
EnumHand.MAIN_HAND,
(float) (result.hitVec.x - result.getBlockPos().getX()),
(float) (result.hitVec.y - result.getBlockPos().getY()),
(float) (result.hitVec.z - result.getBlockPos().getZ())));
swingHand();
func.revert();
}
}