Utility for grabbing a name for a tile entity or block.
This commit is contained in:
@@ -9,12 +9,10 @@ import li.cil.oc2.common.device.Providers;
|
||||
import li.cil.oc2.common.util.NBTTagIds;
|
||||
import li.cil.oc2.common.util.TileEntityUtils;
|
||||
import li.cil.oc2.common.util.WorldUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
@@ -66,13 +64,8 @@ public final class TileEntityDeviceBusElement implements INBTSerializable<Compou
|
||||
final IdentifiableDeviceImpl identifiableDevice;
|
||||
|
||||
if (device.isPresent()) {
|
||||
final Block block = world.getBlockState(pos).getBlock();
|
||||
final ResourceLocation registryName = block.getRegistryName();
|
||||
if (registryName != null) {
|
||||
identifiableDevice = new IdentifiableDeviceImpl(device, deviceIds[index], registryName.toString());
|
||||
} else {
|
||||
identifiableDevice = new IdentifiableDeviceImpl(device, deviceIds[index]);
|
||||
}
|
||||
final String typeName = WorldUtils.getBlockName(world, pos);
|
||||
identifiableDevice = new IdentifiableDeviceImpl(device, deviceIds[index], typeName);
|
||||
device.addListener((ignored) -> handleNeighborChanged(pos));
|
||||
} else {
|
||||
identifiableDevice = null;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package li.cil.oc2.common.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -17,4 +19,34 @@ public final class WorldUtils {
|
||||
|
||||
return world.getTileEntity(pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getBlockName(final World world, final BlockPos pos) {
|
||||
final ChunkPos chunkPos = new ChunkPos(pos);
|
||||
if (!world.chunkExists(chunkPos.x, chunkPos.z)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (tileEntity != null) {
|
||||
final ResourceLocation registryName = tileEntity.getType().getRegistryName();
|
||||
if (registryName != null) {
|
||||
return registryName.toString();
|
||||
}
|
||||
}
|
||||
|
||||
final Block block = world.getBlockState(pos).getBlock();
|
||||
{
|
||||
final ResourceLocation registryName = block.getRegistryName();
|
||||
if (registryName != null) {
|
||||
return registryName.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (tileEntity != null) {
|
||||
return tileEntity.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
return block.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user