Search in sources :

Example 1 with SectionPos

use of net.minecraft.core.SectionPos in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processShowFakeForPacket.

public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (FakeBlock.blocks.isEmpty()) {
        return false;
    }
    try {
        if (packet instanceof ClientboundLevelChunkPacket) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
            if (map == null) {
                return false;
            }
            int chunkX = ((ClientboundLevelChunkPacket) packet).getX();
            int chunkZ = ((ClientboundLevelChunkPacket) packet).getZ();
            ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getLevel().getWorld().getName());
            List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUUID(), chunkCoord);
            if (blocks == null || blocks.isEmpty()) {
                return false;
            }
            ClientboundLevelChunkPacket newPacket = FakeBlockHelper.handleMapChunkPacket((ClientboundLevelChunkPacket) packet, blocks);
            oldManager.send(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
            if (map == null) {
                return false;
            }
            SectionPos coord = (SectionPos) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
            ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getLevel().getWorld().getName());
            if (!map.byChunk.containsKey(coordinateDenizen)) {
                return false;
            }
            ClientboundSectionBlocksUpdatePacket newPacket = new ClientboundSectionBlocksUpdatePacket(copyPacket(packet));
            LocationTag location = new LocationTag(player.getLevel().getWorld(), 0, 0, 0);
            short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
            BlockState[] originalDataArray = (BlockState[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
            short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
            BlockState[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
            OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
            BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
            for (int i = 0; i < offsetArray.length; i++) {
                short offset = offsetArray[i];
                BlockPos pos = coord.relativeToBlockPos(offset);
                location.setX(pos.getX());
                location.setY(pos.getY());
                location.setZ(pos.getZ());
                FakeBlock block = map.byLocation.get(location);
                if (block != null) {
                    dataArray[i] = FakeBlockHelper.getNMSState(block);
                }
            }
            oldManager.send(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof ClientboundBlockUpdatePacket) {
            BlockPos pos = ((ClientboundBlockUpdatePacket) packet).getPos();
            LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
            if (block != null) {
                ClientboundBlockUpdatePacket newPacket = new ClientboundBlockUpdatePacket(((ClientboundBlockUpdatePacket) packet).getPos(), FakeBlockHelper.getNMSState(block));
                oldManager.send(newPacket, genericfuturelistener);
                return true;
            }
        } else if (packet instanceof ClientboundBlockBreakAckPacket) {
            BlockPos pos = ((ClientboundBlockBreakAckPacket) packet).getPos();
            LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
            if (block != null) {
                ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(copyPacket(packet));
                BLOCKDATA_BLOCKBREAK.set(newPacket, FakeBlockHelper.getNMSState(block));
                oldManager.send(newPacket, genericfuturelistener);
                return true;
            }
        }
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
    return false;
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) LocationTag(com.denizenscript.denizen.objects.LocationTag) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) SectionPos(net.minecraft.core.SectionPos)

Example 2 with SectionPos

use of net.minecraft.core.SectionPos in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processShowFakeForPacket.

public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (FakeBlock.blocks.isEmpty()) {
        return false;
    }
    try {
        if (packet instanceof ClientboundLevelChunkWithLightPacket) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
            if (map == null) {
                return false;
            }
            int chunkX = ((ClientboundLevelChunkWithLightPacket) packet).getX();
            int chunkZ = ((ClientboundLevelChunkWithLightPacket) packet).getZ();
            ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getLevel().getWorld().getName());
            List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUUID(), chunkCoord);
            if (blocks == null || blocks.isEmpty()) {
                return false;
            }
            ClientboundLevelChunkWithLightPacket newPacket = FakeBlockHelper.handleMapChunkPacket(player.getBukkitEntity().getWorld(), (ClientboundLevelChunkWithLightPacket) packet, chunkX, chunkZ, blocks);
            oldManager.send(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
            if (map == null) {
                return false;
            }
            SectionPos coord = (SectionPos) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
            ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getLevel().getWorld().getName());
            if (!map.byChunk.containsKey(coordinateDenizen)) {
                return false;
            }
            ClientboundSectionBlocksUpdatePacket newPacket = new ClientboundSectionBlocksUpdatePacket(copyPacket(packet));
            LocationTag location = new LocationTag(player.getLevel().getWorld(), 0, 0, 0);
            short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
            BlockState[] originalDataArray = (BlockState[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
            short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
            BlockState[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
            OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
            BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
            for (int i = 0; i < offsetArray.length; i++) {
                short offset = offsetArray[i];
                BlockPos pos = coord.relativeToBlockPos(offset);
                location.setX(pos.getX());
                location.setY(pos.getY());
                location.setZ(pos.getZ());
                FakeBlock block = map.byLocation.get(location);
                if (block != null) {
                    dataArray[i] = FakeBlockHelper.getNMSState(block);
                }
            }
            oldManager.send(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof ClientboundBlockUpdatePacket) {
            BlockPos pos = ((ClientboundBlockUpdatePacket) packet).getPos();
            LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
            if (block != null) {
                ClientboundBlockUpdatePacket newPacket = new ClientboundBlockUpdatePacket(((ClientboundBlockUpdatePacket) packet).getPos(), FakeBlockHelper.getNMSState(block));
                oldManager.send(newPacket, genericfuturelistener);
                return true;
            }
        } else if (packet instanceof ClientboundBlockBreakAckPacket) {
            ClientboundBlockBreakAckPacket origPack = (ClientboundBlockBreakAckPacket) packet;
            BlockPos pos = origPack.pos();
            LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
            if (block != null) {
                ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
                oldManager.send(newPacket, genericfuturelistener);
                return true;
            }
        }
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
    return false;
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) LocationTag(com.denizenscript.denizen.objects.LocationTag) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) SectionPos(net.minecraft.core.SectionPos)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)2 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)2 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)2 BlockPos (net.minecraft.core.BlockPos)2 SectionPos (net.minecraft.core.SectionPos)2 BlockState (net.minecraft.world.level.block.state.BlockState)2