From 3483af00368e40a57642b8552317283ff431d6ec Mon Sep 17 00:00:00 2001 From: wolfieboy09 <105564186+wolfieboy09@users.noreply.github.com> Date: Sat, 26 Oct 2024 07:47:54 -0400 Subject: [PATCH] A bunch of things. Need to get the block and JEI working with this --- .../qstorage/block/GlobalBlockEntity.java | 1 + .../qstorage/block/ItemResultSlot.java | 6 +- .../DiskAssemblerBlockEntity.java | 13 +++- .../disk_assembler/DiskAssemblerMenu.java | 61 ++++++++++++++----- .../disk_assembler/DiskAssemblerRecipe.java | 8 +-- .../intergration/jei/QSJEIPlugin.java | 2 +- .../DiskAssemblerCategory.java | 11 ++++ 7 files changed, 77 insertions(+), 25 deletions(-) diff --git a/src/main/java/dev/wolfieboy09/qstorage/block/GlobalBlockEntity.java b/src/main/java/dev/wolfieboy09/qstorage/block/GlobalBlockEntity.java index 3de9081..662869f 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/block/GlobalBlockEntity.java +++ b/src/main/java/dev/wolfieboy09/qstorage/block/GlobalBlockEntity.java @@ -4,6 +4,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.world.MenuProvider; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; diff --git a/src/main/java/dev/wolfieboy09/qstorage/block/ItemResultSlot.java b/src/main/java/dev/wolfieboy09/qstorage/block/ItemResultSlot.java index a8619ee..0fd6634 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/block/ItemResultSlot.java +++ b/src/main/java/dev/wolfieboy09/qstorage/block/ItemResultSlot.java @@ -6,9 +6,9 @@ import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.SlotItemHandler; -public class ItemResultSlot extends Slot { - public ItemResultSlot(Container container, int slot, int x, int y) { - super(container, slot, x, y); +public class ItemResultSlot extends SlotItemHandler { + public ItemResultSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition) { + super(itemHandler, index, xPosition, yPosition); } @Override diff --git a/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerBlockEntity.java b/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerBlockEntity.java index a2b9842..477dceb 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerBlockEntity.java +++ b/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerBlockEntity.java @@ -18,6 +18,17 @@ public DiskAssemblerBlockEntity(BlockPos pos, BlockState blockState) { super(QSBlockEntities.DISK_ASSEMBLER.get(), pos, blockState, 20000, 1000, 0); } + public static class DiskAssemblerSlot { + public static final int MAIN_SLOT_1 = 0; + public static final int MAIN_SLOT_2 = 1; + public static final int MAIN_SLOT_3 = 2; + public static final int EXTRA_SLOT_1 = 3; + public static final int EXTRA_SLOT_2 = 4; + public static final int EXTRA_SLOT_3 = 5; + public static final int EXTRA_SLOT_4 = 6; + public static final int OUTPUT_SLOT = 7; + } + private final ItemStackHandler inventory = new ItemStackHandler(8) { @Override protected void onContentsChanged(int slot) { @@ -35,7 +46,7 @@ protected void resetProgress() { if (this.progress != 0) { this.progress = 0; setChanged(); - Objects.requireNonNull(level).sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3); + Objects.requireNonNull(level).sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_ALL); } } diff --git a/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerMenu.java b/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerMenu.java index e9433cc..fb3e94e 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerMenu.java +++ b/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerMenu.java @@ -1,21 +1,25 @@ package dev.wolfieboy09.qstorage.block.disk_assembler; -import dev.wolfieboy09.qstorage.api.energy.ExtendedEnergyStorage; +import dev.wolfieboy09.qstorage.QuantiumizedStorage; import dev.wolfieboy09.qstorage.block.AbstractEnergyContainerMenu; import dev.wolfieboy09.qstorage.block.ItemResultSlot; +import dev.wolfieboy09.qstorage.registries.QSBlocks; import dev.wolfieboy09.qstorage.registries.QSMenuTypes; import net.minecraft.core.BlockPos; -import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.SlotItemHandler; import net.neoforged.neoforge.items.wrapper.PlayerInvWrapper; import org.jetbrains.annotations.NotNull; public class DiskAssemblerMenu extends AbstractEnergyContainerMenu { private DiskAssemblerBlockEntity blockEntity; + private Level level; + private ContainerData data; private static final int HOTBAR_SLOT_COUNT = 9; private static final int PLAYER_INVENTORY_ROW_COUNT = 3; @@ -37,14 +41,13 @@ public DiskAssemblerMenu(int id, BlockPos pos, Inventory playerInventory, Player DiskAssemblerBlockEntity blockEntity = (DiskAssemblerBlockEntity) playerIn.getCommandSenderWorld().getBlockEntity(pos); if (blockEntity == null) return; this.blockEntity = blockEntity; + this.level = playerInventory.player.level(); + this.data = containerData; PlayerInvWrapper playerInvWrapper = new PlayerInvWrapper(playerInventory); final int SLOT_X_SPACING = 18; final int SLOT_Y_SPACING = 18; - final int TE_SLOT_Y_SPACING = 48; - final int TILE_INVENTORY_XPOS = 70; - final int TILE_INVENTORY_YPOS = 12; final int HOTBAR_XPOS = 8; final int HOTBAR_YPOS = 142; @@ -64,26 +67,52 @@ public DiskAssemblerMenu(int id, BlockPos pos, Inventory playerInventory, Player } } - addSlot(new Slot((Container) containerData, 37, 17, 27)); - addSlot(new Slot((Container) containerData, 38, 17, 45)); - addSlot(new Slot((Container) containerData, 39, 35, 36)); + ItemStackHandler itemStackHandler = blockEntity.getInventory(); - addSlot(new Slot((Container) containerData, 40, 116, 27)); - addSlot(new Slot((Container) containerData, 41, 134, 27)); - addSlot(new Slot((Container) containerData, 42, 116, 45)); - addSlot(new Slot((Container) containerData, 43, 134, 45)); + addSlot(new SlotItemHandler(itemStackHandler, 0, 17, 27)); + addSlot(new SlotItemHandler(itemStackHandler, 1, 17, 45)); + addSlot(new SlotItemHandler(itemStackHandler, 2, 35, 36)); - addSlot(new ItemResultSlot((Container) containerData, 44, 80, 36)); + addSlot(new SlotItemHandler(itemStackHandler, 3, 116, 27)); + addSlot(new SlotItemHandler(itemStackHandler, 4, 134, 27)); + addSlot(new SlotItemHandler(itemStackHandler, 5, 116, 45)); + addSlot(new SlotItemHandler(itemStackHandler, 6, 134, 45)); + + addSlot(new ItemResultSlot(itemStackHandler, 7, 80, 36)); } @Override - public ItemStack quickMoveStack(Player player, int i) { - return ItemStack.EMPTY; + public @NotNull ItemStack quickMoveStack(@NotNull Player playerIn, int index) { + Slot sourceSlot = slots.get(index); + if (!sourceSlot.hasItem()) return ItemStack.EMPTY; + ItemStack sourceStack = sourceSlot.getItem(); + ItemStack copyOfSourceStack = sourceStack.copy(); + + if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) { + if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + + 7, false)) { + return ItemStack.EMPTY; + } + } else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + 7) { + if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) { + return ItemStack.EMPTY; + } + } else { + QuantiumizedStorage.LOGGER.warn("Invalid slotIndex: {}", index); + return ItemStack.EMPTY; + } + if (sourceStack.getCount() == 0) { + sourceSlot.set(ItemStack.EMPTY); + } else { + sourceSlot.setChanged(); + } + sourceSlot.onTake(playerIn, sourceStack); + return copyOfSourceStack; } @Override public boolean stillValid(@NotNull Player player) { - return true; + return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), player, QSBlocks.DISK_ASSEMBLER.get()); } @Override diff --git a/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerRecipe.java b/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerRecipe.java index 22ed1ee..4e16269 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerRecipe.java +++ b/src/main/java/dev/wolfieboy09/qstorage/block/disk_assembler/DiskAssemblerRecipe.java @@ -28,7 +28,7 @@ public record DiskAssemblerRecipe( Ingredient diskPort, Ingredient diskCasing, Ingredient screws, - List> extras, + List extras, int energyCost, int timeInTicks, ItemStack result @@ -36,7 +36,7 @@ public record DiskAssemblerRecipe( @Override public boolean matches(RecipeWrapper recipeWrapper, Level level) { - return !level.isClientSide(); + return true; } @Override @@ -70,7 +70,7 @@ public static class Serializer implements RecipeSerializer Ingredient.CODEC.fieldOf("port").forGetter(DiskAssemblerRecipe::diskPort), Ingredient.CODEC.fieldOf("casing").forGetter(DiskAssemblerRecipe::diskCasing), Ingredient.CODEC.fieldOf("screws").forGetter(DiskAssemblerRecipe::screws), - BuiltInRegistries.ITEM.holderByNameCodec().listOf().fieldOf("extras").forGetter(DiskAssemblerRecipe::extras), + Ingredient.CODEC.listOf().fieldOf("extras").forGetter(DiskAssemblerRecipe::extras), Codec.INT.fieldOf("energy").forGetter(DiskAssemblerRecipe::energyCost), Codec.INT.fieldOf("ticks").forGetter(DiskAssemblerRecipe::timeInTicks), ItemStack.CODEC.fieldOf("result").forGetter(DiskAssemblerRecipe::result) @@ -81,7 +81,7 @@ public static class Serializer implements RecipeSerializer Ingredient.CONTENTS_STREAM_CODEC, DiskAssemblerRecipe::diskPort, Ingredient.CONTENTS_STREAM_CODEC, DiskAssemblerRecipe::diskCasing, Ingredient.CONTENTS_STREAM_CODEC, DiskAssemblerRecipe::screws, - ByteBufCodecs.holderRegistry(Registries.ITEM).apply(ByteBufCodecs.list(4)), DiskAssemblerRecipe::extras, + Ingredient.CONTENTS_STREAM_CODEC.apply(ByteBufCodecs.list(4)), DiskAssemblerRecipe::extras, ByteBufCodecs.INT, DiskAssemblerRecipe::energyCost, ByteBufCodecs.INT, DiskAssemblerRecipe::timeInTicks, ItemStack.STREAM_CODEC, DiskAssemblerRecipe::result, diff --git a/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/QSJEIPlugin.java b/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/QSJEIPlugin.java index aaccb8e..3bd4c7e 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/QSJEIPlugin.java +++ b/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/QSJEIPlugin.java @@ -38,7 +38,7 @@ public void registerRecipes(@NotNull IRecipeRegistration registration) { RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager(); registration.addRecipes(DiskAssemblerCategory.RECIPE_TYPE, recipeManager.getAllRecipesFor(QSRecipes.DISK_ASSEMBLER_TYPE.get()).stream() - .map(RecipeHolder::value).collect(Collectors.toList())); + .map(RecipeHolder::value).toList()); } @Override diff --git a/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/disk_assembeler/DiskAssemblerCategory.java b/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/disk_assembeler/DiskAssemblerCategory.java index 81b0c36..2811e15 100644 --- a/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/disk_assembeler/DiskAssemblerCategory.java +++ b/src/main/java/dev/wolfieboy09/qstorage/intergration/jei/disk_assembeler/DiskAssemblerCategory.java @@ -1,5 +1,6 @@ package dev.wolfieboy09.qstorage.intergration.jei.disk_assembeler; +import com.mojang.serialization.Codec; import dev.wolfieboy09.qstorage.QuantiumizedStorage; import dev.wolfieboy09.qstorage.api.annotation.NothingNullByDefault; import dev.wolfieboy09.qstorage.api.util.ResourceHelper; @@ -9,6 +10,7 @@ import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.recipe.IFocusGroup; +import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.network.chat.Component; @@ -51,6 +53,15 @@ public IDrawable getBackground() { @Override public void setRecipe(IRecipeLayoutBuilder builder, DiskAssemblerRecipe recipe, IFocusGroup focuses) { + builder.addSlot(RecipeIngredientRole.INPUT, 17, 27); + builder.addSlot(RecipeIngredientRole.INPUT, 17, 45); + builder.addSlot(RecipeIngredientRole.INPUT, 35, 36); + builder.addSlot(RecipeIngredientRole.INPUT, 116, 27); + builder.addSlot(RecipeIngredientRole.INPUT, 134, 27); + builder.addSlot(RecipeIngredientRole.INPUT, 116, 45); + builder.addSlot(RecipeIngredientRole.INPUT, 134, 45); + + builder.addSlot(RecipeIngredientRole.OUTPUT, 80, 36); } }