Skip to content

Commit

Permalink
fox bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
liansishen committed Sep 21, 2024
1 parent 652a85a commit e4369a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

public class AdvancedTerminalBehavior extends TerminalBehavior {

@Persisted
private AutoBuildSetting autoBuildSetting;
private ItemStack itemStack;

Expand Down Expand Up @@ -82,17 +81,17 @@ private Widget createWidget() {
.setYScrollBarWidth(2)
.setYBarStyle(null, ColorPattern.T_WHITE.rectTexture().setRadius(1))
.addWidget(new LabelWidget(40, 5, Component.translatable("item.gtmthings.advanced_terminal.setting.title").getString()))
.addWidget(new LabelWidget(4, 5 + 16 * rowIndex, Component.translatable("item.gtmthings.advanced_terminal.setting.1"))
.addWidget(new LabelWidget(4, 5 + 16 * rowIndex, Component.translatable("item.gtmthings.advanced_terminal.setting.1").getString())
.setHoverTooltips(Component.translatable("item.gtmthings.advanced_terminal.setting.1.tooltip")))
.addWidget(new TerminalInputWidget(140, 5 + 16 * rowIndex++, 20, 16, autoBuildSetting::getCoilTier,
this::setCoilTier)
.setMin(0).setMax(GTCEuAPI.HEATING_COILS.size() - 1))
.addWidget(new LabelWidget(4, 5 + 16 * rowIndex, Component.translatable("item.gtmthings.advanced_terminal.setting.2"))
.addWidget(new LabelWidget(4, 5 + 16 * rowIndex, Component.translatable("item.gtmthings.advanced_terminal.setting.2").getString())
.setHoverTooltips(Component.translatable("item.gtmthings.advanced_terminal.setting.2.tooltip")))
.addWidget(new TerminalInputWidget(140, 5 + 16 * rowIndex++, 20, 16, autoBuildSetting::getRepeatCount,
this::setRepeatCount)
.setMin(0).setMax(99))
.addWidget(new LabelWidget(4, 5 + 16 * rowIndex, Component.translatable("item.gtmthings.advanced_terminal.setting.3"))
.addWidget(new LabelWidget(4, 5 + 16 * rowIndex, Component.translatable("item.gtmthings.advanced_terminal.setting.3").getString())
.setHoverTooltips(Component.translatable("item.gtmthings.advanced_terminal.setting.3.tooltip")))
.addWidget(new TerminalInputWidget(140, 5 + 16 * rowIndex++, 20, 16, autoBuildSetting::getNoHatchMode,
this::setIsBuildHatches).setMin(0).setMax(1)));
Expand All @@ -105,18 +104,21 @@ public InteractionResultHolder<ItemStack> use(Item item, Level level, Player pla
if (!ConfigHolder.INSTANCE.gameplay.enableCompass) {
ItemStack heldItem = player.getItemInHand(usedHand);
if (player instanceof ServerPlayer serverPlayer) {
if (this.itemStack == null){
this.itemStack = heldItem;
var tag = this.itemStack.getTag();
if (tag!=null && !tag.isEmpty()) {
this.autoBuildSetting.setCoilTier(tag.getInt("CoilTier"));
this.autoBuildSetting.setRepeatCount(tag.getInt("RepeatCount"));
this.autoBuildSetting.setNoHatchMode(tag.getInt("NoHatchMode"));
} else {
this.autoBuildSetting.setCoilTier(0);
this.autoBuildSetting.setRepeatCount(0);
this.autoBuildSetting.setNoHatchMode(0);
}
this.itemStack = heldItem;
var tag = this.itemStack.getTag();
if (tag!=null && !tag.isEmpty()) {
this.autoBuildSetting.setCoilTier(tag.getInt("CoilTier"));
this.autoBuildSetting.setRepeatCount(tag.getInt("RepeatCount"));
this.autoBuildSetting.setNoHatchMode(tag.getInt("NoHatchMode"));
} else {
tag = new CompoundTag();
tag.putInt("CoilTier",0);
tag.putInt("RepeatCount",0);
tag.putInt("NoHatchMode",0);
this.itemStack.setTag(tag);
this.autoBuildSetting.setCoilTier(0);
this.autoBuildSetting.setRepeatCount(0);
this.autoBuildSetting.setNoHatchMode(0);
}
HeldItemUIFactory.INSTANCE.openUI(serverPlayer, usedHand);
}
Expand Down Expand Up @@ -153,7 +155,7 @@ private void setIsBuildHatches(int isBuildHatches) {
public static class AutoBuildSetting {

final String[] HATCH_NAMES = {"input_hatch","output_hatch","input_bus","output_bus","laser_target","laser_source",
"transmitter_hatch","receiver_hatch","maintenance_hatch","parallel_hatch"};
"transmitter_hatch","receiver_hatch","maintenance_hatch","parallel_hatch","import_bus","export_bus"};

@Getter
@Setter
Expand All @@ -170,13 +172,13 @@ public List<ItemStack> apply(BlockInfo[] blockInfos) {
if (blockInfos != null) {
if (Arrays.stream(blockInfos).anyMatch(
info -> info.getBlockState().getBlock() instanceof CoilBlock)) {
var tier = Math.max(coilTier, blockInfos.length - 1);
candidates.add(blockInfos[tier].getItemStackForm());
for (int i = 0; i < tier; i++) {
candidates.add(blockInfos[i].getItemStackForm());
}
for (int i = tier + 1; i < blockInfos.length - 1; i++) {
candidates.add(blockInfos[i].getItemStackForm());
var tier = Math.min(coilTier, blockInfos.length - 1);
if (tier == 0) {
for (int i = 0; i < blockInfos.length - 1; i++) {
candidates.add(blockInfos[i].getItemStackForm());
}
} else {
candidates.add(blockInfos[tier].getItemStackForm());
}
return candidates;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/hepdd/gtmthings/data/CustomItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private static ItemEntry<ComponentItem> registerTieredCover(String name, String

public static ItemEntry<ComponentItem> ADVANCED_TERMINAL = GTMTHINGS_REGISTRATE
.item("advanced_terminal", ComponentItem::create)
.properties(p -> p.stacksTo(1))
.onRegister(attach(new AdvancedTerminalBehavior())).register();

public static <T extends ItemLike> NonNullConsumer<T> compassNode(CompassSection section, CompassNode... preNodes) {
Expand Down

0 comments on commit e4369a4

Please sign in to comment.