Search in sources :

Example 1 with SPacketMultiBlockChange

use of net.minecraft.network.play.server.SPacketMultiBlockChange in project Minecraft-SlientClient-Hack by YouNeverKnow00.

the class PlayerChunkMapEntry method update.

public void update() {
    if (this.sentToPlayers && this.chunk != null) {
        if (this.changes != 0) {
            if (this.changes == 1) {
                int i = (this.changedBlocks[0] >> 12 & 15) + this.pos.chunkXPos * 16;
                int j = this.changedBlocks[0] & 255;
                int k = (this.changedBlocks[0] >> 8 & 15) + this.pos.chunkZPos * 16;
                BlockPos blockpos = new BlockPos(i, j, k);
                this.sendPacket(new SPacketBlockChange(this.playerChunkMap.getWorldServer(), blockpos));
                if (this.playerChunkMap.getWorldServer().getBlockState(blockpos).getBlock().hasTileEntity()) {
                    this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos));
                }
            } else if (this.changes == 64) {
                this.sendPacket(new SPacketChunkData(this.chunk, this.changedSectionFilter));
            } else {
                this.sendPacket(new SPacketMultiBlockChange(this.changes, this.changedBlocks, this.chunk));
                for (int l = 0; l < this.changes; ++l) {
                    int i1 = (this.changedBlocks[l] >> 12 & 15) + this.pos.chunkXPos * 16;
                    int j1 = this.changedBlocks[l] & 255;
                    int k1 = (this.changedBlocks[l] >> 8 & 15) + this.pos.chunkZPos * 16;
                    BlockPos blockpos1 = new BlockPos(i1, j1, k1);
                    if (this.playerChunkMap.getWorldServer().getBlockState(blockpos1).getBlock().hasTileEntity()) {
                        this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos1));
                    }
                }
            }
            this.changes = 0;
            this.changedSectionFilter = 0;
        }
    }
}
Also used : SPacketChunkData(net.minecraft.network.play.server.SPacketChunkData) BlockPos(net.minecraft.util.math.BlockPos) SPacketMultiBlockChange(net.minecraft.network.play.server.SPacketMultiBlockChange) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Example 2 with SPacketMultiBlockChange

use of net.minecraft.network.play.server.SPacketMultiBlockChange in project cosmos by momentumdevelopment.

the class SurroundModule method onPacketReceive.

