diff --git a/gradle.properties b/gradle.properties index f138230..c63b9fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ minecraft_version=1.21 # as they do not follow standard versioning conventions. minecraft_version_range=[1.21,1.21.1) # The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=21.0.164 +neo_version=21.0.167 # The Neo version range can use any version of Neo as bounds neo_version_range=[21.0.0-beta,) # The loader version range can only use the major version of FML as bounds diff --git a/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 b/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 index 7a6b941..4c9733f 100644 --- a/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 +++ b/src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361 @@ -1,2 +1,2 @@ -// 1.21 2024-08-13T03:55:33.7111786 Languages: zh_cn for mod: lingshi -6691b4e3de41dca51664777d2790f94bd059d1ac assets/lingshi/lang/zh_cn.json +// 1.21 2024-08-15T20:42:41.6040699 Languages: zh_cn for mod: lingshi +ad34dce9233433d976c01585ed4b08af089d10f5 assets/lingshi/lang/zh_cn.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 17e86d0..9633c33 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,8 @@ -// 1.21 2024-08-14T05:22:07.8393123 Recipes -80c03e628f24c66af32ca2f2a7f7efcfedeacb9f data/lingshi/advancement/recipes/skillet/dd.json -4f3b846962abd318042306445c7ecd01a176ef1f data/lingshi/recipe/chopping_board/rice.json -f8fc62d1b3c33ff6e83d1d8f585d6dc4deff2cd3 data/lingshi/recipe/skillet/dd.json +// 1.21 2024-08-16T05:17:35.2742695 Recipes +5bebf6a89fdd6614d0e0b2b0908f76f48afe8ad3 data/lingshi/advancement/recipes/skillet/test00.json +82ba2633d02b797c4ed89708055c8aab59a9cc39 data/lingshi/advancement/recipes/skillet/test01.json +b055e56217dec23b58a0c5f454e5dd060e0ed81a data/lingshi/advancement/recipes/skillet/test02.json +3e41620c4ec5b19f87046dad7fe5c7ed6ede21c2 data/lingshi/recipe/chopping_board/rice.json +9622697bc2a3e83291b218d768aa2c1026c1d38f data/lingshi/recipe/skillet/test00.json +43b74387359bb0f936238fc99d5dce19aa60859a data/lingshi/recipe/skillet/test01.json +49673e41d352c946039d76d4a55b406153e7cc00 data/lingshi/recipe/skillet/test02.json diff --git a/src/generated/resources/assets/lingshi/lang/zh_cn.json b/src/generated/resources/assets/lingshi/lang/zh_cn.json index 07d1cd8..cc58628 100644 --- a/src/generated/resources/assets/lingshi/lang/zh_cn.json +++ b/src/generated/resources/assets/lingshi/lang/zh_cn.json @@ -4,6 +4,7 @@ "block.lingshi.rice_seedling": "稻苗", "block.lingshi.skillet": "平底锅", "block.lingshi.tea_tree": "茶树", + "gui.lingshi.skillet_menu": "平底锅", "item.lingshi.iron_knife": "铁菜刀", "item.lingshi.rice_of_ear": "稻穗", "item.lingshi.tea_leaf": "茶叶", diff --git a/src/generated/resources/data/lingshi/recipe/chopping_board/rice.json b/src/generated/resources/data/lingshi/recipe/chopping_board/rice.json index c815ef0..978c84e 100644 --- a/src/generated/resources/data/lingshi/recipe/chopping_board/rice.json +++ b/src/generated/resources/data/lingshi/recipe/chopping_board/rice.json @@ -1,5 +1,5 @@ { - "type": "lingshi:chopping_board_serializer", + "type": "lingshi:chopping_board", "input": { "item": "lingshi:rice_of_ear" }, diff --git a/src/main/java/mczme/lingshi/ModEnumParams.java b/src/main/java/mczme/lingshi/ModEnumParams.java new file mode 100644 index 0000000..b3e6928 --- /dev/null +++ b/src/main/java/mczme/lingshi/ModEnumParams.java @@ -0,0 +1,25 @@ +package mczme.lingshi; + +import mczme.lingshi.common.registry.ModItems; +import net.minecraft.client.RecipeBookCategories; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.neoforged.fml.common.asm.enumextension.EnumProxy; + +import java.util.List; +import java.util.function.Supplier; + +public class ModEnumParams { + + public static final EnumProxy SKILLET_SEARCH_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(Items.COMPASS) ); + public static final EnumProxy SKILLET_HEAT_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(ModItems.RICE_OF_EAR.get())); + public static final EnumProxy PAN_FRY_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(ModItems.RICE.get())); + public static final EnumProxy STIR_FRY_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(ModItems.IRON_KNIFE.get())); + public static final EnumProxy BOIL_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(Items.WHEAT)); + public static final EnumProxy MISC_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(Items.BUCKET)); + + private static Supplier> params(Item item){ + return ()-> List.of(new ItemStack(item)); + } +} diff --git a/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java b/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java new file mode 100644 index 0000000..f8d6929 --- /dev/null +++ b/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java @@ -0,0 +1,41 @@ +package mczme.lingshi.client.BlockEntityRenderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Axis; +import mczme.lingshi.common.block.ChoppingBoardBlock; +import mczme.lingshi.common.block.entity.SkilletBlockEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.core.Direction; +import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; + +import java.util.List; + +public class SkilletBER implements BlockEntityRenderer { + + public SkilletBER(BlockEntityRendererProvider.Context pContext){ + + } + + @Override + public void render(SkilletBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { + List itemStack = pBlockEntity.getItemStacks(); + Direction direction = pBlockEntity.getBlockState().getValue(ChoppingBoardBlock.FACING); + + if(!itemStack.isEmpty()){ + for (int i = 0; i + { + if (recipe.value() instanceof SkilletRecipe Recipe) { + CookingFoodRecipeLabel label = Recipe.getLabel(); + return switch (label) { + case HEAT -> SKILLET_HEAT.get(); + case PAN_FRY -> SKILLET_PAN_FRY.get(); + case STIR_FRY -> SKILLET_STIR_FRY.get(); + case BOIL -> SKILLET_BOIL.get(); + default -> MISC.get(); + }; + } + return MISC.get(); + }); + } + } diff --git a/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java b/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java new file mode 100644 index 0000000..fb3049a --- /dev/null +++ b/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java @@ -0,0 +1,169 @@ +package mczme.lingshi.client.menu; + +import mczme.lingshi.common.block.entity.SkilletBlockEntity; +import mczme.lingshi.common.recipe.SkilletRecipe; +import mczme.lingshi.common.recipe.input.SkilletRecipeInput; +import mczme.lingshi.common.registry.ModMenuTypes; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.StackedContents; +import net.minecraft.world.inventory.*; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.level.Level; +import net.neoforged.neoforge.items.ItemStackHandler; +import net.neoforged.neoforge.items.SlotItemHandler; + +import java.util.List; + +import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET; +import static mczme.lingshi.common.utility.ListUtility.copy; + +public class SkilletMenu extends RecipeBookMenu { + + SkilletBlockEntity blockEntity; + public final ItemStackHandler inventory; + protected final Level level; + + public SkilletMenu(int pContainerId, Inventory pPlayerInventory, FriendlyByteBuf pContext) { + this(pContainerId, pPlayerInventory, (SkilletBlockEntity) pPlayerInventory.player.level().getBlockEntity(pContext.readBlockPos())); + } + + public SkilletMenu(int pContainerId, Inventory pPlayerInventory, + SkilletBlockEntity blockEntity) { + super(ModMenuTypes.SKILLET_MENU.get(), pContainerId); + checkContainerSize(pPlayerInventory, 1); + this.blockEntity = blockEntity; + this.inventory = blockEntity.getInventory(); + this.level = pPlayerInventory.player.level(); + this.addWorkSlot(copy(blockEntity.getItemStacks())); + layoutPlayerInventorySlots(pPlayerInventory); + } + + private void addWorkSlot(List itemStacks) { + if (itemStacks.size() < blockEntity.getMAX()) { + for (int i = itemStacks.size(); i < blockEntity.getMAX(); i++) + itemStacks.add(ItemStack.EMPTY); + } + int[] X = {42, 60, 33, 51, 69, 98, 127}; + int[] Y = {29, 29, 47, 47, 47, 29, 47}; + for (int i = 0; i < blockEntity.getMAX(); i++) { + SlotItemHandler slot = new SlotItemHandler(inventory, i, X[i], Y[i]); + slot.set(itemStacks.get(i)); + this.addSlot(slot); + } + this.addSlot(new SlotItemHandler(inventory, 5, X[5], Y[5])); + this.addSlot(new SlotItemHandler(inventory, 6, X[6], Y[6])); + } + + private void layoutPlayerInventorySlots(Inventory playerInventory) { + // Player inventory + for (int i = 0; i < 3; ++i) { + for (int l = 0; l < 9; ++l) { + this.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 84 + i * 18)); + } + } + // Hotbar + for (int i = 0; i < 9; ++i) { + this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); + } + } + + @Override + public void removed(Player pPlayer) { + blockEntity.getItemStacks().clear(); + for (int i = 0; i < blockEntity.getMAX(); i++) { + if (!this.getSlot(i).getItem().isEmpty()) { + blockEntity.setItem(this.getSlot(i).getItem()); + } + } + blockEntity.setChanged(); + super.removed(pPlayer); + } + + @Override + public ItemStack quickMoveStack(Player pPlayer, int pIndex) { + ItemStack quickMovedStack = ItemStack.EMPTY; + Slot quickMovedSlot = this.slots.get(pIndex); + if (quickMovedSlot.hasItem()) { + ItemStack rawStack = quickMovedSlot.getItem(); + quickMovedStack = rawStack.copy(); + if (pIndex >= 7 && pIndex < 43) { + if (!this.moveItemStackTo(rawStack, 0, 5, false)) { + if (pIndex < 32) { + if (!this.moveItemStackTo(rawStack, 34, 43, false)) { + return ItemStack.EMPTY; + } + } else if (!this.moveItemStackTo(rawStack, 7, 34, false)) { + return ItemStack.EMPTY; + } + } + } else if (!this.moveItemStackTo(rawStack, 7, 43, false)) { + return ItemStack.EMPTY; + } + + if (rawStack.isEmpty()) { + quickMovedSlot.set(ItemStack.EMPTY); + } else { + quickMovedSlot.setChanged(); + } + if (rawStack.getCount() == quickMovedStack.getCount()) { + return ItemStack.EMPTY; + } + quickMovedSlot.onTake(pPlayer, rawStack); + } + return quickMovedStack; + } + + @Override + public boolean stillValid(Player pPlayer) { + return true; + } + + @Override + public void fillCraftSlotsStackedContents(StackedContents pItemHelper) { + + } + + @Override + public void clearCraftingContent() { + this.getSlot(0).set(ItemStack.EMPTY); + this.getSlot(2).set(ItemStack.EMPTY); + } + + @Override + public boolean recipeMatches(RecipeHolder pRecipe) { + return true; + } + + @Override + public int getResultSlotIndex() { + return 6; + } + + @Override + public int getGridWidth() { + return 1; + } + + @Override + public int getGridHeight() { + return 7; + } + + @Override + public int getSize() { + return 7; + } + + @Override + public RecipeBookType getRecipeBookType() { + return SKILLET; + } + + @Override + public boolean shouldMoveToInventory(int pSlotIndex) { + return pSlotIndex != 1; + } +} diff --git a/src/main/java/mczme/lingshi/client/recipebook/CookingFoodRecipeLabel.java b/src/main/java/mczme/lingshi/client/recipebook/CookingFoodRecipeLabel.java new file mode 100644 index 0000000..e04b2a4 --- /dev/null +++ b/src/main/java/mczme/lingshi/client/recipebook/CookingFoodRecipeLabel.java @@ -0,0 +1,39 @@ +package mczme.lingshi.client.recipebook; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; + +public enum CookingFoodRecipeLabel { + HEAT("heat"), + PAN_FRY("pan_fry"), + STIR_FRY("stir_fry"), + BOIL("boil"), + STEW("stew"), + DEEP_FRY("deep_fly"), + MISC("misc"); + + public final String string; + public static final Codec CODEC = Codec.STRING.flatXmap(s -> { + CookingFoodRecipeLabel label = isinside(s); + if(s!=null) return DataResult.success(label); + else return DataResult.error(()-> "Unknown cooking food recipe label: " + s); + },label -> DataResult.success(label.toString()) + ); + + CookingFoodRecipeLabel(String string) { + this.string = string; + } + + public static CookingFoodRecipeLabel isinside(String s){ + CookingFoodRecipeLabel[] t = values(); + for(CookingFoodRecipeLabel i : t) { + if (i.toString().equals(s)) return i; + } + return null; + } + + @Override + public String toString() { + return string; + } +} diff --git a/src/main/java/mczme/lingshi/client/recipebook/ModRecipeBookCategories.java b/src/main/java/mczme/lingshi/client/recipebook/ModRecipeBookCategories.java new file mode 100644 index 0000000..e000f2f --- /dev/null +++ b/src/main/java/mczme/lingshi/client/recipebook/ModRecipeBookCategories.java @@ -0,0 +1,15 @@ +package mczme.lingshi.client.recipebook; + +import com.google.common.base.Suppliers; +import net.minecraft.client.RecipeBookCategories; + +import java.util.function.Supplier; + +public class ModRecipeBookCategories { + public static final Supplier SKILLET_SEARCH = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_SKILLET_SEARCH")); + public static final Supplier SKILLET_HEAT = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_SKILLET_HEAT")); + public static final Supplier SKILLET_PAN_FRY = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_PAN_FRY")); + public static final Supplier SKILLET_STIR_FRY = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_STIR_FRY")); + public static final Supplier SKILLET_BOIL = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_BOIL")); + public static final Supplier MISC = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_MISC")); +} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/client/recipebook/ModRecipeBookType.java b/src/main/java/mczme/lingshi/client/recipebook/ModRecipeBookType.java new file mode 100644 index 0000000..57a4a0e --- /dev/null +++ b/src/main/java/mczme/lingshi/client/recipebook/ModRecipeBookType.java @@ -0,0 +1,7 @@ +package mczme.lingshi.client.recipebook; + +import net.minecraft.world.inventory.RecipeBookType; + +public class ModRecipeBookType { + public static final RecipeBookType SKILLET = RecipeBookType.valueOf("lingshi_SKILLET"); +} diff --git a/src/main/java/mczme/lingshi/client/recipebook/SkilletRecipeBookComponent.java b/src/main/java/mczme/lingshi/client/recipebook/SkilletRecipeBookComponent.java new file mode 100644 index 0000000..de253e5 --- /dev/null +++ b/src/main/java/mczme/lingshi/client/recipebook/SkilletRecipeBookComponent.java @@ -0,0 +1,46 @@ +package mczme.lingshi.client.recipebook; + +import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; +import net.minecraft.core.NonNullList; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeHolder; + +import javax.annotation.Nullable; +import java.util.Iterator; +import java.util.List; + +public class SkilletRecipeBookComponent extends RecipeBookComponent { + + @Override + public void slotClicked(@Nullable Slot pSlot) { + super.slotClicked(pSlot); + if (pSlot != null && pSlot.index < this.menu.getSize()) { + this.ghostRecipe.clear(); + } + } + + @Override + public void setupGhostRecipe(RecipeHolder pRecipe, List pSlots) { + ItemStack itemstack = pRecipe.value().getResultItem(this.minecraft.level.registryAccess()); + this.ghostRecipe.setRecipe(pRecipe); + this.ghostRecipe.addIngredient(Ingredient.of(itemstack), pSlots.get(2).x, pSlots.get(2).y); + NonNullList nonnulllist = pRecipe.value().getIngredients(); + + Iterator iterator = nonnulllist.iterator(); + + for (int i = 0; i < 2; i++) { + if (!iterator.hasNext()) { + return; + } + + Ingredient ingredient = iterator.next(); + if (!ingredient.isEmpty()) { + Slot slot1 = pSlots.get(i); + this.ghostRecipe.addIngredient(ingredient, slot1.x, slot1.y); + } + } + } + +} diff --git a/src/main/java/mczme/lingshi/client/screen/SkilletScreen.java b/src/main/java/mczme/lingshi/client/screen/SkilletScreen.java new file mode 100644 index 0000000..412828c --- /dev/null +++ b/src/main/java/mczme/lingshi/client/screen/SkilletScreen.java @@ -0,0 +1,112 @@ +package mczme.lingshi.client.screen; + +import mczme.lingshi.client.menu.SkilletMenu; +import mczme.lingshi.client.recipebook.SkilletRecipeBookComponent; +import mczme.lingshi.lingshi; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; +import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.Slot; + +public class SkilletScreen extends AbstractContainerScreen implements RecipeUpdateListener { + + public final SkilletRecipeBookComponent recipeBookComponent = new SkilletRecipeBookComponent(); + private boolean widthTooNarrow; + private static final ResourceLocation BACKGROUND_TEXTURE = ResourceLocation.fromNamespaceAndPath(lingshi.MODID,"textures/gui/container/skillet.png"); + + public SkilletScreen(SkilletMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu,pPlayerInventory, pTitle); + } + + @Override + public void init(){ + super.init(); + this.widthTooNarrow = this.width < 379; + this.recipeBookComponent.init(this.width, this.height, this.minecraft, this.widthTooNarrow, this.menu); + this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth); + this.addRenderableWidget(new ImageButton(this.leftPos + 20, this.height / 2 - 49, 20, 18, RecipeBookComponent.RECIPE_BUTTON_SPRITES, p_313431_ -> { + this.recipeBookComponent.toggleVisibility(); + this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth); + p_313431_.setPosition(this.leftPos + 20, this.height / 2 - 49); + })); + this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2; + } + + @Override + public void containerTick() { + super.containerTick(); + this.recipeBookComponent.tick(); + } + + @Override + public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { + if (this.recipeBookComponent.isVisible() && this.widthTooNarrow) { + this.renderBackground(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + this.recipeBookComponent.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + } else { + super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + this.recipeBookComponent.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + this.recipeBookComponent.renderGhostRecipe(pGuiGraphics, this.leftPos, this.topPos, true, pPartialTick); + } + + this.renderTooltip(pGuiGraphics, pMouseX, pMouseY); + this.recipeBookComponent.renderTooltip(pGuiGraphics, this.leftPos, this.topPos, pMouseX, pMouseY); + super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + } + + @Override + protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) { + pGuiGraphics.blit(BACKGROUND_TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); + } + + @Override + public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) { + if (this.recipeBookComponent.mouseClicked(pMouseX, pMouseY, pButton)) { + return true; + } else { + return this.widthTooNarrow && this.recipeBookComponent.isVisible() ? true : super.mouseClicked(pMouseX, pMouseY, pButton); + } + } + + @Override + protected void slotClicked(Slot pSlot, int pSlotId, int pMouseButton, ClickType pType) { + super.slotClicked(pSlot, pSlotId, pMouseButton, pType); + this.recipeBookComponent.slotClicked(pSlot); + } + + @Override + public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) { + return this.recipeBookComponent.keyPressed(pKeyCode, pScanCode, pModifiers) ? true : super.keyPressed(pKeyCode, pScanCode, pModifiers); + } + + @Override + protected boolean hasClickedOutside(double pMouseX, double pMouseY, int pGuiLeft, int pGuiTop, int pMouseButton) { + boolean flag = pMouseX < (double)pGuiLeft + || pMouseY < (double)pGuiTop + || pMouseX >= (double)(pGuiLeft + this.imageWidth) + || pMouseY >= (double)(pGuiTop + this.imageHeight); + return this.recipeBookComponent.hasClickedOutside(pMouseX, pMouseY, this.leftPos, this.topPos, this.imageWidth, this.imageHeight, pMouseButton) && flag; + } + + @Override + public boolean charTyped(char pCodePoint, int pModifiers) { + return this.recipeBookComponent.charTyped(pCodePoint, pModifiers) ? true : super.charTyped(pCodePoint, pModifiers); + } + + @Override + public void recipesUpdated() { + this.recipeBookComponent.recipesUpdated(); + } + + @Override + public RecipeBookComponent getRecipeBookComponent() { + return this.recipeBookComponent; + } + +} diff --git a/src/main/java/mczme/lingshi/common/block/SkilletBlock.java b/src/main/java/mczme/lingshi/common/block/SkilletBlock.java index 744b28a..0a5106b 100644 --- a/src/main/java/mczme/lingshi/common/block/SkilletBlock.java +++ b/src/main/java/mczme/lingshi/common/block/SkilletBlock.java @@ -4,10 +4,7 @@ import mczme.lingshi.common.block.entity.SkilletBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.ItemInteractionResult; +import net.minecraft.world.*; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; @@ -55,16 +52,27 @@ protected MapCodec codec() { public ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHitResult) { if(pLevel.getBlockEntity(pPos) instanceof SkilletBlockEntity blockEntity){ + if(!blockEntity.isFull() && !pStack.isEmpty()){ + blockEntity.setItem(pStack); + pStack.consume(pStack.getCount(),pPlayer); + blockEntity.setChanged(); + return ItemInteractionResult.SUCCESS; + } + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } - return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION; } @Override protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) { if(pLevel.getBlockEntity(pPos) instanceof SkilletBlockEntity blockEntity){ - if(pPlayer.isShiftKeyDown() && !pLevel.isClientSide() && pPlayer instanceof ServerPlayer){ -// pPlayer.openMenu() + if(pPlayer.isShiftKeyDown() ){ + if(!pLevel.isClientSide()){ + pPlayer.openMenu(blockEntity,pPos); + } + }else if(!blockEntity.getItemStacks().isEmpty()) { + Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY()+0.2, pPos.getZ(), blockEntity.dropItem()); + blockEntity.setChanged(); } } return InteractionResult.sidedSuccess(pLevel.isClientSide); @@ -114,5 +122,4 @@ public RenderShape getRenderShape(BlockState pState) { protected void createBlockStateDefinition(StateDefinition.Builder pBuilder) { pBuilder.add(FACING, HAS_SUPPORT); } - } diff --git a/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java b/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java index 54485a7..20ac2d2 100644 --- a/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java +++ b/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java @@ -1,116 +1,167 @@ package mczme.lingshi.common.block.entity; +import mczme.lingshi.client.menu.SkilletMenu; import mczme.lingshi.common.registry.BlockEntityTypes; +import mczme.lingshi.lingshi; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; -import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.world.ContainerHelper; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.items.ItemStackHandler; +import org.jetbrains.annotations.Nullable; -public class SkilletBlockEntity extends BlockEntity { +import java.util.ArrayList; +import java.util.List; + +public class SkilletBlockEntity extends BlockEntity implements MenuProvider { + + private List itemStacks = new ArrayList<>(); + private FluidStack fluidStacks = new FluidStack(Fluids.WATER, 1000); - private NonNullList itemStacks = NonNullList.withSize(5, ItemStack.EMPTY); - private NonNullList fluidStacks = NonNullList.withSize(5, FluidStack.EMPTY); private final int MAX_SLOT = 5; + private final ItemStackHandler inventory = new ItemStackHandler(MAX_SLOT + 2); + public SkilletBlockEntity(BlockPos pPos, BlockState pBlockState) { super(BlockEntityTypes.SKILLET_BLOCKENTITY.get(), pPos, pBlockState); } - public boolean isFull(){ - return itemStacks.size()+fluidStacks.size() >= MAX_SLOT; + public boolean isFull() { + return itemStacks.size() >= MAX_SLOT; } - public ItemStack getItem(int slot){ + public ItemStack getItem(int slot) { return itemStacks.get(slot); } - public FluidStack getFluid(int slot){ - return fluidStacks.get(slot); + public ItemStack dropItem() { + return itemStacks.removeLast(); } - public NonNullList getItemStacks(){ - return itemStacks; + public FluidStack getFluid() { + return fluidStacks; } - public NonNullList getFluidStacks(){ - return fluidStacks; + public List getItemStacks() { + return itemStacks; } - public void setItem(ItemStack item){ + public void setItem(ItemStack item) { itemStacks.add(item); } - public void setFluid(FluidStack fluid){ - fluidStacks.add(fluid); + public void setFluid(FluidStack fluid) { + fluidStacks = fluid; + } + + public int getMAX() { + return MAX_SLOT; + } + + public ItemStackHandler getInventory() { + return inventory; } @Override - public ClientboundBlockEntityDataPacket getUpdatePacket() { + public Packet getUpdatePacket() { return ClientboundBlockEntityDataPacket.create(this); } @Override public CompoundTag getUpdateTag(HolderLookup.Provider pRegistries) { - return this.saveCustomOnly(pRegistries); + CompoundTag tag = new CompoundTag(); + ListTag listtag = new ListTag(); + if (!itemStacks.isEmpty()) { + for (int i = 0; i < itemStacks.size(); i++) { + ItemStack itemstack = itemStacks.get(i); + if (!itemstack.isEmpty()) { + CompoundTag compoundtag = new CompoundTag(); + compoundtag.putByte("Slot", (byte) i); + listtag.add(itemstack.save(pRegistries, compoundtag)); + } + } + } + tag.put("skillet", listtag); + if (!fluidStacks.isEmpty()) { + tag.put("fluid", fluidStacks.save(pRegistries)); + } + return tag; } @Override protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { - try{ - ContainerHelper.loadAllItems(pTag, itemStacks, pRegistries); - loadFluid(pTag,fluidStacks,pRegistries); - }catch (Exception e){ - itemStacks=NonNullList.withSize(5, ItemStack.EMPTY); - fluidStacks=NonNullList.withSize(5, FluidStack.EMPTY); + ListTag listtag = (ListTag) pTag.get("skillet"); + if (listtag != null) { + for (int i = 0; i < listtag.size(); i++) { + CompoundTag compoundtag = listtag.getCompound(i); + int j = compoundtag.getByte("Slot") & 255; + itemStacks.add(j, ItemStack.parse(pRegistries, compoundtag).orElse(ItemStack.EMPTY)); + } + } + if (pTag.get("fluid") != null) { + fluidStacks = FluidStack.parse(pRegistries, pTag.getCompound("fluid")).orElse(FluidStack.EMPTY); } } @Override protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { super.saveAdditional(pTag, pRegistries); + ListTag listtag = new ListTag(); if (!this.itemStacks.isEmpty()) { - ContainerHelper.saveAllItems(pTag, this.itemStacks, pRegistries); + for (int i = 0; i < itemStacks.size(); i++) { + ItemStack itemstack = itemStacks.get(i); + if (!itemstack.isEmpty()) { + CompoundTag compoundtag = new CompoundTag(); + compoundtag.putByte("Slot", (byte) i); + listtag.add(itemstack.save(pRegistries, compoundtag)); + } + } } if (!this.fluidStacks.isEmpty()) { - saveFluid(pTag, this.fluidStacks, true, pRegistries); + pTag.put("fluid", fluidStacks.save(pRegistries)); } + pTag.put("skillet", listtag); } - private void loadFluid(CompoundTag pTag, NonNullList pItems, HolderLookup.Provider pLevelRegistry){ - ListTag listtag = (ListTag)pTag.get("Fluids"); - - for (int i = 0; i < listtag.size(); i++) { - CompoundTag compoundtag = listtag.getCompound(i); - int j = compoundtag.getByte("Slot") & 255; - if (j >= 0 && j < pItems.size()) { - pItems.set(j, FluidStack.parse(pLevelRegistry, compoundtag).orElse(FluidStack.EMPTY)); + private void loadItem(CompoundTag pTag, HolderLookup.Provider pLevelRegistry) { + ListTag listtag = (ListTag) pTag.get("item"); + if (listtag != null) { + for (int i = 0; i < listtag.size(); i++) { + CompoundTag compoundtag = listtag.getCompound(i); + int j = compoundtag.getByte("Slot") & 255; + itemStacks.add(j, ItemStack.parse(pLevelRegistry, compoundtag).orElse(ItemStack.EMPTY)); } - } - } - - private CompoundTag saveFluid(CompoundTag pTag, NonNullList pItems, boolean pAlwaysPutTag, HolderLookup.Provider pLevelRegistry){ - ListTag listtag = new ListTag(); - - for (int i = 0; i < pItems.size(); i++) { - FluidStack fluidstack = pItems.get(i); - if (!fluidstack.isEmpty()) { - CompoundTag compoundtag = new CompoundTag(); - compoundtag.putByte("Slot", (byte)i); - listtag.add(fluidstack.save(pLevelRegistry, compoundtag)); + } else if (this.level != null && this.level.isClientSide()) { + for (int i = 0; i < pTag.size(); i++) { + itemStacks.add(i, ItemStack.parse(pLevelRegistry, pTag.getCompound("Item" + i)).orElse(ItemStack.EMPTY)); } + } else { + itemStacks = new ArrayList<>(); + setChanged(); } + } - if (!listtag.isEmpty() || pAlwaysPutTag) { - pTag.put("Fluids", listtag); - } + @Override + public Component getDisplayName() { + return Component.translatable("gui." + lingshi.MODID + ".skillet_menu"); + } - return pTag; + @Nullable + @Override + public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { + return new SkilletMenu(pContainerId, pPlayerInventory, this); } } diff --git a/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java b/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java index 24df67a..984fe36 100644 --- a/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java +++ b/src/main/java/mczme/lingshi/common/data/builder/SkilletRecipeBuilder.java @@ -1,5 +1,6 @@ package mczme.lingshi.common.data.builder; +import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.common.recipe.SkilletRecipe; import mczme.lingshi.lingshi; import net.minecraft.advancements.Advancement; @@ -19,6 +20,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; + +import static mczme.lingshi.client.recipebook.CookingFoodRecipeLabel.MISC; public class SkilletRecipeBuilder implements RecipeBuilder { @@ -29,6 +33,7 @@ public class SkilletRecipeBuilder implements RecipeBuilder { protected final Map> criteria = new LinkedHashMap<>(); @Nullable protected String group; + protected CookingFoodRecipeLabel label; public SkilletRecipeBuilder(List items, List fluids, ItemStack result) { this.items = items; @@ -37,17 +42,22 @@ public SkilletRecipeBuilder(List items, List fluids, Ite } @Override - public RecipeBuilder unlockedBy(String pName, Criterion pCriterion) { + public SkilletRecipeBuilder unlockedBy(String pName, Criterion pCriterion) { this.criteria.put(pName, pCriterion); return this; } @Override - public RecipeBuilder group(@Nullable String pGroupName) { + public SkilletRecipeBuilder group(@Nullable String pGroupName) { this.group = pGroupName; return this; } + public SkilletRecipeBuilder setLabel(@Nullable CookingFoodRecipeLabel pLabelName) { + this.label=pLabelName; + return this; + } + @Override public Item getResult() { return this.result.getItem(); @@ -61,7 +71,7 @@ public void save(RecipeOutput pRecipeOutput, ResourceLocation pId) { .rewards(AdvancementRewards.Builder.recipe(id)) .requirements(AdvancementRequirements.Strategy.OR); this.criteria.forEach(advancement::addCriterion); - SkilletRecipe recipe = new SkilletRecipe(this.items, this.fluids, this.result); + SkilletRecipe recipe = new SkilletRecipe(this.items, this.fluids, this.result, Objects.requireNonNullElse(this.group, ""),Objects.requireNonNullElse(this.label,MISC)); pRecipeOutput.accept(id, recipe, advancement.build(id.withPrefix("recipes/"))); } } diff --git a/src/main/java/mczme/lingshi/common/data/lang/ChineseLanguageProvider.java b/src/main/java/mczme/lingshi/common/data/lang/ChineseLanguageProvider.java index ef149e6..87d4f96 100644 --- a/src/main/java/mczme/lingshi/common/data/lang/ChineseLanguageProvider.java +++ b/src/main/java/mczme/lingshi/common/data/lang/ChineseLanguageProvider.java @@ -26,5 +26,7 @@ protected void addTranslations() { this.add(ModItems.IRON_KNIFE.get(), "铁菜刀"); this.add(ModItems.SKILLET.get(), "平底锅"); + + this.add("gui.lingshi.skillet_menu","平底锅"); } } diff --git a/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java b/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java index 08226ff..520db55 100644 --- a/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java +++ b/src/main/java/mczme/lingshi/common/data/recipe/SkilletRecipeDatagen.java @@ -1,5 +1,6 @@ package mczme.lingshi.common.data.recipe; +import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.common.data.builder.SkilletRecipeBuilder; import mczme.lingshi.common.registry.ModItems; import net.minecraft.data.recipes.RecipeOutput; @@ -16,10 +17,15 @@ public SkilletRecipeDatagen(RecipeOutput output) { } protected void buildRecipes(RecipeOutput output) { - build(List.of(Ingredient.of(Items.DIAMOND),Ingredient.of(Items.IRON_BLOCK)), List.of(), new ItemStack(Items.APPLE.asItem()), output,"dd"); + build(List.of(Ingredient.of(Items.DIAMOND),Ingredient.of(Items.IRON_BLOCK)), List.of(), + new ItemStack(Items.APPLE.asItem()), output,"test00", CookingFoodRecipeLabel.PAN_FRY); + build(List.of(Ingredient.of(Items.GOLD_BLOCK),Ingredient.of(Items.IRON_BLOCK)), List.of(), + new ItemStack(Items.DIAMOND.asItem()), output,"test01",CookingFoodRecipeLabel.BOIL); + build(List.of(Ingredient.of(Items.DIAMOND_BLOCK),Ingredient.of(Items.MILK_BUCKET)), List.of(), + new ItemStack(Items.WHEAT.asItem()), output,"test02", CookingFoodRecipeLabel.HEAT); } - private void build(List items,List fluids, ItemStack result,RecipeOutput output,String pid){ - new SkilletRecipeBuilder(items, fluids, result).unlockedBy(result.toString(),Recipes.has(ModItems.SKILLET.get())).save(output,pid); + private void build(List items, List fluids, ItemStack result, RecipeOutput output, String pid, CookingFoodRecipeLabel label){ + new SkilletRecipeBuilder(items, fluids, result).setLabel(label).group("Skillet").setLabel(label).unlockedBy(result.toString(),Recipes.has(ModItems.SKILLET.get())).save(output,pid); } } diff --git a/src/main/java/mczme/lingshi/common/recipe/CookingFoodRecipe.java b/src/main/java/mczme/lingshi/common/recipe/CookingFoodRecipe.java new file mode 100644 index 0000000..d1b0da1 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/recipe/CookingFoodRecipe.java @@ -0,0 +1,21 @@ +package mczme.lingshi.common.recipe; + +import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; + +public abstract class CookingFoodRecipe { + + private final CookingFoodRecipeLabel label; + + protected CookingFoodRecipe(CookingFoodRecipeLabel label) { + this.label = label; + } + + public CookingFoodRecipeLabel getLabel(){ + return label; + } + + public String getLabelName(){ + return label.toString(); + } + +} diff --git a/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java b/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java index 7cd37d0..92adc79 100644 --- a/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java +++ b/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java @@ -1,5 +1,6 @@ package mczme.lingshi.common.recipe; +import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.common.recipe.input.SkilletRecipeInput; import mczme.lingshi.common.registry.ModRecipes; import mczme.lingshi.common.registry.ModSerializer; @@ -12,13 +13,14 @@ import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import net.neoforged.neoforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; import static net.neoforged.neoforge.common.util.RecipeMatcher.findMatches; -public class SkilletRecipe implements Recipe { +public class SkilletRecipe extends CookingFoodRecipe implements Recipe{ public static final int MAX_SLOT = 5; @@ -26,10 +28,14 @@ public class SkilletRecipe implements Recipe { private final List fluids; private final ItemStack result; - public SkilletRecipe(List items, List fluids, ItemStack result) { + final String group; + + public SkilletRecipe(List items, List fluids, ItemStack result, String group, CookingFoodRecipeLabel label) { + super(label); this.items = items; this.fluids = fluids; this.result = result; + this.group = group; } @Override @@ -89,4 +95,9 @@ public List getFluids() { public List getItems() { return items; } + + @Override + public @NotNull String getGroup() { + return this.group; + } } diff --git a/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java b/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java index df894de..05e1ae1 100644 --- a/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java +++ b/src/main/java/mczme/lingshi/common/recipe/serializer/SkilletRecipeSerializer.java @@ -1,8 +1,11 @@ package mczme.lingshi.common.recipe.serializer; +import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.common.recipe.SkilletRecipe; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; @@ -18,7 +21,9 @@ public class SkilletRecipeSerializer implements RecipeSerializer public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group( Ingredient.CODEC.listOf().fieldOf("ingredients").forGetter(SkilletRecipe::getItems), FluidStack.CODEC.listOf().fieldOf("fluids").forGetter(SkilletRecipe::getFluids), - ItemStack.CODEC.fieldOf("result").forGetter(SkilletRecipe::getResult) + ItemStack.CODEC.fieldOf("result").forGetter(SkilletRecipe::getResult), + Codec.STRING.fieldOf("group").forGetter(SkilletRecipe::getGroup), + CookingFoodRecipeLabel.CODEC.fieldOf("label").forGetter(SkilletRecipe::getLabel) ).apply(inst, SkilletRecipe::new)); public static final StreamCodec> FLUIDSTACK_STREAM_CODEC = @@ -29,12 +34,16 @@ public class SkilletRecipeSerializer implements RecipeSerializer Ingredient.CONTENTS_STREAM_CODEC.apply( ByteBufCodecs.list(SkilletRecipe.MAX_SLOT) ); + public static final StreamCodec CookingFoodLabel_STREAM_CODEC = + StreamCodec.of(SkilletRecipeSerializer::encode,SkilletRecipeSerializer::decode); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( INGREDIENT_STREAM_CODEC,SkilletRecipe::getItems, FLUIDSTACK_STREAM_CODEC,SkilletRecipe::getFluids, ItemStack.STREAM_CODEC,SkilletRecipe::getResult, + ByteBufCodecs.STRING_UTF8,SkilletRecipe::getGroup, + CookingFoodLabel_STREAM_CODEC,SkilletRecipe::getLabel, SkilletRecipe::new ); @@ -47,4 +56,14 @@ public MapCodec codec() { public StreamCodec streamCodec() { return STREAM_CODEC; } + + public static CookingFoodRecipeLabel decode(FriendlyByteBuf buffer){ + return CookingFoodRecipeLabel.isinside(buffer.readUtf()); + } + + public static void encode(FriendlyByteBuf buffer,CookingFoodRecipeLabel label){ + buffer.writeUtf(label.toString() !=null ? label.toString():""); + } + + } diff --git a/src/main/java/mczme/lingshi/common/registry/ModMenuTypes.java b/src/main/java/mczme/lingshi/common/registry/ModMenuTypes.java new file mode 100644 index 0000000..7cfd8d2 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/registry/ModMenuTypes.java @@ -0,0 +1,24 @@ +package mczme.lingshi.common.registry; + +import mczme.lingshi.client.menu.SkilletMenu; +import mczme.lingshi.lingshi; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.inventory.MenuType; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.function.Supplier; + +public class ModMenuTypes { + + public static final DeferredRegister> MENU_TYPES = DeferredRegister.create(Registries.MENU, lingshi.MODID); + + + public static final Supplier> SKILLET_MENU = MENU_TYPES.register("skillet_menu", () -> IMenuTypeExtension.create(SkilletMenu::new)); + + public static void register(IEventBus eventBus){ + MENU_TYPES.register(eventBus); + } + +} diff --git a/src/main/java/mczme/lingshi/common/registry/ModRecipes.java b/src/main/java/mczme/lingshi/common/registry/ModRecipes.java index fd9b01f..4b96384 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModRecipes.java +++ b/src/main/java/mczme/lingshi/common/registry/ModRecipes.java @@ -23,7 +23,7 @@ public class ModRecipes { public static final Supplier> SKILLET_RECIPE = RECIPE_TYPES.register( "skillet_recipe", - () -> RecipeType.simple(ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "right_click_block")) + () -> RecipeType.simple(ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "skillet_recipe")) ); public static void register(IEventBus modEventBus) { diff --git a/src/main/java/mczme/lingshi/common/registry/ModSerializer.java b/src/main/java/mczme/lingshi/common/registry/ModSerializer.java index 15dac00..9eb65c8 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModSerializer.java +++ b/src/main/java/mczme/lingshi/common/registry/ModSerializer.java @@ -17,9 +17,9 @@ public class ModSerializer { public static final DeferredRegister> RECIPE_SERIALIZERS = DeferredRegister.create(Registries.RECIPE_SERIALIZER, lingshi.MODID); public static final Supplier> CHOPPING_BOARD_SERIALIZER = - RECIPE_SERIALIZERS.register("chopping_board_serializer", ChoppingBoardRecipeSerializer::new); + RECIPE_SERIALIZERS.register("chopping_board", ChoppingBoardRecipeSerializer::new); public static final Supplier> SKILLET_SERIALIZER = - RECIPE_SERIALIZERS.register("skillet_serializer", SkilletRecipeSerializer::new); + RECIPE_SERIALIZERS.register("skillet", SkilletRecipeSerializer::new); public static void register (IEventBus modEventBus) { RECIPE_SERIALIZERS.register(modEventBus); diff --git a/src/main/java/mczme/lingshi/common/utility/ListUtility.java b/src/main/java/mczme/lingshi/common/utility/ListUtility.java new file mode 100644 index 0000000..2175e14 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/utility/ListUtility.java @@ -0,0 +1,17 @@ +package mczme.lingshi.common.utility; + +import net.minecraft.world.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class ListUtility { + + public static List copy(List list){ + List newList = new ArrayList<>(); + for (ItemStack t : list) { + newList.add(t.copy()); + } + return newList; + } +} diff --git a/src/main/java/mczme/lingshi/lingshi.java b/src/main/java/mczme/lingshi/lingshi.java index a1a2328..306828a 100644 --- a/src/main/java/mczme/lingshi/lingshi.java +++ b/src/main/java/mczme/lingshi/lingshi.java @@ -27,7 +27,7 @@ public lingshi(IEventBus modEventBus, ModContainer modContainer) BlockEntityTypes.register(modEventBus); ModRecipes.register(modEventBus); ModSerializer.register(modEventBus); - + ModMenuTypes.register(modEventBus); } diff --git a/src/main/resources/META-INF/enumExtensions.json b/src/main/resources/META-INF/enumExtensions.json new file mode 100644 index 0000000..3d689e9 --- /dev/null +++ b/src/main/resources/META-INF/enumExtensions.json @@ -0,0 +1,64 @@ +{ + "entries": [ + { + "enum": "net/minecraft/world/inventory/RecipeBookType", + "name": "lingshi_SKILLET", + "constructor": "()V", + "parameters": [] + }, + { + "enum": "net/minecraft/client/RecipeBookCategories", + "name": "lingshi_SKILLET_SEARCH", + "constructor": "(Ljava/util/function/Supplier;)V", + "parameters": { + "class": "mczme/lingshi/ModEnumParams", + "field": "SKILLET_SEARCH_ENUM_PROXY" + } + }, + { + "enum": "net/minecraft/client/RecipeBookCategories", + "name": "lingshi_SKILLET_HEAT", + "constructor": "(Ljava/util/function/Supplier;)V", + "parameters": { + "class": "mczme/lingshi/ModEnumParams", + "field": "SKILLET_HEAT_ENUM_PROXY" + } + }, + { + "enum": "net/minecraft/client/RecipeBookCategories", + "name": "lingshi_PAN_FRY", + "constructor": "(Ljava/util/function/Supplier;)V", + "parameters": { + "class": "mczme/lingshi/ModEnumParams", + "field": "PAN_FRY_ENUM_PROXY" + } + }, + { + "enum": "net/minecraft/client/RecipeBookCategories", + "name": "lingshi_STIR_FRY", + "constructor": "(Ljava/util/function/Supplier;)V", + "parameters": { + "class": "mczme/lingshi/ModEnumParams", + "field": "STIR_FRY_ENUM_PROXY" + } + }, + { + "enum": "net/minecraft/client/RecipeBookCategories", + "name": "lingshi_BOIL", + "constructor": "(Ljava/util/function/Supplier;)V", + "parameters": { + "class": "mczme/lingshi/ModEnumParams", + "field": "BOIL_ENUM_PROXY" + } + }, + { + "enum": "net/minecraft/client/RecipeBookCategories", + "name": "lingshi_MISC", + "constructor": "(Ljava/util/function/Supplier;)V", + "parameters": { + "class": "mczme/lingshi/ModEnumParams", + "field": "MISC_ENUM_PROXY" + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index 1b9f6e9..0e217a4 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -28,6 +28,10 @@ version="${mod_version}" #mandatory # A display name for the mod displayName="${mod_name}" #mandatory +## The file is relative to the output directory of the resources, or the root path inside the jar when compiled +## The 'resources' directory represents the root output directory of the resources +enumExtensions="META-INF/enumextensions.json" + # A URL to query for updates for this mod. See the JSON update specification https://docs.neoforged.net/docs/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional diff --git a/src/main/resources/assets/lingshi/textures/gui/container/skillet.png b/src/main/resources/assets/lingshi/textures/gui/container/skillet.png new file mode 100644 index 0000000..c8a6922 Binary files /dev/null and b/src/main/resources/assets/lingshi/textures/gui/container/skillet.png differ