Search in sources :

Example 11 with BlockPos

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

the class BlockHelperImpl method setNbtData.

@Override
public void setNbtData(Block block, CompoundTag ctag) {
    CompoundTagBuilder builder = ctag.createBuilder();
    builder.putInt("x", block.getX());
    builder.putInt("y", block.getY());
    builder.putInt("z", block.getZ());
    ctag = builder.build();
    BlockPos blockPos = new BlockPos(block.getX(), block.getY(), block.getZ());
    BlockEntity te = ((CraftWorld) block.getWorld()).getHandle().getBlockEntity(blockPos, true);
    te.load(((CompoundTagImpl) ctag).toNMSTag());
}
Also used : BlockPos(net.minecraft.core.BlockPos) CompoundTagBuilder(com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 12 with BlockPos

use of net.minecraft.core.BlockPos 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 13 with BlockPos

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

the class WorldHelperImpl method getLocalDifficulty.

@Override
public float getLocalDifficulty(Location location) {
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    DifficultyInstance scaler = ((CraftWorld) location.getWorld()).getHandle().getCurrentDifficultyAt(pos);
    return scaler.getEffectiveDifficulty();
}
Also used : DifficultyInstance(net.minecraft.world.DifficultyInstance) BlockPos(net.minecraft.core.BlockPos)

Example 14 with BlockPos

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

the class BlockLightImpl method checkIfLightsBrokenByPacket.

public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
    try {
        BlockPos pos = packet.getPos();
        int chunkX = pos.getX() >> 4;
        int chunkZ = pos.getZ() >> 4;
        Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
            LevelChunk chunk = world.getChunkAt(chunkX, chunkZ);
            boolean any = false;
            for (Vector vec : RELATIVE_CHUNKS) {
                ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
                if (other instanceof LevelChunk) {
                    List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
                    if (lights != null) {
                        any = true;
                        for (BlockLight light : lights) {
                            Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
                        }
                    }
                }
            }
            if (any) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
            }
        }, 1);
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight) BlockPos(net.minecraft.core.BlockPos) Vector(org.bukkit.util.Vector)

Example 15 with BlockPos

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

the class EntityHelperImpl method forceInteraction.

@Override
public void forceInteraction(Player player, Location location) {
    CraftPlayer craftPlayer = (CraftPlayer) player;
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    ((CraftBlock) location.getBlock()).getNMS().use(((CraftWorld) location.getWorld()).getHandle(), craftPlayer != null ? craftPlayer.getHandle() : null, InteractionHand.MAIN_HAND, new BlockHitResult(new Vec3(0, 0, 0), null, pos, false));
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Aggregations

BlockPos (net.minecraft.core.BlockPos)54 BlockState (net.minecraft.world.level.block.state.BlockState)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)8 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)8 Level (net.minecraft.world.level.Level)7 Direction (net.minecraft.core.Direction)6 Vec3 (net.minecraft.world.phys.Vec3)6 Nonnull (javax.annotation.Nonnull)5 ResourceLocation (net.minecraft.resources.ResourceLocation)5 ItemStack (net.minecraft.world.item.ItemStack)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 Nullable (javax.annotation.Nullable)3 GameTest (net.minecraft.gametest.framework.GameTest)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)3 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)2 CompoundTagBuilder (com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2