This commit is contained in:
skippyall
2024-09-17 10:46:43 +02:00
parent 1dd6914454
commit d6a324a93f
3 changed files with 91 additions and 5 deletions
@@ -40,7 +40,7 @@ public class MinionGui {
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE) .setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
.setName(Text.translatable("minions.gui.main.modules")) .setName(Text.translatable("minions.gui.main.modules"))
.setCallback((i, clickType, slotActionType) -> { .setCallback((i, clickType, slotActionType) -> {
openModuleInventory(player, minion); ModuleInventory.openModuleInventory(player, minion);
}) })
); );
gui.setSlot(5, new GuiElementBuilder() gui.setSlot(5, new GuiElementBuilder()
@@ -61,10 +61,6 @@ public class MinionGui {
} }
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) { public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false); SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName())); gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName()));
@@ -1,13 +1,19 @@
package io.github.skippyall.minions.gui; package io.github.skippyall.minions.gui;
import io.github.skippyall.minions.command.Command; import io.github.skippyall.minions.command.Command;
import io.github.skippyall.minions.fakeplayer.MinionFakePlayer;
import io.github.skippyall.minions.module.ModuleItem; import io.github.skippyall.minions.module.ModuleItem;
import io.github.skippyall.minions.program.block.CodeBlock; import io.github.skippyall.minions.program.block.CodeBlock;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories; import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.SimpleInventory; import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.RegistryWrapper;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -17,6 +23,10 @@ public class ModuleInventory extends SimpleInventory {
super(27); super(27);
} }
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> new ModuleInventoryScreenHandler(syncId, playerInventory, minion.getModuleInventory()), Text.translatable("minions.gui.modules.title", minion.getName())));
}
@Override @Override
public int getMaxCountPerStack() { public int getMaxCountPerStack() {
return 1; return 1;
@@ -0,0 +1,80 @@
package io.github.skippyall.minions.gui;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
public class ModuleInventoryScreenHandler extends ScreenHandler {
private final int rows = 3;
private final ModuleInventory inventory;
public ModuleInventoryScreenHandler(int syncId, ModuleInventory inventory) {
super(ScreenHandlerType.GENERIC_9X3, syncId);
this.inventory = inventory;
}
public ModuleInventoryScreenHandler(int syncId, PlayerInventory playerInventory, ModuleInventory inventory) {
super(ScreenHandlerType.GENERIC_9X3, syncId);
int k;
int j;
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
this.inventory = inventory;
inventory.onOpen(playerInventory.player);
int i = (rows - 4) * 18;
for (j = 0; j < rows; ++j) {
for (k = 0; k < 9; ++k) {
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
@Override
public boolean canInsert(ItemStack stack) {
return super.canInsert(stack) && inventory.isValid(getIndex(), stack);
}
});
}
}
for (j = 0; j < 3; ++j) {
for (k = 0; k < 9; ++k) {
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
}
}
for (j = 0; j < 9; ++j) {
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 161 + i));
}
}
@Override
public boolean canUse(PlayerEntity player) {
return this.inventory.canPlayerUse(player);
}
@Override
public ItemStack quickMove(PlayerEntity player, int slot) {
ItemStack itemStack = ItemStack.EMPTY;
Slot slot2 = (Slot)this.slots.get(slot);
if (slot2 != null && slot2.hasStack()) {
ItemStack itemStack2 = slot2.getStack();
itemStack = itemStack2.copy();
if (slot < this.rows * 9 ? !this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true) : !this.insertItem(itemStack2, 0, this.rows * 9, false)) {
return ItemStack.EMPTY;
}
if (itemStack2.isEmpty()) {
slot2.setStack(ItemStack.EMPTY);
} else {
slot2.markDirty();
}
}
return itemStack;
}
@Override
public void onClosed(PlayerEntity player) {
super.onClosed(player);
this.inventory.onClose(player);
}
public ModuleInventory getInventory() {
return inventory;
}
}