Skip to content

Commit

Permalink
添加:烹饪锅渲染和hud
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Aug 26, 2024
1 parent 144699c commit fc3943a
Show file tree
Hide file tree
Showing 23 changed files with 324 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "lingshi:block/cooking_pot"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:baked_potato"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_beef"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_chicken"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_cod"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_mutton"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_porkchop"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_rabbit"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "minecraft:cooked_salmon"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "lingshi:fried_egg"
"items": "lingshi:skillet"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CookingPotBlockEntity> {

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();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/mczme/lingshi/client/event/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
52 changes: 41 additions & 11 deletions src/main/java/mczme/lingshi/client/screen/CookingHud.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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 <T extends ICanBeHeated> 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;
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/mczme/lingshi/client/util/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit fc3943a

Please sign in to comment.