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();
}
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;
}
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());
}
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;
}
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());
}
Aggregations