Search in sources :

Example 6 with BlockEntity

use of net.minecraft.world.level.block.entity.BlockEntity in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showSignEditor.

@Override
public boolean showSignEditor(Player player, Location location) {
    if (location == null) {
        LocationTag fakeSign = new LocationTag(player.getLocation());
        fakeSign.setY(0);
        FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
        BlockPos pos = new BlockPos(fakeSign.getX(), 0, fakeSign.getZ());
        ((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().connection.connection).packetListener.fakeSignExpected = pos;
        send(player, new ClientboundOpenSignEditorPacket(pos));
        return true;
    }
    BlockEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getTileEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), true);
    if (tileEntity instanceof SignBlockEntity) {
        SignBlockEntity sign = (SignBlockEntity) tileEntity;
        // Prevent client crashing by sending current state of the sign
        send(player, sign.getUpdatePacket());
        sign.isEditable = true;
        sign.setAllowedPlayerEditor(player.getUniqueId());
        send(player, new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
        return true;
    } else {
        return false;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BlockPos(net.minecraft.core.BlockPos) DenizenNetworkManagerImpl(com.denizenscript.denizen.nms.v1_17.impl.network.handlers.DenizenNetworkManagerImpl) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity)

Example 7 with BlockEntity

use of net.minecraft.world.level.block.entity.BlockEntity 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().getTileEntity(blockPos, true);
    te.load(((CompoundTagImpl) ctag).toNMSTag());
}
Also used : BlockPos(net.minecraft.core.BlockPos) CompoundTagBuilder(com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 8 with BlockEntity

use of net.minecraft.world.level.block.entity.BlockEntity in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showSignEditor.

@Override
public boolean showSignEditor(Player player, Location location) {
    if (location == null) {
        LocationTag fakeSign = new LocationTag(player.getLocation());
        fakeSign.setY(0);
        FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
        BlockPos pos = new BlockPos(fakeSign.getX(), 0, fakeSign.getZ());
        ((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().connection.connection).packetListener.fakeSignExpected = pos;
        send(player, new ClientboundOpenSignEditorPacket(pos));
        return true;
    }
    BlockEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getBlockEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), true);
    if (tileEntity instanceof SignBlockEntity) {
        SignBlockEntity sign = (SignBlockEntity) tileEntity;
        // Prevent client crashing by sending current state of the sign
        send(player, sign.getUpdatePacket());
        sign.isEditable = true;
        sign.setAllowedPlayerEditor(player.getUniqueId());
        send(player, new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
        return true;
    } else {
        return false;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BlockPos(net.minecraft.core.BlockPos) DenizenNetworkManagerImpl(com.denizenscript.denizen.nms.v1_18.impl.network.handlers.DenizenNetworkManagerImpl) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity)

Example 9 with BlockEntity

use of net.minecraft.world.level.block.entity.BlockEntity in project MinecraftForge by MinecraftForge.

the class ModelDataManager method refreshModelData.

private static void refreshModelData(Level world, ChunkPos chunk) {
    cleanCaches(world);
    Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
    if (needUpdate != null) {
        Map<BlockPos, IModelData> data = modelDataCache.computeIfAbsent(chunk, $ -> new ConcurrentHashMap<>());
        for (BlockPos pos : needUpdate) {
            BlockEntity toUpdate = world.getBlockEntity(pos);
            if (toUpdate != null && !toUpdate.isRemoved()) {
                data.put(pos, toUpdate.getModelData());
            } else {
                data.remove(pos);
            }
        }
    }
}
Also used : BlockPos(net.minecraft.core.BlockPos) IModelData(net.minecraftforge.client.model.data.IModelData) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 10 with BlockEntity

use of net.minecraft.world.level.block.entity.BlockEntity in project MinecraftForge by MinecraftForge.

the class FluidUtil method getFluidHandler.

/**
 * Helper method to get an IFluidHandler for at a block position.
 */
public static LazyOptional<IFluidHandler> getFluidHandler(Level world, BlockPos blockPos, @Nullable Direction side) {
    BlockState state = world.getBlockState(blockPos);
    Block block = state.getBlock();
    if (state.hasBlockEntity()) {
        BlockEntity blockEntity = world.getBlockEntity(blockPos);
        if (blockEntity != null) {
            return blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        }
    }
    return LazyOptional.empty();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 BlockPos (net.minecraft.core.BlockPos)8 CompoundTagBuilder (com.denizenscript.denizen.nms.util.jnbt.CompoundTagBuilder)2 LocationTag (com.denizenscript.denizen.objects.LocationTag)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)2 Level (net.minecraft.world.level.Level)2 SignBlockEntity (net.minecraft.world.level.block.entity.SignBlockEntity)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 IModelData (net.minecraftforge.client.model.data.IModelData)2 CompoundTag (com.denizenscript.denizen.nms.util.jnbt.CompoundTag)1 DenizenNetworkManagerImpl (com.denizenscript.denizen.nms.v1_17.impl.network.handlers.DenizenNetworkManagerImpl)1 DenizenNetworkManagerImpl (com.denizenscript.denizen.nms.v1_18.impl.network.handlers.DenizenNetworkManagerImpl)1 Preconditions (com.google.common.base.Preconditions)1 WeakReference (java.lang.ref.WeakReference)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1