Search in sources :

Example 1 with BlockEntity

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

the class VanillaInventoryCodeHooks method getItemHandler.

public static Optional<Pair<IItemHandler, Object>> getItemHandler(Level worldIn, double x, double y, double z, final Direction side) {
    int i = Mth.floor(x);
    int j = Mth.floor(y);
    int k = Mth.floor(z);
    BlockPos blockpos = new BlockPos(i, j, k);
    net.minecraft.world.level.block.state.BlockState state = worldIn.getBlockState(blockpos);
    if (state.hasBlockEntity()) {
        BlockEntity blockEntity = worldIn.getBlockEntity(blockpos);
        if (blockEntity != null) {
            return blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side).map(capability -> ImmutablePair.<IItemHandler, Object>of(capability, blockEntity));
        }
    }
    return Optional.empty();
}
Also used : BlockPos(net.minecraft.core.BlockPos) HopperBlockEntity(net.minecraft.world.level.block.entity.HopperBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) DispenserBlockEntity(net.minecraft.world.level.block.entity.DispenserBlockEntity)

Example 2 with BlockEntity

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

the class BlockSnapshot method restoreToLocation.

public boolean restoreToLocation(LevelAccessor world, BlockPos pos, boolean force, boolean notifyNeighbors) {
    BlockState current = getCurrentBlock();
    BlockState replaced = getReplacedBlock();
    int flags = notifyNeighbors ? Block.UPDATE_ALL : Block.UPDATE_CLIENTS;
    if (current != replaced) {
        if (force)
            world.setBlock(pos, replaced, flags);
        else
            return false;
    }
    world.setBlock(pos, replaced, flags);
    if (world instanceof Level)
        ((Level) world).sendBlockUpdated(pos, current, replaced, flags);
    BlockEntity te = null;
    if (getTag() != null) {
        te = world.getBlockEntity(pos);
        if (te != null) {
            te.load(getTag());
            te.setChanged();
        }
    }
    if (DEBUG)
        System.out.println("Restored " + this.toString());
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with BlockEntity

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

the class ModelDataManager method requestModelDataRefresh.

public static void requestModelDataRefresh(BlockEntity te) {
    Preconditions.checkNotNull(te, "Tile entity must not be null");
    Level world = te.getLevel();
    cleanCaches(world);
    needModelDataRefresh.computeIfAbsent(new ChunkPos(te.getBlockPos()), $ -> Collections.synchronizedSet(new HashSet<>())).add(te.getBlockPos());
}
Also used : ChunkEvent(net.minecraftforge.event.world.ChunkEvent) IModelData(net.minecraftforge.client.model.data.IModelData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EventBusSubscriber(net.minecraftforge.fml.common.Mod.EventBusSubscriber) Set(java.util.Set) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Dist(net.minecraftforge.api.distmarker.Dist) HashSet(java.util.HashSet) ChunkPos(net.minecraft.world.level.ChunkPos) Minecraft(net.minecraft.client.Minecraft) BlockPos(net.minecraft.core.BlockPos) Map(java.util.Map) Preconditions(com.google.common.base.Preconditions) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) WeakReference(java.lang.ref.WeakReference) Level(net.minecraft.world.level.Level) Collections(java.util.Collections) Bus(net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus) Nullable(javax.annotation.Nullable) Level(net.minecraft.world.level.Level) ChunkPos(net.minecraft.world.level.ChunkPos)

Example 4 with BlockEntity

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

the class BlockHelperImpl method getNbtData.

@Override
public CompoundTag getNbtData(Block block) {
    BlockEntity te = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(new BlockPos(block.getX(), block.getY(), block.getZ()), true);
    if (te != null) {
        net.minecraft.nbt.CompoundTag compound = new net.minecraft.nbt.CompoundTag();
        te.save(compound);
        return CompoundTagImpl.fromNMSTag(compound);
    }
    return null;
}
Also used : BlockPos(net.minecraft.core.BlockPos) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 5 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().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)

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