From fc3943acff583e48a2edae7c974c928f637d3524 Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Tue, 27 Aug 2024 05:01:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=83=B9=E9=A5=AA?= =?UTF-8?q?=E9=94=85=E6=B8=B2=E6=9F=93=E5=92=8Chud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 | 3 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 20 ++-- .../lingshi/models/item/cooking_pot.json | 3 + .../recipes/skillet/baked_potato.json | 2 +- .../recipes/skillet/cooked_beef.json | 2 +- .../recipes/skillet/cooked_chicken.json | 2 +- .../recipes/skillet/cooked_cod.json | 2 +- .../recipes/skillet/cooked_mutton.json | 2 +- .../recipes/skillet/cooked_porkchop.json | 2 +- .../recipes/skillet/cooked_rabbit.json | 2 +- .../recipes/skillet/cooked_salmon.json | 2 +- .../recipes/skillet/fried_egg.json | 2 +- .../BlockEntityRenderer/CookingPotBER.java | 49 ++++++++ .../BlockEntityRenderer/SkilletBER.java | 4 +- .../mczme/lingshi/client/event/Registry.java | 4 + .../lingshi/client/screen/CookingHud.java | 52 +++++++-- .../mczme/lingshi/client/util/RenderUtil.java | 8 +- .../lingshi/common/block/CookingPotBlock.java | 61 ++++++++-- .../block/entity/CookingPotBlockEntity.java | 105 ++++++++++++++++++ .../block/entity/SkilletBlockEntity.java | 21 +++- .../entity/baseblockentity/ICanBeHeated.java | 15 +++ .../mczme/lingshi/common/item/PotLid.java | 12 ++ .../lingshi/common/registry/ModItems.java | 3 +- 23 files changed, 324 insertions(+), 54 deletions(-) create mode 100644 src/generated/resources/assets/lingshi/models/item/cooking_pot.json create mode 100644 src/main/java/mczme/lingshi/client/BlockEntityRenderer/CookingPotBER.java diff --git a/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 b/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 index 63d7859..493ec00 100644 --- a/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 +++ b/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 @@ -1,5 +1,6 @@ -// 1.21 2024-08-21T06:28:09.8764642 Item Models: lingshi +// 1.21 2024-08-27T02:55:56.0305846 Item Models: lingshi bad0cb5e093fa42331c2d4a1157d1a7b5b3fc588 assets/lingshi/models/item/chopping_board.json +8106af92df770f5e2062db0b6aaed967fe386d87 assets/lingshi/models/item/cooking_pot.json 014b17c43a62c41d623a0d944e434cf1ac3986be assets/lingshi/models/item/fried_egg.json 249957a6811e300efca306db358e468855851d73 assets/lingshi/models/item/iron_knife.json b767fc7952daf0eff3485fe4d8c06c5bba930c22 assets/lingshi/models/item/oil_bucket.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 845250f..8e4ed31 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,15 +1,15 @@ -// 1.21 2024-08-22T18:03:26.4870994 Recipes +// 1.21 2024-08-27T02:55:56.0325835 Recipes 6a319c97da924f9ab21b5d264c18cb8ad9da8755 data/lingshi/advancement/recipes/decorations/chopping_board.json 0a4b54bfda8aa98f1a26bbf1d8231c76ed12e770 data/lingshi/advancement/recipes/decorations/skillet.json -90e465ef819e2007fb2b023b2970095ecce8b79a data/lingshi/advancement/recipes/skillet/baked_potato.json -270b8d1827bb4d94559088a008f9f2b887d3cf79 data/lingshi/advancement/recipes/skillet/cooked_beef.json -3da01b8b1fa7548e7f2b7992450356eed7c3f638 data/lingshi/advancement/recipes/skillet/cooked_chicken.json -61c5eeeda0e4c82b459978a7ace05bac2ae3a724 data/lingshi/advancement/recipes/skillet/cooked_cod.json -0d382e904771b12b539540f8bfe3aba5a316288b data/lingshi/advancement/recipes/skillet/cooked_mutton.json -7dac12da1bf40c7246fff7b3f5d3ad3395ca7fee data/lingshi/advancement/recipes/skillet/cooked_porkchop.json -dd85a62c2968cd2bfa854faa7b3251ec7f3ff3a1 data/lingshi/advancement/recipes/skillet/cooked_rabbit.json -90acc516d2ea75e5ff8ab2117d4570b6f4f37137 data/lingshi/advancement/recipes/skillet/cooked_salmon.json -84acc8c3c7e0177a6a39a017a2b688d9e95c7fbb data/lingshi/advancement/recipes/skillet/fried_egg.json +e4ccb4f32d90b93ef63a3f2a17e843c6a8b2322b data/lingshi/advancement/recipes/skillet/baked_potato.json +c9b88b929d6f4b7d68c10c6a3915182cb096d363 data/lingshi/advancement/recipes/skillet/cooked_beef.json +0235c27183fa0a2f93fdf2a6726f2f9d1acc95b7 data/lingshi/advancement/recipes/skillet/cooked_chicken.json +02656e018c573dab31666c441fe9674bb62060c4 data/lingshi/advancement/recipes/skillet/cooked_cod.json +51df8caa6bb3b8352065953531aae9d75bc0c6f9 data/lingshi/advancement/recipes/skillet/cooked_mutton.json +11c0e1c5c1fee50df7de493ee95764ca109b36f3 data/lingshi/advancement/recipes/skillet/cooked_porkchop.json +938ed8fe297341fd3b755b1381bae2e276a00eb3 data/lingshi/advancement/recipes/skillet/cooked_rabbit.json +de37dcaf7e9f79459492cd69ddb81d8d27406f99 data/lingshi/advancement/recipes/skillet/cooked_salmon.json +ee50d7e3c59e644ce93e46945ff090c3c68fda04 data/lingshi/advancement/recipes/skillet/fried_egg.json 0e940fa2ba82aed478ee367c4b998f0bc7ead5c3 data/lingshi/advancement/recipes/tools/iron_knife.json e511f76246f906a279fc1ec531922d8f70dfb68c data/lingshi/advancement/recipes/tools/spatula.json bec1047337843fdd073fe87393c3b500ae11a1de data/lingshi/recipe/chopping_board.json diff --git a/src/generated/resources/assets/lingshi/models/item/cooking_pot.json b/src/generated/resources/assets/lingshi/models/item/cooking_pot.json new file mode 100644 index 0000000..2db5e21 --- /dev/null +++ b/src/generated/resources/assets/lingshi/models/item/cooking_pot.json @@ -0,0 +1,3 @@ +{ + "parent": "lingshi:block/cooking_pot" +} \ No newline at end of file diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/baked_potato.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/baked_potato.json index 9fe0b5c..b7c2976 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/baked_potato.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/baked_potato.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:baked_potato" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_beef.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_beef.json index 2fb7faa..329cf6c 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_beef.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_beef.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_beef" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_chicken.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_chicken.json index d57a8da..f7e06af 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_chicken.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_chicken.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_chicken" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_cod.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_cod.json index 49bc207..05f6eec 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_cod.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_cod.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_cod" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_mutton.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_mutton.json index 30be9dc..7180670 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_mutton.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_mutton.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_mutton" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_porkchop.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_porkchop.json index 7ea5203..05d60d6 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_porkchop.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_porkchop.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_porkchop" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_rabbit.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_rabbit.json index 1bb807d..c6af6fa 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_rabbit.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_rabbit.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_rabbit" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_salmon.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_salmon.json index 65a72df..436718f 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_salmon.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/cooked_salmon.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "minecraft:cooked_salmon" + "items": "lingshi:skillet" } ] }, diff --git a/src/generated/resources/data/lingshi/advancement/recipes/skillet/fried_egg.json b/src/generated/resources/data/lingshi/advancement/recipes/skillet/fried_egg.json index 9d95653..9a51172 100644 --- a/src/generated/resources/data/lingshi/advancement/recipes/skillet/fried_egg.json +++ b/src/generated/resources/data/lingshi/advancement/recipes/skillet/fried_egg.json @@ -5,7 +5,7 @@ "conditions": { "items": [ { - "items": "lingshi:fried_egg" + "items": "lingshi:skillet" } ] }, diff --git a/src/main/java/mczme/lingshi/client/BlockEntityRenderer/CookingPotBER.java b/src/main/java/mczme/lingshi/client/BlockEntityRenderer/CookingPotBER.java new file mode 100644 index 0000000..ca5f3c4 --- /dev/null +++ b/src/main/java/mczme/lingshi/client/BlockEntityRenderer/CookingPotBER.java @@ -0,0 +1,49 @@ +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.CookingPotBlockEntity; +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.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.items.ItemStackHandler; + +import static mczme.lingshi.client.util.RenderUtil.fluidRender; +import static mczme.lingshi.common.block.CookingPotBlock.COVER; + +public class CookingPotBER implements BlockEntityRenderer { + + public CookingPotBER(BlockEntityRendererProvider.Context pContext) { + + } + + @Override + public void render(CookingPotBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) { + if(!pBlockEntity.getBlockState().getValue(COVER)){ + ItemStackHandler itemStack = pBlockEntity.getItemStacks(); + FluidStack fluidStack = pBlockEntity.getFluid(); + Direction direction = pBlockEntity.getBlockState().getValue(ChoppingBoardBlock.FACING); + + if (!pBlockEntity.isEmpty()) { + if (!fluidStack.isEmpty()) { + fluidRender(fluidStack.getFluid(), pPoseStack, pBufferSource, pBlockEntity.getLevel(), pBlockEntity.getBlockPos(), pPackedLight, new float[]{10F/16.0F,16/16.0F,10F/16.0F,5F/16.0F,5F/16.0F,11F}); + } + + for (int i = 0; i < pBlockEntity.getMAX(); i++) { + if (itemStack.getStackInSlot(i).isEmpty()) continue; + pPoseStack.pushPose(); + pPoseStack.translate(0.5, 0.2 + i / 16.0, 0.5); + pPoseStack.mulPose(Axis.YP.rotationDegrees(-direction.toYRot())); + pPoseStack.scale(0.5F, 0.5F, 0.5F); + Minecraft.getInstance().getItemRenderer().renderStatic(itemStack.getStackInSlot(i), ItemDisplayContext.FIXED, pPackedLight, pPackedOverlay, pPoseStack, pBufferSource, pBlockEntity.getLevel(), (int) pBlockEntity.getBlockPos().asLong()); + pPoseStack.popPose(); + } + } + } + } +} diff --git a/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java b/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java index 35aa36d..3d0e673 100644 --- a/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java +++ b/src/main/java/mczme/lingshi/client/BlockEntityRenderer/SkilletBER.java @@ -40,9 +40,9 @@ public void render(SkilletBlockEntity pBlockEntity, float pPartialTick, PoseStac if (!pBlockEntity.isEmpty()) { if (!fluidStack.isEmpty()) { if(fluidStack.getFluid().isSame(Fluids.WATER)){ - fluidRender(fluidStack.getFluid(), pPoseStack, pBufferSource, pBlockEntity.getLevel(), pBlockEntity.getBlockPos(), pPackedLight, 2.5f); + fluidRender(fluidStack.getFluid(), pPoseStack, pBufferSource, pBlockEntity.getLevel(), pBlockEntity.getBlockPos(), pPackedLight, new float[]{13/16.0F,13/16.0F,13/16.0F,2/16.0F,2/16.0F,2.5F}); }else { - fluidRender(fluidStack.getFluid(), pPoseStack, pBufferSource, pBlockEntity.getLevel(), pBlockEntity.getBlockPos(), pPackedLight, 1.5f); + fluidRender(fluidStack.getFluid(), pPoseStack, pBufferSource, pBlockEntity.getLevel(), pBlockEntity.getBlockPos(), pPackedLight, new float[]{13/16.0F,13/16.0F,13/16.0F,2/16.0F,2/16F,1.5F}); } } diff --git a/src/main/java/mczme/lingshi/client/event/Registry.java b/src/main/java/mczme/lingshi/client/event/Registry.java index 9cec3f1..7807044 100644 --- a/src/main/java/mczme/lingshi/client/event/Registry.java +++ b/src/main/java/mczme/lingshi/client/event/Registry.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.shaders.FogShape; import com.mojang.blaze3d.systems.RenderSystem; import mczme.lingshi.client.BlockEntityRenderer.ChoppingBoardBER; +import mczme.lingshi.client.BlockEntityRenderer.CookingPotBER; import mczme.lingshi.client.BlockEntityRenderer.SkilletBER; import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.client.screen.CookingHud; @@ -40,10 +41,13 @@ @EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class Registry { + +// block render @SubscribeEvent public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { event.registerBlockEntityRenderer(BlockEntityTypes.CHOPPING_BOARD_BLOCKENTITY.get(), ChoppingBoardBER::new); event.registerBlockEntityRenderer(BlockEntityTypes.SKILLET_BLOCKENTITY.get(), SkilletBER::new); + event.registerBlockEntityRenderer(BlockEntityTypes.COOKING_POT_BLOCKENTITY.get(), CookingPotBER::new); } // menu screen diff --git a/src/main/java/mczme/lingshi/client/screen/CookingHud.java b/src/main/java/mczme/lingshi/client/screen/CookingHud.java index be803c3..3ba1b49 100644 --- a/src/main/java/mczme/lingshi/client/screen/CookingHud.java +++ b/src/main/java/mczme/lingshi/client/screen/CookingHud.java @@ -1,6 +1,8 @@ package mczme.lingshi.client.screen; +import mczme.lingshi.common.block.entity.CookingPotBlockEntity; import mczme.lingshi.common.block.entity.SkilletBlockEntity; +import mczme.lingshi.common.block.entity.baseblockentity.ICanBeHeated; import mczme.lingshi.common.datamap.DataMapTypes; import mczme.lingshi.common.datamap.ingredient.CookingFoodData; import mczme.lingshi.common.registry.BlockEntityTypes; @@ -30,7 +32,7 @@ public class CookingHud implements LayeredDraw.Layer { private ItemStackHandler itemStackHandler; private FluidStack fluidStack = FluidStack.EMPTY; private ItemStack container = ItemStack.EMPTY; - private int stirFryCount; + private int Count; private int[] cookingTime; private ItemStack result = ItemStack.EMPTY; private int MAX_SLOT; @@ -47,12 +49,40 @@ public void render(@NotNull GuiGraphics pGuiGraphics, @NotNull DeltaTracker pDel } this.player = Minecraft.getInstance().player; if (player != null && getHitResult(BlockEntityTypes.SKILLET_BLOCKENTITY.get())) { - getData(); + getData((SkilletBlockEntity)Minecraft.getInstance().level.getBlockEntity(blockPos)); int j = 0; if (!result.isEmpty()) { pGuiGraphics.renderItem(result, X - 18, Y); pGuiGraphics.blit(HUD_Sprite, X, Y , 16, 16, 0, 36,16,16, 64, 64); - pGuiGraphics.drawCenteredString(Minecraft.getInstance().font, String.valueOf(stirFryCount), X + 24, Y + 6, 0xffffff); + pGuiGraphics.drawCenteredString(Minecraft.getInstance().font, String.valueOf(Count), X + 24, Y + 6, 0xffffff); + if (!container.isEmpty()) { + pGuiGraphics.renderItem(container, X + 36, Y); + } + j++; + } + if (!fluidStack.isEmpty()) { + CookingFoodData cookingFoodData = fluidStack.getFluidHolder().getData(DataMapTypes.COOKING_FOOD_FLUID); + if (cookingFoodData != null) { + drawFluidProgress(pGuiGraphics, cookingFoodData, j); + } + j++; + } + for (int i = 0; i < MAX_SLOT; i++) { + if (!itemStackHandler.getStackInSlot(i).isEmpty()) { + pGuiGraphics.renderItem(itemStackHandler.getStackInSlot(i), X - 18, Y + (i + j) * 18); + CookingFoodData cookingFoodData = itemStackHandler.getStackInSlot(i).getItemHolder().getData(DataMapTypes.COOKING_FOOD_ITEM); + if (cookingFoodData != null) { + drawItemProgress(pGuiGraphics, cookingFoodData, i, j); + } + } + } + } else if (player != null && getHitResult(BlockEntityTypes.COOKING_POT_BLOCKENTITY.get())) { + getData((CookingPotBlockEntity)Minecraft.getInstance().level.getBlockEntity(blockPos)); + int j = 0; + if (!result.isEmpty()) { + pGuiGraphics.renderItem(result, X - 18, Y); +// pGuiGraphics.blit(HUD_Sprite, X, Y , 16, 16, 0, 36,16,16, 64, 64); + pGuiGraphics.drawCenteredString(Minecraft.getInstance().font, String.valueOf(Count), X + 24, Y + 6, 0xffffff); if (!container.isEmpty()) { pGuiGraphics.renderItem(container, X + 36, Y); } @@ -77,19 +107,19 @@ public void render(@NotNull GuiGraphics pGuiGraphics, @NotNull DeltaTracker pDel } } - private void getData() { - SkilletBlockEntity blockEntity = null; - if (Minecraft.getInstance().level != null) { - blockEntity = (SkilletBlockEntity) Minecraft.getInstance().level.getBlockEntity(blockPos); - } + private void getData(T blockEntity) { if (blockEntity != null) { this.itemStackHandler = blockEntity.getItemStacks(); this.fluidStack = blockEntity.getFluid(); this.cookingTime = blockEntity.getCookingTime(); this.MAX_SLOT = blockEntity.getMAX(); - this.result = blockEntity.result; - this.container = blockEntity.container; - this.stirFryCount = blockEntity.stirFryCount; + this.result = blockEntity.getResult(); + this.container = blockEntity.getContainer(); + if(blockEntity instanceof SkilletBlockEntity blockEntity1){ + this.Count = blockEntity1.stirFryCount; + }else if (blockEntity instanceof CookingPotBlockEntity blockEntity1){ + this.Count = blockEntity1.stewingTime; + } } } diff --git a/src/main/java/mczme/lingshi/client/util/RenderUtil.java b/src/main/java/mczme/lingshi/client/util/RenderUtil.java index e350c80..d867af8 100644 --- a/src/main/java/mczme/lingshi/client/util/RenderUtil.java +++ b/src/main/java/mczme/lingshi/client/util/RenderUtil.java @@ -15,17 +15,17 @@ public class RenderUtil { - public static void fluidRender(Fluid fluid, PoseStack pPoseStack, MultiBufferSource pBufferSource, Level pLevel, BlockPos pPos,int pPackedLight,float height){ + public static void fluidRender(Fluid fluid, PoseStack pPoseStack, MultiBufferSource pBufferSource, Level pLevel, BlockPos pPos,int pPackedLight,float[] size){ pPoseStack.pushPose(); - pPoseStack.scale(13/16F, 13/16F, 13/16F); - pPoseStack.translate(2/16F, 0F, 2/16F); + pPoseStack.scale(size[0], size[1], size[2]); + pPoseStack.translate(size[3], 0F, size[4]); TextureAtlasSprite[] atextureatlassprite = net.neoforged.neoforge.client.textures.FluidSpriteCache.getFluidSprites(pLevel, pPos, fluid.defaultFluidState()); TextureAtlasSprite still = atextureatlassprite[0]; int colour = fluid.isSame(Fluids.WATER)?BiomeColors.getAverageWaterColor(pLevel, pPos) : 0xA1EAD909; float red = (float) FastColor.ARGB32.red(colour) / 255.0F; float green = (float) FastColor.ARGB32.green(colour) / 255.0F; float blue = (float) FastColor.ARGB32.blue(colour) / 255.0F; - float offset = height /16; + float offset = size[5] /16; float uScale = still.getU1() - still.getU0(); float vScale = still.getV1() - still.getV0(); float u0 = still.getU0() + uScale * (float)0; diff --git a/src/main/java/mczme/lingshi/common/block/CookingPotBlock.java b/src/main/java/mczme/lingshi/common/block/CookingPotBlock.java index d5c3c36..cf5abb8 100644 --- a/src/main/java/mczme/lingshi/common/block/CookingPotBlock.java +++ b/src/main/java/mczme/lingshi/common/block/CookingPotBlock.java @@ -2,6 +2,7 @@ import com.mojang.serialization.MapCodec; import mczme.lingshi.common.block.entity.CookingPotBlockEntity; +import mczme.lingshi.common.registry.ModFluids; import mczme.lingshi.common.registry.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -11,6 +12,7 @@ import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -21,14 +23,18 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import net.neoforged.neoforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; @@ -36,7 +42,7 @@ public class CookingPotBlock extends BaseEntityBlock { public static final BooleanProperty COVER = BooleanProperty.create("cover"); public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; - public static final VoxelShape SHAPE = Block.box(3,0,3,13,12,13); + public static final VoxelShape SHAPE = Block.box(3, 0, 3, 13, 12, 13); public CookingPotBlock(Properties pProperties) { super(pProperties); @@ -44,9 +50,32 @@ public CookingPotBlock(Properties pProperties) { } public ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHitResult) { - if (pLevel.getBlockEntity(pPos) instanceof CookingPotBlockEntity blockEntity){ - if(pStack.is(ModItems.POT_LID.get())&& !pState.getValue(COVER)){ - pLevel.setBlockAndUpdate(pPos, pState.setValue(COVER, true)); + if (pLevel.getBlockEntity(pPos) instanceof CookingPotBlockEntity blockEntity) { + if (!blockEntity.container.isEmpty() && pStack.is(blockEntity.container.getItem())) { + if (pPlayer.addItem(blockEntity.result)) { + pStack.consume(1, pPlayer); + blockEntity.clear(); + blockEntity.setChanged(); + return ItemInteractionResult.SUCCESS; + } + } else if (!blockEntity.isFull() && !pStack.isEmpty() && !pStack.is(ModItems.POT_LID.get()) && !pState.getValue(COVER)) { + if (pStack.is(Items.WATER_BUCKET)) { + blockEntity.setFluid(new FluidStack(Fluids.WATER, 1000)); + blockEntity.getCookingTime()[5] = 0; + blockEntity.setChanged(); + return ItemInteractionResult.SUCCESS; + } else if (pStack.is(ModItems.OIL_BUCKET.get())) { + blockEntity.setFluid(new FluidStack(ModFluids.OIL_SOURCE.get(), 1000)); + blockEntity.getCookingTime()[5] = 0; + blockEntity.setChanged(); + return ItemInteractionResult.SUCCESS; + } + if(pStack.getCount()<=16) { + blockEntity.setItem(pStack.consumeAndReturn(pStack.getCount(), pPlayer)); + }else { + blockEntity.setItem(pStack.consumeAndReturn(16, pPlayer)); + } + blockEntity.setChanged(); return ItemInteractionResult.SUCCESS; } return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; @@ -57,18 +86,22 @@ public ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Leve @Override protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) { - if (pLevel.getBlockEntity(pPos) instanceof CookingPotBlockEntity blockEntity){ - if (pState.getValue(COVER)){ + if (pLevel.getBlockEntity(pPos) instanceof CookingPotBlockEntity blockEntity) { + if (pState.getValue(COVER)) { pLevel.setBlockAndUpdate(pPos, pState.setValue(COVER, false)); - Containers.dropItemStack(pLevel,pPos.getX(), pPos.getY()+0.7, pPos.getZ(), new ItemStack(ModItems.POT_LID.get())); + Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY() + 0.7, pPos.getZ(), new ItemStack(ModItems.POT_LID.get())); return InteractionResult.SUCCESS; } else if (pPlayer.isShiftKeyDown()) { - pPlayer.openMenu(blockEntity,pPos); + pPlayer.openMenu(blockEntity, pPos); + return InteractionResult.sidedSuccess(pLevel.isClientSide); + } else if (!blockEntity.isEmpty()) { + Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY() + 0.2, pPos.getZ(), blockEntity.dropItem()); + blockEntity.setChanged(); + return InteractionResult.SUCCESS; } - + return InteractionResult.PASS; } - - return InteractionResult.sidedSuccess(pLevel.isClientSide); + return InteractionResult.PASS; } @Override @@ -115,4 +148,10 @@ protected void createBlockStateDefinition(StateDefinition.Builder BlockEntityTicker getTicker(Level pLevel, BlockState pState, BlockEntityType pType) { + return !pLevel.isClientSide ? CookingPotBlockEntity::serverTick : null; + } + } diff --git a/src/main/java/mczme/lingshi/common/block/entity/CookingPotBlockEntity.java b/src/main/java/mczme/lingshi/common/block/entity/CookingPotBlockEntity.java index 4aa52e5..fae135f 100644 --- a/src/main/java/mczme/lingshi/common/block/entity/CookingPotBlockEntity.java +++ b/src/main/java/mczme/lingshi/common/block/entity/CookingPotBlockEntity.java @@ -3,7 +3,13 @@ import mczme.lingshi.client.menu.Slot.CookingItemStackHandler; import mczme.lingshi.client.menu.CookingPotMenu; import mczme.lingshi.common.block.entity.baseblockentity.ICanBeHeated; +import mczme.lingshi.common.datamap.DataMapTypes; +import mczme.lingshi.common.datamap.ingredient.CookingFoodData; +import mczme.lingshi.common.recipe.SkilletRecipe; +import mczme.lingshi.common.recipe.input.CookingFoodRecipeInput; import mczme.lingshi.common.registry.BlockEntityTypes; +import mczme.lingshi.common.registry.ModItems; +import mczme.lingshi.common.registry.ModRecipes; import mczme.lingshi.lingshi; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; @@ -19,12 +25,17 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.items.ItemStackHandler; import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.Optional; public class CookingPotBlockEntity extends BlockEntity implements ICanBeHeated, MenuProvider { @@ -36,6 +47,7 @@ public class CookingPotBlockEntity extends BlockEntity implements ICanBeHeated, private final int[] cookingTime = new int[MAX_SLOT + 1]; public ItemStack container = ItemStack.EMPTY; public ItemStack result = ItemStack.EMPTY; + public int stewingTime = 0; public CookingPotBlockEntity(BlockPos pPos, BlockState pBlockState) { super(BlockEntityTypes.COOKING_POT_BLOCKENTITY.get(), pPos, pBlockState); @@ -70,10 +82,12 @@ public ItemStack dropItem() { return ItemStack.EMPTY; } + @Override public FluidStack getFluid() { return fluidStacks; } + @Override public CookingItemStackHandler getItemStacks() { return itemStackHandler; } @@ -118,10 +132,22 @@ public void clearTime() { Arrays.fill(cookingTime, 0); } + @Override public int[] getCookingTime() { return cookingTime; } + @Override + public ItemStack getResult(){ + return result; + } + + @Override + public ItemStack getContainer(){ + return container; + } + + @Override public int getMAX() { return MAX_SLOT; } @@ -214,4 +240,83 @@ public Component getDisplayName() { public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new CookingPotMenu(pContainerId, pPlayerInventory, this); } + + public static void serverTick(Level pLevel, BlockPos pPos, BlockState blockState, T t) { + CookingPotBlockEntity blockEntity = (CookingPotBlockEntity) t; + boolean flag = blockEntity.isEmpty(); + boolean heat_flag = blockEntity.isHeated(pLevel, pPos); + int MAX_SLOT = blockEntity.getMAX(); + ItemStackHandler itemStackHandler = blockEntity.getItemStacks(); + blockEntity.container = ItemStack.EMPTY; + if (heat_flag) { + if (!flag) { + int cookedTime = 0, burntTime = 0; + int cooked_size = 0, burnt_size = 0; + boolean fluid_heated= blockEntity.getFluid().isEmpty(); +// cookProgress + for (int i = 0; i < MAX_SLOT + 1; i++) { +// fluid + if (i == MAX_SLOT) { + if (!blockEntity.getFluid().isEmpty()) { + CookingFoodData cookingFoodData = blockEntity.getFluid().getFluidHolder().getData(DataMapTypes.COOKING_FOOD_FLUID); + if (cookingFoodData != null) { + cookedTime = cookingFoodData.cookedTime(); + blockEntity.cookingTime[i]++; + } + } else { + blockEntity.cookingTime[i] = 0; + } + if (blockEntity.cookingTime[i] > cookedTime * 20) { + fluid_heated = true; + } + continue; + } +// item + ItemStack itemStack = itemStackHandler.getStackInSlot(i); + if (itemStack.isEmpty()) { + blockEntity.cookingTime[i] = 0; + continue; + } + CookingFoodData cookingFoodData = itemStack.getItemHolder().getData(DataMapTypes.COOKING_FOOD_ITEM); + if (cookingFoodData != null) { + cookedTime = cookingFoodData.cookedTime(); + burntTime = cookingFoodData.burntTime(); + blockEntity.cookingTime[i]++; + } + if (blockEntity.cookingTime[i] > burntTime * 20) { + burnt_size++; + } else if (blockEntity.cookingTime[i] > cookedTime * 20) { + cooked_size++; + } + } +// 获取配方 + CookingFoodRecipeInput input = new CookingFoodRecipeInput(itemStackHandler, blockEntity.getFluid()); + Optional> optional = pLevel.getRecipeManager().getRecipeFor( + ModRecipes.SKILLET_RECIPE.get(), + input, + pLevel + ); + blockEntity.result = optional.map(RecipeHolder::value) + .map(e -> e.assemble(input, pLevel.registryAccess())) + .orElse(ItemStack.EMPTY); + if (cooked_size == blockEntity.size() && !blockEntity.result.isEmpty() && fluid_heated) { + blockEntity.container = optional.map(RecipeHolder::value) + .map(e -> e.getContainer().container()) + .orElse(ItemStack.EMPTY); + if(blockEntity.container.isEmpty()){ + blockEntity.container=new ItemStack(ModItems.SPATULA.get()); + } + } else if (burnt_size > 0) { + blockEntity.result = new ItemStack(ModItems.STRANGE_FOOD.get()); + blockEntity.container=new ItemStack(ModItems.SPATULA.get()); + } + } else { + blockEntity.clearTime(); + blockEntity.result = ItemStack.EMPTY; + } + pLevel.sendBlockUpdated(pPos, blockState, blockState, Block.UPDATE_CLIENTS); + blockEntity.setChanged(); + } + } + } 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 76d5474..b15c7df 100644 --- a/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java +++ b/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java @@ -32,6 +32,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.items.ItemStackHandler; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -137,6 +138,16 @@ public int[] getCookingTime() { return cookingTime; } + @Override + public ItemStack getResult() { + return result; + } + + @Override + public ItemStack getContainer() { + return container; + } + public int getMAX() { return MAX_SLOT; } @@ -147,7 +158,7 @@ public Packet getUpdatePacket() { } @Override - public CompoundTag getUpdateTag(HolderLookup.Provider pRegistries) { + public @NotNull CompoundTag getUpdateTag(HolderLookup.@NotNull Provider pRegistries) { CompoundTag tag = new CompoundTag(); tag.put("items", itemStackHandler.serializeNBT(pRegistries)); if (!fluidStacks.isEmpty()) { @@ -165,7 +176,7 @@ public CompoundTag getUpdateTag(HolderLookup.Provider pRegistries) { } @Override - protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { + protected void loadAdditional(CompoundTag pTag, HolderLookup.@NotNull Provider pRegistries) { itemStackHandler.deserializeNBT(pRegistries, pTag.getCompound("items")); if (pTag.get("fluid") != null) { fluidStacks = FluidStack.parse(pRegistries, pTag.getCompound("fluid")).orElse(FluidStack.EMPTY); @@ -189,7 +200,7 @@ protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistrie } @Override - protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { + protected void saveAdditional(@NotNull CompoundTag pTag, HolderLookup.@NotNull Provider pRegistries) { super.saveAdditional(pTag, pRegistries); pTag.put("items", itemStackHandler.serializeNBT(pRegistries)); if (!this.fluidStacks.isEmpty()) { @@ -223,13 +234,13 @@ private void loadCookingTime(ListTag pTag, int size) { } @Override - public Component getDisplayName() { + public @NotNull Component getDisplayName() { return Component.translatable("gui." + lingshi.MODID + ".skillet_menu"); } @Nullable @Override - public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { + public AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pPlayerInventory, @NotNull Player pPlayer) { return new SkilletMenu(pContainerId, pPlayerInventory, this); } diff --git a/src/main/java/mczme/lingshi/common/block/entity/baseblockentity/ICanBeHeated.java b/src/main/java/mczme/lingshi/common/block/entity/baseblockentity/ICanBeHeated.java index 460f2ef..280a284 100644 --- a/src/main/java/mczme/lingshi/common/block/entity/baseblockentity/ICanBeHeated.java +++ b/src/main/java/mczme/lingshi/common/block/entity/baseblockentity/ICanBeHeated.java @@ -1,11 +1,26 @@ package mczme.lingshi.common.block.entity.baseblockentity; +import mczme.lingshi.client.menu.Slot.CookingItemStackHandler; import mczme.lingshi.common.tag.ModTags; import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.neoforged.neoforge.fluids.FluidStack; public interface ICanBeHeated { + FluidStack getFluid(); + + CookingItemStackHandler getItemStacks(); + + int[] getCookingTime(); + + ItemStack getResult(); + + ItemStack getContainer(); + + int getMAX(); + default boolean isHeated(Level pLevel, BlockPos pPos){ return pLevel.getBlockState(pPos.below()).is(ModTags.HEAT_SOURCE); } diff --git a/src/main/java/mczme/lingshi/common/item/PotLid.java b/src/main/java/mczme/lingshi/common/item/PotLid.java index 7959183..3364ef1 100644 --- a/src/main/java/mczme/lingshi/common/item/PotLid.java +++ b/src/main/java/mczme/lingshi/common/item/PotLid.java @@ -1,10 +1,22 @@ package mczme.lingshi.common.item; +import net.minecraft.world.InteractionResult; import net.minecraft.world.item.Item; +import net.minecraft.world.item.context.UseOnContext; + +import static mczme.lingshi.common.block.CookingPotBlock.COVER; public class PotLid extends Item { public PotLid(Properties properties) { super(properties); } + @Override + public InteractionResult useOn(UseOnContext pContext) { + if(!pContext.getLevel().getBlockState(pContext.getClickedPos()).getValue(COVER)) { + pContext.getLevel().setBlockAndUpdate(pContext.getClickedPos(), pContext.getLevel().getBlockState(pContext.getClickedPos()).setValue(COVER, true)); + } + return InteractionResult.SUCCESS; + } + } diff --git a/src/main/java/mczme/lingshi/common/registry/ModItems.java b/src/main/java/mczme/lingshi/common/registry/ModItems.java index 148c3b1..7c0dd84 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModItems.java +++ b/src/main/java/mczme/lingshi/common/registry/ModItems.java @@ -1,6 +1,7 @@ package mczme.lingshi.common.registry; import mczme.lingshi.common.item.KnifeItem; +import mczme.lingshi.common.item.PotLid; import mczme.lingshi.common.item.SpatulaItem; import mczme.lingshi.lingshi; import net.minecraft.world.food.FoodProperties; @@ -27,7 +28,7 @@ public class ModItems { public static final Supplier COOKING_POT = registerWithCreateTab("cooking_pot", () -> new BlockItem(ModBlocks.COOKING_POT.get(), new Item.Properties())); public static final Supplier CHOPPING_BOARD = registerWithCreateTab("chopping_board", () -> new BlockItem(ModBlocks.CHOPPING_BOARD.get(), new Item.Properties())); - public static final Supplier POT_LID = registerWithCreateTab("pot_lid", () -> new Item( new Item.Properties())); + public static final Supplier POT_LID = registerWithCreateTab("pot_lid", () -> new PotLid(new Item.Properties())); public static final Supplier SPATULA = registerWithCreateTab("spatula", () -> new SpatulaItem(new Item.Properties())); public static final Supplier IRON_KNIFE = registerWithCreateTab("iron_knife", () -> new KnifeItem(Tiers.IRON, new Item.Properties().attributes(SwordItem.createAttributes(Tiers.IRON, 3, -2.4F))));