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