Skip to content

Commit

Permalink
improved scanning method in BlockEntityBase
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Dec 1, 2023
1 parent 53c81dd commit cc35cf6
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 25 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/muramasa/antimatter/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import muramasa.antimatter.gui.container.ContainerCover;
import muramasa.antimatter.gui.container.ContainerMachine;
import muramasa.antimatter.gui.container.ContainerMultiMachine;
import muramasa.antimatter.item.DebugScannerItem;
import muramasa.antimatter.item.ScannerItem;
import muramasa.antimatter.item.ItemCover;
import muramasa.antimatter.item.ItemFluidIcon;
import muramasa.antimatter.machine.types.BasicMachine;
Expand Down Expand Up @@ -43,7 +43,7 @@ public class Data {

public static final Material WRENCH_MATERIAL = new Material(MaterialColor.METAL, false, true, true, true, false, false, PushReaction.NORMAL);

public static DebugScannerItem DEBUG_SCANNER = new DebugScannerItem(Ref.ID, "debug_scanner").tip(ChatFormatting.AQUA + "" + ChatFormatting.ITALIC + "Development Item");
public static ScannerItem DEBUG_SCANNER = new ScannerItem(Ref.ID, "debug_scanner", false).tip(ChatFormatting.AQUA + "" + ChatFormatting.ITALIC + "Development Item");

public static ItemFluidIcon FLUID_ICON = new ItemFluidIcon();
//public static Machine<?> MACHINE_INVALID = new Machine<>(Ref.ID, "invalid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean isServerSide() {


//TODO pass constant StringBuilder
public List<String> getInfo() {
public List<String> getInfo(boolean simple) {
List<String> info = new ObjectArrayList<>();
info.add("Tile: " + getClass().getSimpleName());
return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public BlockState getState() {
}

@Override
public List<String> getInfo() {
List<String> list = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> list = super.getInfo(simple);
if (getState() != null)
list.add("State: " + getState().toString());
if (facing != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ public CompoundTag getUpdateTag() {


@Override
public List<String> getInfo() {
List<String> info = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> info = super.getInfo(simple);
info.add("Machine: " + getMachineType().getId() + " Tier: " + getMachineTier().getId());
info.add("State: " + getMachineState().getId());
String slots = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void onLoad() {
}

@Override
public List<String> getInfo() {
List<String> info = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> info = super.getInfo(simple);
energyHandler.ifPresent(h -> {
info.add("Amperage In: " + h.availableAmpsInput(this.getMaxInputVoltage()));
info.add("Amperage Out: " + h.availableAmpsOutput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ public int drawInfo(InfoRenderWidget.TesseractFluidWidget instance, PoseStack st
}

@Override
public List<String> getInfo() {
List<String> list = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> list = super.getInfo(simple);
fluidHandler.ifPresent(t -> {
for (int i = 0; i < t.getSize(); i++) {
FluidHolder stack = t.getFluidInTank(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ public CompoundTag getUpdateTag() {
}

@Override
public List<String> getInfo() {
List<String> info = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> info = super.getInfo(simple);
info.add("Pipe Type: " + getPipeType().getId());
info.add("Pipe Size: " + getPipeSize().getId());
return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public long getOutputAmperage() {
}

@Override
public List<String> getInfo() {
List<String> info = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> info = super.getInfo(simple);
energyHandler.ifPresent(h -> {
info.add("Amperage In: " + h.availableAmpsInput(this.getMaxInputVoltage()));
info.add("Amperage Out: " + h.availableAmpsOutput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void onGuiEvent(IGuiEvent event, Player playerEntity) {
}

@Override
public List<String> getInfo() {
List<String> info = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> info = super.getInfo(simple);
energyHandler.ifPresent(h -> {
info.add("Voltage Out: " + h.getOutputVoltage());
info.add("Amperage Out: " + h.getOutputAmperage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public MachineState getDefaultMachineState() {
}

@Override
public List<String> getInfo() {
List<String> info = super.getInfo();
public List<String> getInfo(boolean simple) {
List<String> info = super.getInfo(simple);
energyHandler.ifPresent(h -> {
info.add("Voltage In: " + h.getInputVoltage());
info.add("Voltage Out: " + h.getOutputVoltage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static void onRenderDebugInfo(ArrayList<String> left) {
}
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof BlockEntityBase<?> b) {
left.addAll(b.getInfo());
left.addAll(b.getInfo(false));
}
if (MC.player.isCrouching()) {
left.add("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.Data;
import muramasa.antimatter.Ref;
import muramasa.antimatter.block.BlockStone;
import muramasa.antimatter.block.BlockStorage;
import muramasa.antimatter.blockentity.BlockEntityBase;
Expand All @@ -27,16 +29,28 @@

import java.util.List;

public class DebugScannerItem extends ItemBasic<DebugScannerItem> {
public class ScannerItem extends ItemBasic<ScannerItem> {
final boolean simple;

public DebugScannerItem(String domain, String id) {
super(domain, id);
public ScannerItem(String domain, String id, boolean simple) {
this(domain, id, simple, "", new Properties().tab(Ref.TAB_ITEMS));

}

public ScannerItem(String domain, String id, boolean simple, String subDir, Properties properties) {
super(domain, id, subDir, properties);
this.simple = simple;
}

public ScannerItem(String domain, String id, boolean simple, Properties properties) {
this(domain, id, simple, "", properties);
}


@Override
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(Utils.literal(this.tooltip));
if (Screen.hasShiftDown()) {
if (Screen.hasShiftDown() && this == Data.DEBUG_SCANNER) {
tooltip.add(Utils.literal("Blocks: " + AntimatterAPI.all(Block.class).size()));
tooltip.add(Utils.literal("Machines: " + Machine.getTypes(MachineFlag.BASIC, MachineFlag.MULTI, MachineFlag.HATCH).size()));
tooltip.add(Utils.literal("Pipes: " + AntimatterAPI.all(BlockPipe.class).size()));
Expand All @@ -56,7 +70,7 @@ public InteractionResult useOn(UseOnContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
BlockEntity tile = context.getLevel().getBlockEntity(context.getClickedPos());
if (tile instanceof BlockEntityBase) {
((BlockEntityBase<?>) tile).getInfo().forEach(s -> context.getPlayer().sendMessage(Utils.literal(s), context.getPlayer().getUUID()));
((BlockEntityBase<?>) tile).getInfo(simple).forEach(s -> context.getPlayer().sendMessage(Utils.literal(s), context.getPlayer().getUUID()));
}
if (state.getBlock() instanceof BlockDynamic && context.getPlayer() != null) {
((BlockDynamic) state.getBlock()).getInfo(new ObjectArrayList<>(), context.getLevel(), state, context.getClickedPos()).forEach(s -> {
Expand Down

0 comments on commit cc35cf6

Please sign in to comment.