e
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.command.Command;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.module.ModuleItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandsGui {
|
||||
public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
List<ModuleItem> modules = minion.getModuleInventory().getModuleItems();
|
||||
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||
|
||||
gui.setTitle(Text.translatable("minions.gui.module_commands.title"));
|
||||
|
||||
for (int i = 0; i < modules.size(); i++) {
|
||||
ModuleItem module = modules.get(i);
|
||||
gui.setSlot(i, new GuiElementBuilder()
|
||||
.setItem(module.asItem())
|
||||
.setCallback(() -> openServerCommandGui(player, minion, module))
|
||||
);
|
||||
}
|
||||
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public static void openServerCommandGui(ServerPlayerEntity player, MinionFakePlayer minion, ModuleItem module) {
|
||||
List<Command> commands = module.getCommands();
|
||||
|
||||
SimpleGui commandGui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||
|
||||
commandGui.setTitle(Text.translatable("minions.gui.commands.title", module.asItem().getName()));
|
||||
|
||||
for(int j = 0; j < commands.size(); j++) {
|
||||
Command command = commands.get(j);
|
||||
commandGui.setSlot(j, new GuiElementBuilder()
|
||||
.setItem(command.getItemRepresentation())
|
||||
.setName(command.getName())
|
||||
.addLoreLine(command.getDescription())
|
||||
.setCallback(() -> command.onRun(player, minion))
|
||||
);
|
||||
}
|
||||
|
||||
commandGui.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class MinionGui {
|
||||
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
openServerSideInventory(player, minion);
|
||||
}
|
||||
|
||||
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
||||
gui.setTitle(minion.getName());
|
||||
|
||||
gui.setSlot(1, new GuiElementBuilder()
|
||||
.setItem(Items.COMMAND_BLOCK)
|
||||
.setName(Text.translatable("minions.gui.main.commands"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openCommandsGui(player, minion);
|
||||
})
|
||||
);
|
||||
if(minion.isProgrammable()) {
|
||||
gui.setSlot(4, new GuiElementBuilder()
|
||||
.setItem(Items.REDSTONE)
|
||||
.setName(Text.translatable("minions.gui.main.programming"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openProgrammingInventory(player, minion);
|
||||
})
|
||||
);
|
||||
}
|
||||
gui.setSlot(3, new GuiElementBuilder()
|
||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||
.setName(Text.translatable("minions.gui.main.modules"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openModuleInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(5, new GuiElementBuilder()
|
||||
.setItem(Items.CHEST)
|
||||
.setName(Text.translatable("minions.gui.main.inventory"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openMinionInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public static void openCommandsGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
CommandsGui.openServerModuleCommandGui(player, minion);
|
||||
}
|
||||
|
||||
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
|
||||
}
|
||||
|
||||
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, minion.getModuleInventory()), Text.translatable("")));
|
||||
}
|
||||
|
||||
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
||||
gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName()));
|
||||
for (int i = 0; i < minion.getInventory().size(); i++) {
|
||||
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
||||
}
|
||||
gui.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import io.github.skippyall.minions.command.Command;
|
||||
import io.github.skippyall.minions.module.ModuleItem;
|
||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.inventory.SimpleInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleInventory extends SimpleInventory {
|
||||
public ModuleInventory() {
|
||||
super(27);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCountPerStack() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int slot, ItemStack stack) {
|
||||
return (stack.getCount() <= getMaxCountPerStack()) && stack.getItem() instanceof ModuleItem;
|
||||
}
|
||||
|
||||
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||
Inventories.readNbt(nbt, heldStacks, lookup);
|
||||
}
|
||||
|
||||
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||
return Inventories.writeNbt(nbt, heldStacks, lookup);
|
||||
}
|
||||
|
||||
public boolean hasModule(ModuleItem module) {
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module2 && module2 == module) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ModuleItem> getModuleItems() {
|
||||
ArrayList<ModuleItem> modules = new ArrayList<>();
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module) {
|
||||
modules.add(module);
|
||||
}
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
public List<Command> getAllCommands() {
|
||||
ArrayList<Command> commands = new ArrayList<>();
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module) {
|
||||
commands.addAll(module.getCommands());
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public List<CodeBlock<?,?>> getAllCodeBlocks() {
|
||||
ArrayList<CodeBlock<?,?>> commands = new ArrayList<>();
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module) {
|
||||
commands.addAll(module.getCodeBlocks());
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user