Skip to content

Commit

Permalink
A bunch of things. Need to get the block and JEI working with this
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfieboy09 committed Oct 26, 2024
1 parent ced15c0 commit 3483af0
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public record DiskAssemblerRecipe(
Ingredient diskPort,
Ingredient diskCasing,
Ingredient screws,
List<Holder<Item>> extras,
List<Ingredient> extras,
int energyCost,
int timeInTicks,
ItemStack result
) implements Recipe<RecipeWrapper>, RecipeType<DiskAssemblerRecipe> {

@Override
public boolean matches(RecipeWrapper recipeWrapper, Level level) {
return !level.isClientSide();
return true;
}

@Override
Expand Down Expand Up @@ -70,7 +70,7 @@ public static class Serializer implements RecipeSerializer<DiskAssemblerRecipe>
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)
Expand All @@ -81,7 +81,7 @@ public static class Serializer implements RecipeSerializer<DiskAssemblerRecipe>
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3483af0

Please sign in to comment.