@SubscribeEvent
public void onPacketReceive(PacketEvent.PacketReceiveEvent event) {
    // packet for block changes
    if (event.getPacket() instanceof SPacketBlockChange) {
        if (timing.getValue().equals(Timing.SEQUENTIAL)) {
            // check if the block is now replaceable
            if (((SPacketBlockChange) event.getPacket()).getBlockState().getMaterial().isReplaceable()) {
                // the position of the block change
                BlockPos changePosition = ((SPacketBlockChange) event.getPacket()).getBlockPosition();
                // check each of the offsets
                for (Vec3i surroundOffset : calculateOffsets) {
                    // round the player's y position to allow placements if the player is standing on a block that's height is less than 1
                    BlockPos playerPositionRounded = new BlockPos(mc.player.posX, Math.round(mc.player.posY), mc.player.posZ);
                    // the position to place the block
                    BlockPos surroundPosition = playerPositionRounded.add(surroundOffset);
                    if (changePosition.equals(surroundPosition)) {
                        // save the previous slot
                        previousSlot = mc.player.inventory.currentItem;
                        // switch to obsidian
                        getCosmos().getInventoryManager().switchToBlock(block.getValue().getBlock(), autoSwitch.getValue());
                        if (InventoryUtil.isHolding(block.getValue().getBlock())) {
                            // update blocks placed
                            blocksPlaced++;
                            // place a block
                            getCosmos().getInteractionManager().placeBlock(changePosition, rotate.getValue(), strict.getValue());
                        }
                        // switch back to our previous item
                        if (previousSlot != -1) {
                            getCosmos().getInventoryManager().switchToSlot(previousSlot, autoSwitch.getValue());
                            // reset previous slot info
                            previousSlot = -1;
                        }
                        break;
                    }
                }
            }
        }
    }
    // packet for multiple block changes
    if (event.getPacket() instanceof SPacketMultiBlockChange) {
        if (timing.getValue().equals(Timing.SEQUENTIAL)) {
            // check each of the updated blocks
            for (SPacketMultiBlockChange.BlockUpdateData blockUpdateData : ((SPacketMultiBlockChange) event.getPacket()).getChangedBlocks()) {
                // check if the block is now replaceable
                if (blockUpdateData.getBlockState().getMaterial().isReplaceable()) {
                    // the position of the changed block
                    BlockPos changePosition = blockUpdateData.getPos();
                    // check each of the offsets
                    for (Vec3i surroundOffset : calculateOffsets) {
                        // round the player's y position to allow placements if the player is standing on a block that's height is less than 1
                        BlockPos playerPositionRounded = new BlockPos(mc.player.posX, Math.round(mc.player.posY), mc.player.posZ);
                        // the position to place the block
                        BlockPos surroundPosition = playerPositionRounded.add(surroundOffset);
                        if (changePosition.equals(surroundPosition)) {
                            // save the previous slot
                            previousSlot = mc.player.inventory.currentItem;
                            // switch to obsidian
                            getCosmos().getInventoryManager().switchToBlock(block.getValue().getBlock(), autoSwitch.getValue());
                            if (InventoryUtil.isHolding(block.getValue().getBlock())) {
                                // update blocks placed
                                blocksPlaced++;
                                // place a block
                                getCosmos().getInteractionManager().placeBlock(changePosition, rotate.getValue(), strict.getValue());
                            }
                            // switch back to our previous item
                            if (previousSlot != -1) {
                                getCosmos().getInventoryManager().switchToSlot(previousSlot, autoSwitch.getValue());
                                // reset previous slot info
                                previousSlot = -1;
                            }
                        }
                    }
                }
            }
        }
    }
    // packet for block breaking animation
    if (event.getPacket() instanceof SPacketBlockBreakAnim) {
    /*

            getCosmos().getChatManager().sendClientMessage(((SPacketBlockBreakAnim) event.getPacket()).getProgress());

            if (volatiles.getValue()) {
                if () {

                    // the position of the block change
                    BlockPos changePosition = ((SPacketBlockBreakAnim) event.getPacket()).getPosition();

                    // check each of the offsets
                    for (Vec3i surroundOffset : calculateOffsets) {

                        // round the player's y position to allow placements if the player is standing on a block that's height is less than 1
                        BlockPos playerPositionRounded = new BlockPos(mc.player.posX, Math.round(mc.player.posY), mc.player.posZ);

                        // the position to place the block
                        BlockPos surroundPosition = playerPositionRounded.add(surroundOffset);

                        if (changePosition.equals(surroundPosition)) {
                            // save the previous slot
                            previousSlot = mc.player.inventory.currentItem;

                            // switch to obsidian
                            getCosmos().getInventoryManager().switchToBlock(block.getValue().getBlock(), autoSwitch.getValue());

                            // extending blocks
                            List<Vec3i> extender = Arrays.asList(
                                    new Vec3i(1, 0, 0),
                                    new Vec3i(-1, 0, 0),
                                    new Vec3i(0, 0, 1),
                                    new Vec3i(0, 0, -1)
                            );

                            // surround each extender
                            for (Vec3i extend : extender) {

                                // extended position
                                BlockPos extendPosition = changePosition.add(extend);

                                if (InventoryUtil.isHolding(block.getValue().getBlock())) {
                                    // update blocks placed
                                    blocksPlaced++;

                                    // place a block
                                    getCosmos().getInteractionManager().placeBlock(extendPosition, rotate.getValue(), strict.getValue());
                                }
                            }

                            // switch back to our previous item
                            if (previousSlot != -1) {
                                getCosmos().getInventoryManager().switchToSlot(previousSlot, autoSwitch.getValue());

                                // reset previous slot info
                                previousSlot = -1;
                            }

                            break;
                        }
                    }
                }
            }

             */
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) BlockPos(net.minecraft.util.math.BlockPos) SPacketBlockBreakAnim(net.minecraft.network.play.server.SPacketBlockBreakAnim) SPacketMultiBlockChange(net.minecraft.network.play.server.SPacketMultiBlockChange) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with SPacketMultiBlockChange

use of net.minecraft.network.play.server.SPacketMultiBlockChange in project CumServerPro by MCUmbrella.

the class PlayerChunkMapEntry method update.

@SuppressWarnings("unused")
public void update() {
    if (this.sentToPlayers && this.chunk != null) {
        if (this.changes != 0) {
            if (this.changes == 1) {
                int i = (this.changedBlocks[0] >> 12 & 15) + this.pos.x * 16;
                int j = this.changedBlocks[0] & 255;
                int k = (this.changedBlocks[0] >> 8 & 15) + this.pos.z * 16;
                BlockPos blockpos = new BlockPos(i, j, k);
                this.sendPacket(new SPacketBlockChange(this.playerChunkMap.getWorldServer(), blockpos));
                net.minecraft.block.state.IBlockState state = this.playerChunkMap.getWorldServer().getBlockState(blockpos);
                if (state.getBlock().hasTileEntity(state)) {
                    this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos));
                }
            } else if (this.changes >= net.minecraftforge.common.ForgeModContainer.clumpingThreshold) {
                // TODO: FDix Mojang's fuckup to modded by combining all TE data into the chunk data packet... seriously... packet size explosion!
                try {
                    this.sendPacket(new SPacketChunkData(this.chunk, this.changedSectionFilter));
                } catch (Throwable throwable) {
                    // If out of buffer, try resend packet;
                    try {
                        this.sendPacket(new SPacketMultiBlockChange(this.changes, this.changedBlocks, this.chunk));
                        // {// Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small
                        for (int l = 0; l < this.changes; ++l) {
                            int i1 = (this.changedBlocks[l] >> 12 & 15) + this.pos.x * 16;
                            int j1 = this.changedBlocks[l] & 255;
                            int k1 = (this.changedBlocks[l] >> 8 & 15) + this.pos.z * 16;
                            BlockPos blockpos1 = new BlockPos(i1, j1, k1);
                            net.minecraft.block.state.IBlockState state = this.playerChunkMap.getWorldServer().getBlockState(blockpos1);
                            if (state.getBlock().hasTileEntity(state)) {
                                this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos1));
                            }
                        }
                    } catch (Throwable throwable1) {
                        throwable1.printStackTrace();
                        return;
                    // Don't Reset the change blocks. next tick send it
                    }
                }
            } else {
                this.sendPacket(new SPacketMultiBlockChange(this.changes, this.changedBlocks, this.chunk));
                // {// Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small
                for (int l = 0; l < this.changes; ++l) {
                    int i1 = (this.changedBlocks[l] >> 12 & 15) + this.pos.x * 16;
                    int j1 = this.changedBlocks[l] & 255;
                    int k1 = (this.changedBlocks[l] >> 8 & 15) + this.pos.z * 16;
                    BlockPos blockpos1 = new BlockPos(i1, j1, k1);
                    net.minecraft.block.state.IBlockState state = this.playerChunkMap.getWorldServer().getBlockState(blockpos1);
                    if (state.getBlock().hasTileEntity(state)) {
                        this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos1));
                    }
                }
            }
            this.changes = 0;
            this.changedSectionFilter = 0;
        }
    }
}
Also used : SPacketChunkData(net.minecraft.network.play.server.SPacketChunkData) BlockPos(net.minecraft.util.math.BlockPos) SPacketMultiBlockChange(net.minecraft.network.play.server.SPacketMultiBlockChange) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Aggregations

SPacketBlockChange (net.minecraft.network.play.server.SPacketBlockChange)3 SPacketMultiBlockChange (net.minecraft.network.play.server.SPacketMultiBlockChange)3 BlockPos (net.minecraft.util.math.BlockPos)3 SPacketChunkData (net.minecraft.network.play.server.SPacketChunkData)2 SPacketBlockBreakAnim (net.minecraft.network.play.server.SPacketBlockBreakAnim)1 Vec3i (net.minecraft.util.math.Vec3i)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1