Fix crash with chunkloader placed by command. Closes #2349
This commit is contained in:
parent
8398139271
commit
96383ebaaf
2 changed files with 55 additions and 29 deletions
|
@ -27,10 +27,12 @@ package techreborn.items.tool;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.command.BlockDataObject;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
@ -59,23 +61,32 @@ public class DebugToolItem extends Item {
|
|||
return ActionResult.FAIL;
|
||||
}
|
||||
sendMessage(context, new LiteralText(getRegistryName(block)));
|
||||
|
||||
for (Entry<Property<?>, Comparable<?>> entry : blockState.getEntries().entrySet()) {
|
||||
sendMessage(context, new LiteralText(getPropertyString(entry)));
|
||||
}
|
||||
|
||||
BlockEntity blockEntity = context.getWorld().getBlockEntity(context.getBlockPos());
|
||||
if (blockEntity != null) {
|
||||
sendMessage(context, new LiteralText(getBlockEntityType(blockEntity)));
|
||||
if (Energy.valid(blockEntity)) {
|
||||
sendMessage(context, new LiteralText(getRCPower(blockEntity)));
|
||||
}
|
||||
if (blockEntity == null) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
sendMessage(context, new LiteralText(getBlockEntityType(blockEntity)));
|
||||
|
||||
if (Energy.valid(blockEntity)) {
|
||||
sendMessage(context, new LiteralText(getRCPower(blockEntity)));
|
||||
}
|
||||
|
||||
sendMessage(context, getBlockEntityTags(blockEntity));
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
private void sendMessage(ItemUsageContext context, Text string) {
|
||||
if (!context.getWorld().isClient) {
|
||||
context.getPlayer().sendSystemMessage(string, Util.NIL_UUID);
|
||||
private void sendMessage(ItemUsageContext context, Text message) {
|
||||
if (context.getWorld().isClient || context.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
context.getPlayer().sendSystemMessage(message, Util.NIL_UUID);
|
||||
}
|
||||
|
||||
private String getPropertyString(Entry<Property<?>, Comparable<?>> entryIn) {
|
||||
|
@ -102,7 +113,7 @@ public class DebugToolItem extends Item {
|
|||
|
||||
private String getBlockEntityType(BlockEntity blockEntity) {
|
||||
String s = "" + Formatting.GREEN;
|
||||
s += "Tile Entity: ";
|
||||
s += "Block Entity: ";
|
||||
s += Formatting.BLUE;
|
||||
s += blockEntity.getType().toString();
|
||||
|
||||
|
@ -119,4 +130,13 @@ public class DebugToolItem extends Item {
|
|||
|
||||
return s;
|
||||
}
|
||||
|
||||
private Text getBlockEntityTags(BlockEntity blockEntity){
|
||||
MutableText s = new LiteralText("BlockEntity Tags:").formatted(Formatting.GREEN);
|
||||
|
||||
BlockDataObject bdo = new BlockDataObject(blockEntity, blockEntity.getPos());
|
||||
s.append(bdo.getTag().toText());
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue