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;
|
package techreborn.items.tool;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemUseContext;
|
import net.minecraft.item.ItemUseContext;
|
||||||
|
import net.minecraft.state.IProperty;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumActionResult;
|
import net.minecraft.util.EnumActionResult;
|
||||||
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.text.TextComponentString;
|
import net.minecraft.util.text.TextComponentString;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
import reborncore.api.power.IEnergyInterfaceTile;
|
import reborncore.api.power.IEnergyInterfaceTile;
|
||||||
|
@ -48,25 +54,27 @@ public class ItemDebugTool extends Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumActionResult onItemUse(ItemUseContext context) {
|
public EnumActionResult onItemUse(ItemUseContext context) {
|
||||||
Block block = context.getWorld().getBlockState(context.getPos()).getBlock();
|
IBlockState blockState = context.getWorld().getBlockState(context.getPos());
|
||||||
if (block != null) {
|
Block block = blockState.getBlock();
|
||||||
sendMessage(context, new TextComponentString(TextFormatting.GREEN + "Block Registry Name: "
|
if (block == null) {
|
||||||
+ TextFormatting.BLUE + block.getRegistryName().toString()));
|
|
||||||
} else {
|
|
||||||
return EnumActionResult.FAIL;
|
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());
|
TileEntity tile = context.getWorld().getTileEntity(context.getPos());
|
||||||
if (tile != null) {
|
if (tile != null) {
|
||||||
sendMessage(context, new TextComponentString(
|
sendMessage(context, new TextComponentString(getTileEntityType(tile)));
|
||||||
TextFormatting.GREEN + "Tile Entity: " + TextFormatting.BLUE + tile.getType().toString()));
|
if (tile instanceof IEnergyInterfaceTile) {
|
||||||
}
|
sendMessage(context, new TextComponentString(getRCPower((IEnergyInterfaceTile) tile)));
|
||||||
if (tile instanceof IEnergyInterfaceTile) {
|
} else {
|
||||||
sendMessage(context, new TextComponentString(TextFormatting.GREEN + "Power: "
|
IEnergyStorage capEnergy = tile
|
||||||
+ TextFormatting.BLUE + PowerSystem.getLocaliszedPower(((IEnergyInterfaceTile) tile).getEnergy())));
|
.getCapability(CapabilityEnergy.ENERGY, context.getPlacementHorizontalFacing()).orElseGet(null);
|
||||||
} else if (tile.getCapability(CapabilityEnergy.ENERGY, context.getPlacementHorizontalFacing()) != null) {
|
if (capEnergy != null) {
|
||||||
sendMessage(context, new TextComponentString(TextFormatting.GREEN + "Power " + TextFormatting.RED
|
sendMessage(context, new TextComponentString(getForgePower(capEnergy)));
|
||||||
+ ((IEnergyStorage) tile.getCapability(CapabilityEnergy.ENERGY, context.getPlacementHorizontalFacing())).getEnergyStored() + "FU"));
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -76,4 +84,54 @@ public class ItemDebugTool extends Item {
|
||||||
context.getPlayer().sendMessage(string);
|
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
Add a link
Reference in a new issue