diff --git a/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 b/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 index 52e978a..f8814ce 100644 --- a/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 +++ b/src/generated/resources/.cache/71e72dbdeb626cc835aaccd2ae47fd3d8794cd24 @@ -1,4 +1,4 @@ -// 1.21 2024-09-06T10:03:20.9822913 Item Models: lingshi +// 1.21 2024-09-09T22:04:36.2459739 Item Models: lingshi 14f86299910462582d98bcf699b35e34c615ee8e assets/lingshi/models/item/cabbage.json 0e18f939d46f6a164584f621fa97b024122785d9 assets/lingshi/models/item/cabbage_leaf.json 0bcbbc8c3377f7b20a37790cc33d36690c2044c7 assets/lingshi/models/item/cabbage_seed.json @@ -10,6 +10,7 @@ a2eecf0a3a6c93ab1c418b7953b4080059274277 assets/lingshi/models/item/egg_added_st 37db2e9897cd20f19d58456cafcb898f113c1d4b assets/lingshi/models/item/egg_fried_rice.json 3492c131525851e1fa451f33349d2686d2ff1fc0 assets/lingshi/models/item/flour.json 014b17c43a62c41d623a0d944e434cf1ac3986be assets/lingshi/models/item/fried_egg.json +bb65673aded0d1674c4329547af6263f100a1e6b assets/lingshi/models/item/glass_jar.json 249957a6811e300efca306db358e468855851d73 assets/lingshi/models/item/iron_knife.json 8889a4deb394774a900a518a3d4849db21da3370 assets/lingshi/models/item/noodles.json b767fc7952daf0eff3485fe4d8c06c5bba930c22 assets/lingshi/models/item/oil_bucket.json diff --git a/src/generated/resources/assets/lingshi/models/item/glass_jar.json b/src/generated/resources/assets/lingshi/models/item/glass_jar.json new file mode 100644 index 0000000..b1abf06 --- /dev/null +++ b/src/generated/resources/assets/lingshi/models/item/glass_jar.json @@ -0,0 +1,3 @@ +{ + "parent": "lingshi:block/glass_jar" +} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/client/ItemRender/lingshiBEWLR.java b/src/main/java/mczme/lingshi/client/ItemRender/lingshiBEWLR.java index c8ee944..18686be 100644 --- a/src/main/java/mczme/lingshi/client/ItemRender/lingshiBEWLR.java +++ b/src/main/java/mczme/lingshi/client/ItemRender/lingshiBEWLR.java @@ -1,10 +1,20 @@ package mczme.lingshi.client.ItemRender; import com.mojang.blaze3d.vertex.PoseStack; +import mczme.lingshi.common.registry.ModItems; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.CustomData; +import net.neoforged.neoforge.fluids.FluidStack; + +import static mczme.lingshi.client.util.RenderUtil.fluidRender; public class lingshiBEWLR extends BlockEntityWithoutLevelRenderer { public lingshiBEWLR() { @@ -13,6 +23,29 @@ public lingshiBEWLR() { @Override public void renderByItem(ItemStack pStack, ItemDisplayContext pDisplayContext, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay) { + if(pStack.is(ModItems.GLASS_JAR.get())){ + renderGlassJar(pStack,pPoseStack,pBuffer,pPackedLight,pPackedOverlay); + } + } + + private void renderGlassJar(ItemStack pStack,PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay){ + BlockRenderDispatcher blockRenderer = Minecraft.getInstance().getBlockRenderer(); + pPoseStack.pushPose(); + if(pStack.get(DataComponents.BLOCK_ENTITY_DATA)!=null){ + CustomData customData = pStack.get(DataComponents.BLOCK_ENTITY_DATA); + FluidStack fluidStack = FluidStack.EMPTY; + if(customData.copyTag().getCompound("fluidStack")!=null){ + CompoundTag compoundTag = customData.copyTag().getCompound("fluidStack"); + fluidStack = FluidStack.parse(Minecraft.getInstance().level.registryAccess(), compoundTag).orElse(FluidStack.EMPTY); + } + if(!fluidStack.isEmpty()) { + fluidRender(fluidStack,5.1F,1,5.1F,5.8F,10,5.8F,1000,pPoseStack,pBuffer,pPackedLight); + } + blockRenderer.renderSingleBlock(((BlockItem)pStack.getItem()).getBlock().defaultBlockState(), pPoseStack, pBuffer, pPackedLight, pPackedOverlay); + }else { + blockRenderer.renderSingleBlock(((BlockItem)pStack.getItem()).getBlock().defaultBlockState(), pPoseStack, pBuffer, pPackedLight, pPackedOverlay); + } + pPoseStack.popPose(); } diff --git a/src/main/java/mczme/lingshi/client/event/Registry.java b/src/main/java/mczme/lingshi/client/event/Registry.java index ef09133..b43ef85 100644 --- a/src/main/java/mczme/lingshi/client/event/Registry.java +++ b/src/main/java/mczme/lingshi/client/event/Registry.java @@ -8,6 +8,7 @@ import mczme.lingshi.client.BlockEntityRenderer.GlassJarBER; import mczme.lingshi.client.BlockEntityRenderer.SkilletBER; import mczme.lingshi.client.ItemRender.lingshiBEWLR; +import mczme.lingshi.client.model.GlassJarBakeModel; import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.client.screen.CookingHud; import mczme.lingshi.client.screen.CookingPotScreen; @@ -22,21 +23,23 @@ import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; -import net.neoforged.neoforge.client.event.EntityRenderersEvent; -import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent; -import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; -import net.neoforged.neoforge.client.event.RegisterRecipeBookCategoriesEvent; +import net.neoforged.neoforge.client.event.*; import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent; import org.jetbrains.annotations.NotNull; import org.joml.Vector3f; +import java.util.Map; + import static mczme.lingshi.client.recipebook.ModRecipeBookCategories.*; import static mczme.lingshi.client.recipebook.ModRecipeBookType.COOKING_POT; import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET; @@ -44,7 +47,7 @@ @EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class Registry { -// block render + // block render @SubscribeEvent public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { event.registerBlockEntityRenderer(BlockEntityTypes.CHOPPING_BOARD_BLOCK_ENTITY.get(), ChoppingBoardBER::new); @@ -109,7 +112,7 @@ public static void onClientEvent(FMLClientSetupEvent event) { } -// Render + // Render @SubscribeEvent public static void registerClientExtensionsEvent(RegisterClientExtensionsEvent event) { // fluid @@ -140,6 +143,7 @@ public int getTintColor() { int renderDistance, float darkenWorldAmount, Vector3f fluidFogColor) { return new Vector3f(234f / 255f, 217f / 255f, 9f / 255f); } + // 液体中的能见度 或者 说雾的范围 @Override public void modifyFogRender(Camera camera, FogRenderer.FogMode mode, float renderDistance, float partialTick, @@ -156,12 +160,29 @@ public void modifyFogRender(Camera camera, FogRenderer.FogMode mode, float rende public BlockEntityWithoutLevelRenderer getCustomRenderer() { return new lingshiBEWLR(); } - }, ModItems.GLASS_JAR.get()); + }, ModItems.GLASS_JAR.get()); } //HUD @SubscribeEvent public static void registerGuiLayersEvent(RegisterGuiLayersEvent event) { - event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(lingshi.MODID,"cooking_hud"), CookingHud.getInstance()); + event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "cooking_hud"), CookingHud.getInstance()); + } + + // Model + @SubscribeEvent + public static void onModelBaked(ModelEvent.ModifyBakingResult event) { + // glass jar item model + Map modelRegistry = event.getModels(); + ModelResourceLocation location = new ModelResourceLocation(BuiltInRegistries.ITEM.getKey(ModItems.GLASS_JAR.get()), "inventory"); + BakedModel bakeModel = modelRegistry.get(location); + if (bakeModel == null) { + throw new RuntimeException("Did not find Obsidian Hidden in registry"); + } else if (bakeModel instanceof GlassJarBakeModel) { + throw new RuntimeException("Tried to replaceObsidian Hidden twice"); + } else { + GlassJarBakeModel glassJarBakeModel = new GlassJarBakeModel(bakeModel); + event.getModels().put(location, glassJarBakeModel); + } } } diff --git a/src/main/java/mczme/lingshi/client/model/GlassJarBakeModel.java b/src/main/java/mczme/lingshi/client/model/GlassJarBakeModel.java new file mode 100644 index 0000000..92a2557 --- /dev/null +++ b/src/main/java/mczme/lingshi/client/model/GlassJarBakeModel.java @@ -0,0 +1,24 @@ +package mczme.lingshi.client.model; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.world.item.ItemDisplayContext; +import net.neoforged.neoforge.client.model.BakedModelWrapper; + +public class GlassJarBakeModel extends BakedModelWrapper { + + public GlassJarBakeModel(BakedModel originalModel) { + super(originalModel); + } + + @Override + public boolean isCustomRenderer() { + return true; + } + + @Override + public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform) { + this.getTransforms().getTransform(cameraTransformType).apply(applyLeftHandTransform, poseStack); + return this; + } +} diff --git a/src/main/java/mczme/lingshi/common/block/GlassJarBlock.java b/src/main/java/mczme/lingshi/common/block/GlassJarBlock.java index c081ed6..306a2e5 100644 --- a/src/main/java/mczme/lingshi/common/block/GlassJarBlock.java +++ b/src/main/java/mczme/lingshi/common/block/GlassJarBlock.java @@ -6,9 +6,7 @@ import mczme.lingshi.common.registry.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -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.Items; @@ -52,17 +50,34 @@ public ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Leve blockEntity.setChanged(); return ItemInteractionResult.SUCCESS; } + } else if (pStack.is(Items.BUCKET)) { + FluidStack fluidStack = blockEntity.removeFluidStack(1000); + if(!fluidStack.isEmpty()){ + pPlayer.setItemInHand(pHand, new ItemStack(fluidStack.getFluid().getBucket())); + 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 GlassJarBlockEntity blockEntity){ + } return InteractionResult.PASS; } + @Override + protected void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) { + ItemStack itemStack = new ItemStack(ModItems.GLASS_JAR.get()); + pLevel.getBlockEntity(pPos).saveToItem(itemStack,pLevel.registryAccess()); + Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), itemStack); + } + @Override protected MapCodec codec() { return CODEC; diff --git a/src/main/java/mczme/lingshi/common/block/entity/GlassJarBlockEntity.java b/src/main/java/mczme/lingshi/common/block/entity/GlassJarBlockEntity.java index 9bca10c..e0f8bca 100644 --- a/src/main/java/mczme/lingshi/common/block/entity/GlassJarBlockEntity.java +++ b/src/main/java/mczme/lingshi/common/block/entity/GlassJarBlockEntity.java @@ -43,9 +43,13 @@ public boolean addFluidStack(FluidStack fluidStack) { } public FluidStack removeFluidStack(int amount) { - if (this.fluidStack.getAmount() >= amount) { + if (this.fluidStack.getAmount() > amount) { this.fluidStack.setAmount(this.fluidStack.getAmount() - amount); return new FluidStack(this.fluidStack.getFluid(), amount); + } else if (this.fluidStack.getAmount() == amount) { + FluidStack temp = this.fluidStack.copy(); + this.fluidStack = FluidStack.EMPTY; + return temp; } return FluidStack.EMPTY; } diff --git a/src/main/java/mczme/lingshi/common/data/ItemModels.java b/src/main/java/mczme/lingshi/common/data/ItemModels.java index 946b832..b3755ba 100644 --- a/src/main/java/mczme/lingshi/common/data/ItemModels.java +++ b/src/main/java/mczme/lingshi/common/data/ItemModels.java @@ -40,6 +40,6 @@ protected void registerModels() { withExistingParent(String.valueOf(ModItems.SKILLET.get()), modLoc("block/skillet")); withExistingParent(String.valueOf(ModItems.IRON_KNIFE.get()),mcLoc("item/handheld")).texture("layer0", modLoc("item/iron_knife")); withExistingParent(String.valueOf(ModItems.SPATULA.get()),mcLoc("item/handheld")).texture("layer0", modLoc("item/spatula")); - + withExistingParent(String.valueOf(ModItems.GLASS_JAR.get()),modLoc("block/glass_jar")); } }