Go Back!
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ public abstract class InstructionBoundBlock extends Block implements EntityBlock
|
|||||||
|
|
||||||
world.getBlockEntity(pos, getBlockEntityType()).ifPresent(be -> {
|
world.getBlockEntity(pos, getBlockEntityType()).ifPresent(be -> {
|
||||||
String name = MinionPersistentState.get(world.getServer()).getMinionData(be.getMinionUuid()).name();
|
String name = MinionPersistentState.get(world.getServer()).getMinionData(be.getMinionUuid()).name();
|
||||||
player.sendSystemMessage(Component.translatable("minions.reference.instruction.tooltip", name, be.getInstructionName()));
|
player.sendSystemMessage(Component.translatable("minions.reference.instruction.tooltip", be.getInstructionName(), name));
|
||||||
});
|
});
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -28,7 +28,9 @@ public abstract class InstructionBoundBlockEntity<L extends BlockEntityMinionLis
|
|||||||
public void removeListener() {
|
public void removeListener() {
|
||||||
if(level instanceof ServerLevel serverWorld) {
|
if(level instanceof ServerLevel serverWorld) {
|
||||||
L listener = getListener();
|
L listener = getListener();
|
||||||
listener.remove(serverWorld.getServer());
|
if(listener != null) {
|
||||||
|
listener.remove(serverWorld.getServer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package io.github.skippyall.minions.gui;
|
|||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||||
import io.github.skippyall.minions.util.TranslationUtil;
|
import io.github.skippyall.minions.util.TranslationUtil;
|
||||||
import it.unimi.dsi.fastutil.objects.ReferenceSortedSets;
|
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.core.UUIDUtil;
|
import net.minecraft.core.UUIDUtil;
|
||||||
import net.minecraft.core.component.DataComponentPatch;
|
import net.minecraft.core.component.DataComponentPatch;
|
||||||
|
import net.minecraft.core.component.DataComponentType;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -21,11 +21,23 @@ import net.minecraft.world.item.Rarity;
|
|||||||
import net.minecraft.world.item.component.ResolvableProfile;
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
import net.minecraft.world.item.component.TooltipDisplay;
|
import net.minecraft.world.item.component.TooltipDisplay;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface GuiDisplay {
|
public interface GuiDisplay {
|
||||||
Codec<GuiDisplay> CODEC = MinionRegistries.GUI_DISPLAY_TYPE.byNameCodec().dispatch(GuiDisplay::getCodec, codec -> codec.fieldOf("data"));
|
Codec<GuiDisplay> CODEC = MinionRegistries.GUI_DISPLAY_TYPE.byNameCodec().dispatch(GuiDisplay::getCodec, codec -> codec.fieldOf("data"));
|
||||||
GuiDisplay DEFAULT_DISPLAY = new ItemBased(Items.BARRIER);
|
GuiDisplay DEFAULT_DISPLAY = new ItemBased(Items.BARRIER);
|
||||||
|
TooltipDisplay TOOLTIP_DISPLAY = createTooltipDisplay();
|
||||||
|
|
||||||
|
private static TooltipDisplay createTooltipDisplay() {
|
||||||
|
LinkedHashSet<DataComponentType<?>> set = new LinkedHashSet<>();
|
||||||
|
for(DataComponentType<?> type : BuiltInRegistries.DATA_COMPONENT_TYPE) {
|
||||||
|
if(type != DataComponents.LORE) {
|
||||||
|
set.add(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new TooltipDisplay(false, set);
|
||||||
|
}
|
||||||
|
|
||||||
static GuiDisplay getGuiDisplay(Identifier id, RegistryAccess manager) {
|
static GuiDisplay getGuiDisplay(Identifier id, RegistryAccess manager) {
|
||||||
return manager.lookup(MinionRegistries.GUI_DISPLAY).map(registry -> registry.getValue(id)).orElse(DEFAULT_DISPLAY);
|
return manager.lookup(MinionRegistries.GUI_DISPLAY).map(registry -> registry.getValue(id)).orElse(DEFAULT_DISPLAY);
|
||||||
@@ -94,7 +106,7 @@ public interface GuiDisplay {
|
|||||||
@Override
|
@Override
|
||||||
public ItemStackTemplate createItemStackTemplate() {
|
public ItemStackTemplate createItemStackTemplate() {
|
||||||
return new ItemStackTemplate(item, DataComponentPatch.builder()
|
return new ItemStackTemplate(item, DataComponentPatch.builder()
|
||||||
.set(DataComponents.TOOLTIP_DISPLAY, new TooltipDisplay(true, ReferenceSortedSets.emptySet()))
|
.set(DataComponents.TOOLTIP_DISPLAY, TOOLTIP_DISPLAY)
|
||||||
.set(DataComponents.RARITY, Rarity.COMMON)
|
.set(DataComponents.RARITY, Rarity.COMMON)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package io.github.skippyall.minions.gui;
|
package io.github.skippyall.minions.gui;
|
||||||
|
|
||||||
|
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.item.Items;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class MinionsGui {
|
public abstract class MinionsGui {
|
||||||
@@ -44,26 +47,29 @@ public abstract class MinionsGui {
|
|||||||
|
|
||||||
public void close(boolean alreadyClosed) {
|
public void close(boolean alreadyClosed) {
|
||||||
if(open) {
|
if(open) {
|
||||||
if(parent != null) {
|
open = false;
|
||||||
parent.child = null;
|
if(child != null) {
|
||||||
//parent.reopen();
|
child.close(alreadyClosed);
|
||||||
|
} else if(!alreadyClosed) {
|
||||||
|
closeBacking();
|
||||||
}
|
}
|
||||||
closeNoOpen(alreadyClosed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeNoOpen(boolean closeBacking) {
|
public void goBack() {
|
||||||
open = false;
|
|
||||||
boolean hasChild = child != null;
|
|
||||||
if(hasChild) {
|
|
||||||
child.closeNoOpen(closeBacking);
|
|
||||||
}
|
|
||||||
if(parent != null) {
|
if(parent != null) {
|
||||||
|
open = false;
|
||||||
parent.child = null;
|
parent.child = null;
|
||||||
|
parent.reopen();
|
||||||
|
} else {
|
||||||
|
close(false);
|
||||||
}
|
}
|
||||||
if(closeBacking && !hasChild) {
|
}
|
||||||
closeBacking();
|
|
||||||
}
|
public GuiElementBuilder backButton() {
|
||||||
|
return new GuiElementBuilder(Items.MANGROVE_DOOR)
|
||||||
|
.setName(Component.translatable("gui.back"))
|
||||||
|
.setCallback(this::goBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void closeBacking();
|
protected abstract void closeBacking();
|
||||||
|
|||||||
@@ -27,13 +27,15 @@ public class PaginatedList extends MinionsGui {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void open() {
|
protected void open() {
|
||||||
gui = new SimpleGui(MenuType.GENERIC_9x4, viewer, false) {
|
gui = new SimpleGui(MenuType.GENERIC_9x6, viewer, false) {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerClose(boolean success) {
|
public void onPlayerClose(boolean success) {
|
||||||
onBackingClosed();
|
onBackingClosed();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
gui.setTitle(title);
|
gui.setTitle(title);
|
||||||
|
|
||||||
|
gui.setSlot(8, backButton());
|
||||||
addItems();
|
addItems();
|
||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
@@ -52,12 +54,14 @@ public class PaginatedList extends MinionsGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addItems() {
|
private void addItems() {
|
||||||
for(int i = 27 * page; i < Math.min(27 * (page + 1), size); i++) {
|
int slot = 9;
|
||||||
gui.addSlot(display.apply(i, this));
|
for(int i = 36 * page; i < Math.min(36 * (page + 1), size); i++) {
|
||||||
|
gui.setSlot(slot, display.apply(i, this));
|
||||||
|
slot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(page > 0) {
|
if(page > 0) {
|
||||||
gui.setSlot(30, new GuiElementBuilder(Items.SPECTRAL_ARROW)
|
gui.setSlot(48, new GuiElementBuilder(Items.SPECTRAL_ARROW)
|
||||||
.setItemName(Component.translatable("book.page_button.previous"))
|
.setItemName(Component.translatable("book.page_button.previous"))
|
||||||
.setCallback(() -> {
|
.setCallback(() -> {
|
||||||
page--;
|
page--;
|
||||||
@@ -65,11 +69,11 @@ public class PaginatedList extends MinionsGui {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
gui.clearSlot(30);
|
gui.clearSlot(48);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(27 * (page + 1) < size) {
|
if(27 * (page + 1) < size) {
|
||||||
gui.setSlot(32, new GuiElementBuilder(Items.ARROW)
|
gui.setSlot(50, new GuiElementBuilder(Items.ARROW)
|
||||||
.setItemName(Component.translatable("book.page_button.next"))
|
.setItemName(Component.translatable("book.page_button.next"))
|
||||||
.setCallback(() -> {
|
.setCallback(() -> {
|
||||||
page++;
|
page++;
|
||||||
@@ -77,7 +81,7 @@ public class PaginatedList extends MinionsGui {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
gui.clearSlot(32);
|
gui.clearSlot(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,14 +74,14 @@ public class ChoiceInput {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Void> confirm(MinionsGui parent, Component title) {
|
public static CompletableFuture<Boolean> confirm(MinionsGui parent, Component title) {
|
||||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
|
|
||||||
new SimpleMinionsGui(parent, (onClose, me) -> {
|
new SimpleMinionsGui(parent, (onClose, me) -> {
|
||||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, parent.getViewer(), false) {
|
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, parent.getViewer(), false) {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerClose(boolean success) {
|
public void onPlayerClose(boolean success) {
|
||||||
future.cancel(false);
|
future.complete(false);
|
||||||
onClose.run();
|
onClose.run();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -90,12 +90,18 @@ public class ChoiceInput {
|
|||||||
|
|
||||||
gui.setSlot(3, new GuiElementBuilder(Items.REDSTONE_BLOCK)
|
gui.setSlot(3, new GuiElementBuilder(Items.REDSTONE_BLOCK)
|
||||||
.setName(Component.translatable("minions.gui.abort"))
|
.setName(Component.translatable("minions.gui.abort"))
|
||||||
.setCallback(() -> future.cancel(false))
|
.setCallback(() -> {
|
||||||
|
future.complete(false);
|
||||||
|
me.goBack();
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
gui.setSlot(5, new GuiElementBuilder(Items.EMERALD_BLOCK)
|
gui.setSlot(5, new GuiElementBuilder(Items.EMERALD_BLOCK)
|
||||||
.setName(Component.translatable("minions.gui.confirm"))
|
.setName(Component.translatable("minions.gui.confirm"))
|
||||||
.setCallback(() -> future.complete(null))
|
.setCallback(() -> {
|
||||||
|
future.complete(true);
|
||||||
|
me.goBack();
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
gui.open();
|
gui.open();
|
||||||
|
|||||||
@@ -53,9 +53,12 @@ public class TextInput<T> extends AnvilInputGui {
|
|||||||
CompletableFuture<T> future = new CompletableFuture<>();
|
CompletableFuture<T> future = new CompletableFuture<>();
|
||||||
new SimpleMinionsGui(gui, (onClose, me) -> {
|
new SimpleMinionsGui(gui, (onClose, me) -> {
|
||||||
TextInput<T> input = new TextInput<>(gui.getViewer(), title, defaultValue, parser, future);
|
TextInput<T> input = new TextInput<>(gui.getViewer(), title, defaultValue, parser, future);
|
||||||
future.handle((v, e) -> {
|
future.whenComplete((v, e) -> {
|
||||||
onClose.run();
|
if(e != null) {
|
||||||
return null;
|
onClose.run();
|
||||||
|
} else {
|
||||||
|
me.goBack();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
input.open();
|
input.open();
|
||||||
return input;
|
return input;
|
||||||
@@ -115,7 +118,6 @@ public class TextInput<T> extends AnvilInputGui {
|
|||||||
if(result != null) {
|
if(result != null) {
|
||||||
result.ifSuccess(success -> {
|
result.ifSuccess(success -> {
|
||||||
isConfirm = true;
|
isConfirm = true;
|
||||||
close();
|
|
||||||
future.complete(success);
|
future.complete(success);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class ArgumentGui extends MinionsGui {
|
public class ArgumentGui extends MinionsGui {
|
||||||
private final GuiContext.ValueSupplier context;
|
private final GuiContext.ValueSupplier context;
|
||||||
private final MinionFakePlayer minion;
|
|
||||||
private final ConfiguredInstruction<MinionRuntime> instruction;
|
private final ConfiguredInstruction<MinionRuntime> instruction;
|
||||||
private final Parameter<?> parameter;
|
private final Parameter<?> parameter;
|
||||||
|
|
||||||
@@ -34,7 +33,6 @@ public class ArgumentGui extends MinionsGui {
|
|||||||
|
|
||||||
public ArgumentGui(MinionsGui parent, GuiContext.ValueSupplier context) {
|
public ArgumentGui(MinionsGui parent, GuiContext.ValueSupplier context) {
|
||||||
super(parent);
|
super(parent);
|
||||||
minion = context.getMinion();
|
|
||||||
instruction = context.getInstruction();
|
instruction = context.getInstruction();
|
||||||
this.parameter = context.getParameter();
|
this.parameter = context.getParameter();
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -71,6 +69,8 @@ public class ArgumentGui extends MinionsGui {
|
|||||||
Component.translatable(TranslationUtil.getTranslationKey(parameter.type(), MinionRegistries.VALUE_TYPES))
|
Component.translatable(TranslationUtil.getTranslationKey(parameter.type(), MinionRegistries.VALUE_TYPES))
|
||||||
));
|
));
|
||||||
|
|
||||||
|
gui.setSlot(2, backButton());
|
||||||
|
|
||||||
updateTypeConfiguration();
|
updateTypeConfiguration();
|
||||||
updateArgumentConfiguration();
|
updateArgumentConfiguration();
|
||||||
updateConverterConfiguration();
|
updateConverterConfiguration();
|
||||||
@@ -102,12 +102,7 @@ public class ArgumentGui extends MinionsGui {
|
|||||||
.setName(Component.translatable("minions.gui.instruction.argument.configure.data"))
|
.setName(Component.translatable("minions.gui.instruction.argument.configure.data"))
|
||||||
.addLoreLine(getArgument() != null ? getArgument().getDisplayText() : Component.translatable("minions.gui.not_set"))
|
.addLoreLine(getArgument() != null ? getArgument().getDisplayText() : Component.translatable("minions.gui.not_set"))
|
||||||
.setCallback(() -> argumentType.openConfiguration(this, parameter.type(), getArgument())
|
.setCallback(() -> argumentType.openConfiguration(this, parameter.type(), getArgument())
|
||||||
.thenAccept(newArgument -> {
|
.thenAccept(this::setArgument)
|
||||||
setArgument(newArgument);
|
|
||||||
if(child != null) {
|
|
||||||
child.close();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -149,7 +144,7 @@ public class ArgumentGui extends MinionsGui {
|
|||||||
new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_SUPPLIER_TYPES, type, viewer.registryAccess()))
|
new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_SUPPLIER_TYPES, type, viewer.registryAccess()))
|
||||||
.setCallback(() -> {
|
.setCallback(() -> {
|
||||||
setArgumentType(type);
|
setArgumentType(type);
|
||||||
me.close();
|
me.goBack();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-5
@@ -50,7 +50,7 @@ public class ConfigureInstructionGui extends MinionsGui implements ConfiguredIns
|
|||||||
|
|
||||||
gui.setTitle(Component.literal(name));
|
gui.setTitle(Component.literal(name));
|
||||||
|
|
||||||
gui.setSlot(7, new GuiElementBuilder(Items.ANVIL)
|
gui.setSlot(6, new GuiElementBuilder(Items.ANVIL)
|
||||||
.setName(Component.translatable("minions.gui.instruction.configure.rename"))
|
.setName(Component.translatable("minions.gui.instruction.configure.rename"))
|
||||||
.setCallback(() -> InstructionGui.inputInstructionName(this, context, name).thenAccept(newName -> {
|
.setCallback(() -> InstructionGui.inputInstructionName(this, context, name).thenAccept(newName -> {
|
||||||
minion.getInstructionManager().setInstructionName(name, newName);
|
minion.getInstructionManager().setInstructionName(name, newName);
|
||||||
@@ -58,15 +58,19 @@ public class ConfigureInstructionGui extends MinionsGui implements ConfiguredIns
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
gui.setSlot(8, new GuiElementBuilder(Items.LAVA_BUCKET)
|
gui.setSlot(7, new GuiElementBuilder(Items.LAVA_BUCKET)
|
||||||
.setName(Component.translatable("minions.gui.instruction.configure.delete"))
|
.setName(Component.translatable("minions.gui.instruction.configure.delete"))
|
||||||
.setCallback(() -> ChoiceInput.confirm(this, Component.translatable("minions.gui.instruction.configure.delete.confirm", name))
|
.setCallback(() -> ChoiceInput.confirm(this, Component.translatable("minions.gui.instruction.configure.delete.confirm", name))
|
||||||
.thenAccept(v -> {
|
.thenAccept((confirmed) -> {
|
||||||
minion.getInstructionManager().removeInstruction(name);
|
if(confirmed) {
|
||||||
close();
|
minion.getInstructionManager().removeInstruction(name);
|
||||||
|
goBack();
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
gui.setSlot(8, backButton());
|
||||||
|
|
||||||
updateSuppliers();
|
updateSuppliers();
|
||||||
|
|
||||||
gui.setSlot(13, InstructionGui.createInstructionElement(instruction.getInstruction(), viewer.registryAccess()));
|
gui.setSlot(13, InstructionGui.createInstructionElement(instruction.getInstruction(), viewer.registryAccess()));
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class ConverterGui extends MinionsGui {
|
|||||||
|
|
||||||
updateTypeDisplay();
|
updateTypeDisplay();
|
||||||
updateConverterDisplay();
|
updateConverterDisplay();
|
||||||
|
gui.setSlot(8, backButton());
|
||||||
|
|
||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
@@ -101,7 +102,7 @@ public class ConverterGui extends MinionsGui {
|
|||||||
GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_CONVERTER_TYPES, type, viewer.registryAccess())
|
GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_CONVERTER_TYPES, type, viewer.registryAccess())
|
||||||
).setCallback(() -> {
|
).setCallback(() -> {
|
||||||
setType(type);
|
setType(type);
|
||||||
me.close();
|
me.goBack();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -109,12 +110,7 @@ public class ConverterGui extends MinionsGui {
|
|||||||
private void configureData() {
|
private void configureData() {
|
||||||
if(valueConverterType != null) {
|
if(valueConverterType != null) {
|
||||||
valueConverterType.configure(this, from, to, converter)
|
valueConverterType.configure(this, from, to, converter)
|
||||||
.thenAccept(newConverter -> {
|
.thenAccept(this::setConverter);
|
||||||
setConverter(newConverter);
|
|
||||||
if(child != null) {
|
|
||||||
child.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ public class ConverterListGui extends MinionsGui {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
gui.setSlot(8, backButton());
|
||||||
|
|
||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class InstructionGui {
|
public class InstructionGui {
|
||||||
public static MinionsGui openInstructionMainMenu(MinionsGui parent, GuiContext.Minion context) {
|
public static void openInstructionMainMenu(MinionsGui parent, GuiContext.Minion context) {
|
||||||
return new SimpleMinionsGui(parent, (onClose, me) -> {
|
new SimpleMinionsGui(parent, (onClose, me) -> {
|
||||||
ServerPlayer player = parent.getViewer();
|
ServerPlayer player = parent.getViewer();
|
||||||
|
|
||||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, player, false) {
|
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, player, false) {
|
||||||
@@ -42,6 +42,7 @@ public class InstructionGui {
|
|||||||
};
|
};
|
||||||
gui.setTitle(Component.translatable("minions.gui.instruction.title"));
|
gui.setTitle(Component.translatable("minions.gui.instruction.title"));
|
||||||
|
|
||||||
|
gui.setSlot(2, me.backButton());
|
||||||
gui.setSlot(3, new GuiElementBuilder()
|
gui.setSlot(3, new GuiElementBuilder()
|
||||||
.setItem(Items.BOOK)
|
.setItem(Items.BOOK)
|
||||||
.setName(Component.translatable("minions.gui.instruction.list"))
|
.setName(Component.translatable("minions.gui.instruction.list"))
|
||||||
@@ -101,7 +102,7 @@ public class InstructionGui {
|
|||||||
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
||||||
|
|
||||||
new SimpleMinionsGui(parent, (closeHandler, me) -> {
|
new SimpleMinionsGui(parent, (closeHandler, me) -> {
|
||||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_9x3, viewer, false) {
|
SimpleGui gui = new SimpleGui(MenuType.GENERIC_9x4, viewer, false) {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerClose(boolean success) {
|
public void onPlayerClose(boolean success) {
|
||||||
if (!future.isDone()) {
|
if (!future.isDone()) {
|
||||||
@@ -112,11 +113,13 @@ public class InstructionGui {
|
|||||||
};
|
};
|
||||||
gui.setTitle(Component.translatable("minions.gui.instruction.select_instruction"));
|
gui.setTitle(Component.translatable("minions.gui.instruction.select_instruction"));
|
||||||
|
|
||||||
|
gui.setSlot(8, me.backButton());
|
||||||
|
|
||||||
for (int i = 0; i < minion.getModuleInventory().getContainerSize(); i++) {
|
for (int i = 0; i < minion.getModuleInventory().getContainerSize(); i++) {
|
||||||
ItemStack moduleItem = minion.getModuleInventory().getItem(i);
|
ItemStack moduleItem = minion.getModuleInventory().getItem(i);
|
||||||
MinionModule module = moduleItem.get(MinionComponentTypes.MODULE);
|
MinionModule module = moduleItem.get(MinionComponentTypes.MODULE);
|
||||||
if (module != null && !module.instructions().isEmpty()) {
|
if (module != null && !module.instructions().isEmpty()) {
|
||||||
gui.addSlot(new GuiElementBuilder(moduleItem)
|
gui.setSlot(i + 9, new GuiElementBuilder(moduleItem)
|
||||||
.setCallback(() -> selectInstructionMenu(parent, context, module)
|
.setCallback(() -> selectInstructionMenu(parent, context, module)
|
||||||
.thenApply(future::complete)
|
.thenApply(future::complete)
|
||||||
)
|
)
|
||||||
@@ -134,7 +137,7 @@ public class InstructionGui {
|
|||||||
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
||||||
|
|
||||||
new SimpleMinionsGui(parent, (closeHandler, me) -> {
|
new SimpleMinionsGui(parent, (closeHandler, me) -> {
|
||||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_9x3, parent.getViewer(), false) {
|
SimpleGui gui = new SimpleGui(MenuType.GENERIC_9x4, parent.getViewer(), false) {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerClose(boolean success) {
|
public void onPlayerClose(boolean success) {
|
||||||
if (!future.isDone()) {
|
if (!future.isDone()) {
|
||||||
@@ -145,10 +148,13 @@ public class InstructionGui {
|
|||||||
};
|
};
|
||||||
gui.setTitle(Component.translatable("minions.gui.instruction.select_instruction"));
|
gui.setTitle(Component.translatable("minions.gui.instruction.select_instruction"));
|
||||||
|
|
||||||
|
gui.setSlot(8, me.backButton());
|
||||||
|
int slot = 9;
|
||||||
for (InstructionType<MinionRuntime> instructionType : module.instructions()) {
|
for (InstructionType<MinionRuntime> instructionType : module.instructions()) {
|
||||||
gui.addSlot(createInstructionElement(instructionType, parent.getViewer().registryAccess())
|
gui.setSlot(slot, createInstructionElement(instructionType, parent.getViewer().registryAccess())
|
||||||
.setCallback(() -> future.complete(instructionType))
|
.setCallback(() -> future.complete(instructionType))
|
||||||
);
|
);
|
||||||
|
slot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.open();
|
gui.open();
|
||||||
|
|||||||
@@ -33,13 +33,15 @@ public class InstructionListGui extends MinionsGui implements MinionListener {
|
|||||||
@Override
|
@Override
|
||||||
protected void open() {
|
protected void open() {
|
||||||
minion.addMinionListener(this);
|
minion.addMinionListener(this);
|
||||||
gui = new SimpleGui(MenuType.GENERIC_9x3, viewer, false) {
|
gui = new SimpleGui(MenuType.GENERIC_9x4, viewer, false) {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerClose(boolean success) {
|
public void onPlayerClose(boolean success) {
|
||||||
onBackingClosed();
|
onBackingClosed();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
gui.setTitle(Component.translatable("minions.gui.instruction.title"));
|
gui.setTitle(Component.translatable("minions.gui.instruction.title"));
|
||||||
|
|
||||||
|
gui.setSlot(8, backButton());
|
||||||
resetInstructionList();
|
resetInstructionList();
|
||||||
gui.open();
|
gui.open();
|
||||||
}
|
}
|
||||||
@@ -51,7 +53,7 @@ public class InstructionListGui extends MinionsGui implements MinionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resetInstructionList() {
|
private void resetInstructionList() {
|
||||||
int i = 0;
|
int i = 9;
|
||||||
for (String instructionName : minion.getInstructionManager().getInstructionNames()) {
|
for (String instructionName : minion.getInstructionManager().getInstructionNames()) {
|
||||||
ConfiguredInstruction<MinionRuntime> instruction = minion.getInstructionManager().getInstruction(instructionName);
|
ConfiguredInstruction<MinionRuntime> instruction = minion.getInstructionManager().getInstruction(instructionName);
|
||||||
gui.setSlot(i, new GuiElementBuilder(GuiDisplay.getGuiDisplayFor(MinionRegistries.INSTRUCTION_TYPES, instruction.getInstruction(), viewer.registryAccess()).createItemStack())
|
gui.setSlot(i, new GuiElementBuilder(GuiDisplay.getGuiDisplayFor(MinionRegistries.INSTRUCTION_TYPES, instruction.getInstruction(), viewer.registryAccess()).createItemStack())
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class GuiContextImpl implements GuiContext {
|
|||||||
private final MinionFakePlayer minion;
|
private final MinionFakePlayer minion;
|
||||||
|
|
||||||
public MinionImpl(GuiContext context, MinionFakePlayer minion) {
|
public MinionImpl(GuiContext context, MinionFakePlayer minion) {
|
||||||
super(context);
|
super(context instanceof DelegatingGuiContextImpl<?> impl ? impl.context : context);
|
||||||
this.minion = minion;
|
this.minion = minion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ public class GuiContextImpl implements GuiContext {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public InstructionImpl(GuiContext.Minion context, ConfiguredInstruction<MinionRuntime> instruction, String name) {
|
public InstructionImpl(GuiContext.Minion context, ConfiguredInstruction<MinionRuntime> instruction, String name) {
|
||||||
super(context);
|
super(context instanceof DelegatingMinionImpl<?> impl ? impl.context : context);
|
||||||
this.instruction = instruction;
|
this.instruction = instruction;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class GuiContextImpl implements GuiContext {
|
|||||||
private final Parameter<?> parameter;
|
private final Parameter<?> parameter;
|
||||||
|
|
||||||
public ValueSupplierImpl(GuiContext.Instruction context, Parameter<?> parameter) {
|
public ValueSupplierImpl(GuiContext.Instruction context, Parameter<?> parameter) {
|
||||||
super(context);
|
super(context instanceof DelegatingInstructionImpl<?> impl ? impl.context : context);
|
||||||
this.parameter = parameter;
|
this.parameter = parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public class MinionInventoryGui extends MinionsGui {
|
|||||||
gui.setSlot(5, new ItemStack(Items.LEATHER_BOOTS));
|
gui.setSlot(5, new ItemStack(Items.LEATHER_BOOTS));
|
||||||
gui.setSlot(6, new ItemStack(Items.SHIELD));
|
gui.setSlot(6, new ItemStack(Items.SHIELD));
|
||||||
|
|
||||||
|
gui.setSlot(8, backButton());
|
||||||
|
|
||||||
gui.setSlot(2 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.HEAD, EquipmentSlot.HEAD.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
gui.setSlot(2 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.HEAD, EquipmentSlot.HEAD.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||||
gui.setSlot(3 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.CHEST, EquipmentSlot.CHEST.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
gui.setSlot(3 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.CHEST, EquipmentSlot.CHEST.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||||
gui.setSlot(4 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.LEGS, EquipmentSlot.LEGS.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
gui.setSlot(4 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.LEGS, EquipmentSlot.LEGS.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||||
|
|||||||
+2
@@ -87,11 +87,13 @@ public class AnalogInputSupplier implements ValueSupplier<Long, MinionRuntime> {
|
|||||||
};
|
};
|
||||||
gui.setTitle(Component.translatable("value_supplier.minions.analog_input"));
|
gui.setTitle(Component.translatable("value_supplier.minions.analog_input"));
|
||||||
|
|
||||||
|
gui.setSlot(2, me.backButton());
|
||||||
gui.setSlot(4, new GuiElementBuilder(MinionItems.REFERENCE_ITEM)
|
gui.setSlot(4, new GuiElementBuilder(MinionItems.REFERENCE_ITEM)
|
||||||
.setCallback(() -> {
|
.setCallback(() -> {
|
||||||
ItemStack cursor = parent.getViewer().containerMenu.getCarried();
|
ItemStack cursor = parent.getViewer().containerMenu.getCarried();
|
||||||
if (cursor.is(MinionItems.REFERENCE_ITEM) && cursor.get(MinionComponentTypes.REFERENCE) instanceof BlockPosClipboard pos) {
|
if (cursor.is(MinionItems.REFERENCE_ITEM) && cursor.get(MinionComponentTypes.REFERENCE) instanceof BlockPosClipboard pos) {
|
||||||
future.complete(new AnalogInputSupplier(pos.world(), pos.pos()));
|
future.complete(new AnalogInputSupplier(pos.world(), pos.pos()));
|
||||||
|
me.goBack();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setItemName(Component.translatable("value_supplier.minions.analog_input.config.click_with_reference"))
|
.setItemName(Component.translatable("value_supplier.minions.analog_input.config.click_with_reference"))
|
||||||
|
|||||||
@@ -74,6 +74,8 @@
|
|||||||
|
|
||||||
"instruction.minions.walk": "Walk",
|
"instruction.minions.walk": "Walk",
|
||||||
"instruction.minions.walk.description": "Walk forward a specified amount of blocks",
|
"instruction.minions.walk.description": "Walk forward a specified amount of blocks",
|
||||||
|
"instruction.minions.walk_continuous": "Walk Continuously",
|
||||||
|
"instruction.minions.walk_continuous.description": "Walk forward until the instruction is stopped",
|
||||||
"instruction.minions.turn": "Turn",
|
"instruction.minions.turn": "Turn",
|
||||||
"instruction.minions.turn.description": "Turn the head by specific angle",
|
"instruction.minions.turn.description": "Turn the head by specific angle",
|
||||||
"instruction.minions.attack": "Attack",
|
"instruction.minions.attack": "Attack",
|
||||||
@@ -81,6 +83,9 @@
|
|||||||
"instruction.minions.use": "Use",
|
"instruction.minions.use": "Use",
|
||||||
"instruction.minions.use.description": "Use and place blocks",
|
"instruction.minions.use.description": "Use and place blocks",
|
||||||
"instruction.minions.swap_item": "Swap Items",
|
"instruction.minions.swap_item": "Swap Items",
|
||||||
|
"instruction.minions.swap_item.description": "Swap the items of two slots",
|
||||||
|
"instruction.minions.turn_vector": "Turn (Vector)",
|
||||||
|
"instruction.minions.turn_vector.description": "Turn the head so that it faces a block with specific cardinal offsets",
|
||||||
|
|
||||||
"value_type.minions.long": "Integer",
|
"value_type.minions.long": "Integer",
|
||||||
"value_type.minions.double": "Decimal",
|
"value_type.minions.double": "Decimal",
|
||||||
|
|||||||
Reference in New Issue
Block a user