Facelift for debug tool
This commit is contained in:
parent
5c6b268dcb
commit
3cde5c8244
5 changed files with 79 additions and 21 deletions
|
@ -24,13 +24,19 @@
|
|||
|
||||
package techreborn.items.tool;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
|
@ -48,25 +54,27 @@ public class ItemDebugTool extends Item {
|
|||
|
||||
@Override
|
||||
public EnumActionResult onItemUse(ItemUseContext context) {
|
||||
Block block = context.getWorld().getBlockState(context.getPos()).getBlock();
|
||||
if (block != null) {
|
||||
sendMessage(context, new TextComponentString(TextFormatting.GREEN + "Block Registry Name: "
|
||||
+ TextFormatting.BLUE + block.getRegistryName().toString()));
|
||||
} else {
|
||||
IBlockState blockState = context.getWorld().getBlockState(context.getPos());
|
||||
Block block = blockState.getBlock();
|
||||
if (block == null) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
sendMessage(context, new TextComponentString(getRegistryName(block)));
|
||||
for (Entry<IProperty<?>, Comparable<?>> entry : blockState.getValues().entrySet()) {
|
||||
sendMessage(context, new TextComponentString(getPropertyString(entry)));
|
||||
}
|
||||
TileEntity tile = context.getWorld().getTileEntity(context.getPos());
|
||||
if (tile != null) {
|
||||
sendMessage(context, new TextComponentString(
|
||||
TextFormatting.GREEN + "Tile Entity: " + TextFormatting.BLUE + tile.getType().toString()));
|
||||
}
|
||||
if (tile instanceof IEnergyInterfaceTile) {
|
||||
sendMessage(context, new TextComponentString(TextFormatting.GREEN + "Power: "
|
||||
+ TextFormatting.BLUE + PowerSystem.getLocaliszedPower(((IEnergyInterfaceTile) tile).getEnergy())));
|
||||
} else if (tile.getCapability(CapabilityEnergy.ENERGY, context.getPlacementHorizontalFacing()) != null) {
|
||||
sendMessage(context, new TextComponentString(TextFormatting.GREEN + "Power " + TextFormatting.RED
|
||||
+ ((IEnergyStorage) tile.getCapability(CapabilityEnergy.ENERGY, context.getPlacementHorizontalFacing())).getEnergyStored() + "FU"));
|
||||
sendMessage(context, new TextComponentString(getTileEntityType(tile)));
|
||||
if (tile instanceof IEnergyInterfaceTile) {
|
||||
sendMessage(context, new TextComponentString(getRCPower((IEnergyInterfaceTile) tile)));
|
||||
} else {
|
||||
IEnergyStorage capEnergy = tile
|
||||
.getCapability(CapabilityEnergy.ENERGY, context.getPlacementHorizontalFacing()).orElseGet(null);
|
||||
if (capEnergy != null) {
|
||||
sendMessage(context, new TextComponentString(getForgePower(capEnergy)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
@ -76,4 +84,54 @@ public class ItemDebugTool extends Item {
|
|||
context.getPlayer().sendMessage(string);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPropertyString(Entry<IProperty<?>, Comparable<?>> entryIn) {
|
||||
IProperty<?> iproperty = entryIn.getKey();
|
||||
Comparable<?> comparable = entryIn.getValue();
|
||||
String s = Util.getValueName(iproperty, comparable);
|
||||
if (Boolean.TRUE.equals(comparable)) {
|
||||
s = TextFormatting.GREEN + s;
|
||||
} else if (Boolean.FALSE.equals(comparable)) {
|
||||
s = TextFormatting.RED + s;
|
||||
}
|
||||
|
||||
return iproperty.getName() + ": " + s;
|
||||
}
|
||||
|
||||
private String getRegistryName(Block block) {
|
||||
String s = "" + TextFormatting.GREEN;
|
||||
s += "Block Registry Name: ";
|
||||
s += TextFormatting.BLUE;
|
||||
s += block.getRegistryName().toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private String getTileEntityType(TileEntity tile) {
|
||||
String s = "" + TextFormatting.GREEN;
|
||||
s += "Tile Entity: ";
|
||||
s += TextFormatting.BLUE;
|
||||
s += tile.getType().toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private String getRCPower(IEnergyInterfaceTile tile) {
|
||||
String s = "" + TextFormatting.GREEN;
|
||||
s += "Power: ";
|
||||
s += TextFormatting.BLUE;
|
||||
s += PowerSystem.getLocaliszedPower(tile.getEnergy());
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private String getForgePower(IEnergyStorage cap) {
|
||||
String s = "" + TextFormatting.GREEN;
|
||||
s += "Power: ";
|
||||
s += TextFormatting.RED;
|
||||
s += cap.getEnergyStored();
|
||||
s += " RF";
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "techreborn:item/tool/debug_tool"
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"parent": "techreborn:item/techrebornItem",
|
||||
"textures": {
|
||||
"layer0": "techreborn:items/tool/debug"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 603 B After Width: | Height: | Size: 603 B |
Loading…
Add table
Reference in a new issue