From 08c49fbd48075bbf7a4b512dd51788b823c86f89 Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Sun, 18 Aug 2024 21:13:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=B6=B2=E4=BD=93?= =?UTF-8?q?=20=E6=B2=B9=20=E6=B2=B9=E6=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../e0d3d0b8d9c807675613821fa865a35f707cd83f | 4 +- .../lingshi/data_maps/item/cooking_food.json | 12 -- .../mczme/lingshi/client/event/Registry.java | 73 ++++++++++- .../lingshi/client/menu/SkilletMenu.java | 13 +- .../block/entity/SkilletBlockEntity.java | 115 +++++++++++++++--- .../common/data/CookingFoodDataGen.java | 4 +- .../mczme/lingshi/common/data/ItemModels.java | 2 + .../data/lang/ChineseLanguageProvider.java | 2 + .../lingshi/common/datamap/DataMapTypes.java | 4 +- .../mczme/lingshi/common/event/Registry.java | 5 +- .../lingshi/common/fluid/ModFluidType.java | 14 +++ .../mczme/lingshi/common/fluid/OilBlock.java | 11 ++ .../mczme/lingshi/common/fluid/OilFluid.java | 52 ++++++++ .../lingshi/common/recipe/SkilletRecipe.java | 2 +- .../recipe/input/SkilletRecipeInput.java | 20 +-- .../lingshi/common/registry/ModBlocks.java | 5 + .../lingshi/common/registry/ModFluids.java | 46 +++++++ .../lingshi/common/registry/ModItems.java | 6 +- src/main/java/mczme/lingshi/lingshi.java | 1 + 19 files changed, 325 insertions(+), 66 deletions(-) delete mode 100644 src/generated/resources/data/lingshi/data_maps/item/cooking_food.json create mode 100644 src/main/java/mczme/lingshi/common/fluid/ModFluidType.java create mode 100644 src/main/java/mczme/lingshi/common/fluid/OilBlock.java create mode 100644 src/main/java/mczme/lingshi/common/fluid/OilFluid.java create mode 100644 src/main/java/mczme/lingshi/common/registry/ModFluids.java diff --git a/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f b/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f index 94f0da3..28ea919 100644 --- a/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f +++ b/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f @@ -1,2 +1,2 @@ -// 1.21 2024-08-17T18:08:32.4751382 Data Maps -93d8561309e6cfabdc62f0e31ff69d3f67e79b50 data/lingshi/data_maps/item/cooking_food.json +// 1.21 2024-08-18T01:50:29.4609975 Data Maps +15e4de66fa16cad8d36f7b96c6aa67d7cb0b0f1a data/lingshi/data_maps/item/cooking_food_item.json diff --git a/src/generated/resources/data/lingshi/data_maps/item/cooking_food.json b/src/generated/resources/data/lingshi/data_maps/item/cooking_food.json deleted file mode 100644 index 7e9a766..0000000 --- a/src/generated/resources/data/lingshi/data_maps/item/cooking_food.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "values": { - "lingshi:rice": { - "complete_time": 25, - "cooked_time": 15 - }, - "minecraft:apple": { - "complete_time": 20, - "cooked_time": 5 - } - } -} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/client/event/Registry.java b/src/main/java/mczme/lingshi/client/event/Registry.java index 585aecf..2fda3a9 100644 --- a/src/main/java/mczme/lingshi/client/event/Registry.java +++ b/src/main/java/mczme/lingshi/client/event/Registry.java @@ -1,26 +1,40 @@ package mczme.lingshi.client.event; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.shaders.FogShape; +import com.mojang.blaze3d.systems.RenderSystem; import mczme.lingshi.client.BlockEntityRenderer.ChoppingBoardBER; import mczme.lingshi.client.BlockEntityRenderer.SkilletBER; import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel; import mczme.lingshi.client.screen.SkilletScreen; import mczme.lingshi.common.recipe.SkilletRecipe; import mczme.lingshi.common.registry.BlockEntityTypes; +import mczme.lingshi.common.registry.ModFluids; import mczme.lingshi.common.registry.ModMenuTypes; import mczme.lingshi.common.registry.ModRecipes; import mczme.lingshi.lingshi; +import net.minecraft.client.Camera; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.FogRenderer; +import net.minecraft.client.renderer.ItemBlockRenderTypes; +import net.minecraft.client.renderer.RenderType; +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.RegisterMenuScreensEvent; import net.neoforged.neoforge.client.event.RegisterRecipeBookCategoriesEvent; +import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; +import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent; +import org.jetbrains.annotations.NotNull; +import org.joml.Vector3f; import static mczme.lingshi.client.recipebook.ModRecipeBookCategories.*; import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET; -@EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD,value = Dist.CLIENT) +@EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class Registry { @SubscribeEvent public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { @@ -28,17 +42,17 @@ public static void registerRenderers(EntityRenderersEvent.RegisterRenderers even event.registerBlockEntityRenderer(BlockEntityTypes.SKILLET_BLOCKENTITY.get(), SkilletBER::new); } -// menu screen + // menu screen @SubscribeEvent private static void registerScreens(RegisterMenuScreensEvent event) { event.register(ModMenuTypes.SKILLET_MENU.get(), SkilletScreen::new); } -// recipe book + // recipe book @SubscribeEvent public static void registerRecipeBook(RegisterRecipeBookCategoriesEvent event) { - event.registerBookCategories(SKILLET, ImmutableList.of(SKILLET_SEARCH.get(), SKILLET_HEAT.get(),SKILLET_PAN_FRY.get(),SKILLET_STIR_FRY.get(),SKILLET_BOIL.get())); - event.registerAggregateCategory(SKILLET_SEARCH.get(), ImmutableList.of(SKILLET_HEAT.get(),SKILLET_PAN_FRY.get(),SKILLET_STIR_FRY.get(),SKILLET_BOIL.get())); + event.registerBookCategories(SKILLET, ImmutableList.of(SKILLET_SEARCH.get(), SKILLET_HEAT.get(), SKILLET_PAN_FRY.get(), SKILLET_STIR_FRY.get(), SKILLET_BOIL.get())); + event.registerAggregateCategory(SKILLET_SEARCH.get(), ImmutableList.of(SKILLET_HEAT.get(), SKILLET_PAN_FRY.get(), SKILLET_STIR_FRY.get(), SKILLET_BOIL.get())); event.registerRecipeCategoryFinder(ModRecipes.SKILLET_RECIPE.get(), recipe -> { if (recipe.value() instanceof SkilletRecipe Recipe) { @@ -55,4 +69,53 @@ public static void registerRecipeBook(RegisterRecipeBookCategoriesEvent event) { }); } + //fluid + @SubscribeEvent + public static void onClientEvent(FMLClientSetupEvent event) { + event.enqueueWork(() -> { + ItemBlockRenderTypes.setRenderLayer(ModFluids.OIL_FLOWING.get(), RenderType.translucent()); + ItemBlockRenderTypes.setRenderLayer(ModFluids.OIL_SOURCE.get(), RenderType.translucent()); + }); + + } + + @SubscribeEvent + public static void registerClientExtensionsEvent(RegisterClientExtensionsEvent event) { + event.registerFluidType(new IClientFluidTypeExtensions() { + @Override + public ResourceLocation getStillTexture() { + return ResourceLocation.withDefaultNamespace("block/water_still"); + } + + @Override + public ResourceLocation getFlowingTexture() { + return ResourceLocation.withDefaultNamespace("block/water_flow"); + } + + @Override + public @NotNull ResourceLocation getOverlayTexture() { + return ResourceLocation.withDefaultNamespace("block/water_overlay"); + } + + @Override + public int getTintColor() { + return 0xA1EAD909; + } + + // 修改从流体中看雾的颜色 + @Override + public @NotNull Vector3f modifyFogColor(Camera camera, float partialTick, ClientLevel level, + 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, + float nearDistance, float farDistance, FogShape shape) { + RenderSystem.setShaderFogStart(1f); + RenderSystem.setShaderFogEnd(6f); // distance when the fog starts + } + }, ModFluids.MOD_FLUID_TYPE.get()); + } + } diff --git a/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java b/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java index cd763de..5ce77e6 100644 --- a/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java +++ b/src/main/java/mczme/lingshi/client/menu/SkilletMenu.java @@ -15,9 +15,6 @@ import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.SlotItemHandler; -import java.util.ArrayList; -import java.util.List; - import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET; public class SkilletMenu extends RecipeBookMenu { @@ -124,7 +121,7 @@ public void clearCraftingContent() { @Override public boolean recipeMatches(RecipeHolder pRecipe) { - return pRecipe.value().matches(new SkilletRecipeInput(getInputSlotItem(),blockEntity.getFluid()), this.level); + return pRecipe.value().matches(new SkilletRecipeInput(itemStackHandler,blockEntity.getFluid()), this.level); } @Override @@ -156,12 +153,4 @@ public RecipeBookType getRecipeBookType() { public boolean shouldMoveToInventory(int pSlotIndex) { return pSlotIndex != this.getResultSlotIndex(); } - - public ListgetInputSlotItem(){ - List inputSlotItem = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - inputSlotItem.add(this.getSlot(i).getItem()); - } - return inputSlotItem; - } } 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 b9f9e7f..3d55393 100644 --- a/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java +++ b/src/main/java/mczme/lingshi/common/block/entity/SkilletBlockEntity.java @@ -2,7 +2,12 @@ import mczme.lingshi.client.menu.SkilletMenu; 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.SkilletRecipeInput; import mczme.lingshi.common.registry.BlockEntityTypes; +import mczme.lingshi.common.registry.ModRecipes; import mczme.lingshi.lingshi; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; @@ -11,24 +16,32 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.world.Containers; 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.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 SkilletBlockEntity extends BlockEntity implements MenuProvider, ICanBeHeated { private final int MAX_SLOT = 5; private FluidStack fluidStacks = FluidStack.EMPTY; - private ItemStackHandler itemStackHandler = new ItemStackHandler(MAX_SLOT+2); + private ItemStackHandler itemStackHandler = new ItemStackHandler(MAX_SLOT + 2); + + private final int[] cookingTime = new int[5]; public SkilletBlockEntity(BlockPos pPos, BlockState pBlockState) { @@ -37,16 +50,16 @@ public SkilletBlockEntity(BlockPos pPos, BlockState pBlockState) { public boolean isFull() { for (int i = 0; i < MAX_SLOT; i++) { - if(itemStackHandler.getStackInSlot(i).isEmpty()){ + if (itemStackHandler.getStackInSlot(i).isEmpty()) { return false; } } return true; } - public boolean isEmpty(){ + public boolean isEmpty() { for (int i = 0; i < MAX_SLOT; i++) { - if(!itemStackHandler.getStackInSlot(i).isEmpty()){ + if (!itemStackHandler.getStackInSlot(i).isEmpty()) { return false; } } @@ -54,10 +67,10 @@ public boolean isEmpty(){ } public ItemStack dropItem() { - for (int i = MAX_SLOT-1; i >=0; i--) { - if(!itemStackHandler.getStackInSlot(i).isEmpty()){ + for (int i = MAX_SLOT - 1; i >= 0; i--) { + if (!itemStackHandler.getStackInSlot(i).isEmpty()) { ItemStack stack = itemStackHandler.getStackInSlot(i).copy(); - itemStackHandler.setStackInSlot(i,ItemStack.EMPTY); + itemStackHandler.setStackInSlot(i, ItemStack.EMPTY); return stack; } } @@ -74,21 +87,44 @@ public ItemStackHandler getItemStacks() { public void setItem(ItemStack item) { for (int i = 0; i < MAX_SLOT; i++) { - if(itemStackHandler.getStackInSlot(i).isEmpty()){ - itemStackHandler.setStackInSlot(i,item); + if (itemStackHandler.getStackInSlot(i).isEmpty()) { + itemStackHandler.setStackInSlot(i, item); break; } } } - public void setItem(ItemStack item,int slot) { - itemStackHandler.setStackInSlot(slot,item); + public void setItem(ItemStack item, int slot) { + itemStackHandler.setStackInSlot(slot, item); } public void setFluid(FluidStack fluid) { fluidStacks = fluid; } + public int size(){ + int size = 0; + for (int i = 0; i < MAX_SLOT; i++) { + if(!itemStackHandler.getStackInSlot(i).isEmpty()){ + size++; + } + } + return size; + } + + public void clear(){ + for (int i = 0; i < MAX_SLOT; i++) { + itemStackHandler.setStackInSlot(i, ItemStack.EMPTY); + } + } + + public void consume(){ + for (int i = 0; i < MAX_SLOT; i++) { + int count = itemStackHandler.getStackInSlot(i).getCount(); + itemStackHandler.getStackInSlot(i).setCount(count - 1); + } + } + public int getMAX() { return MAX_SLOT; } @@ -101,7 +137,7 @@ public Packet getUpdatePacket() { @Override public CompoundTag getUpdateTag(HolderLookup.Provider pRegistries) { CompoundTag tag = new CompoundTag(); - tag.put("items",itemStackHandler.serializeNBT(pRegistries)); + tag.put("items", itemStackHandler.serializeNBT(pRegistries)); if (!fluidStacks.isEmpty()) { tag.put("fluid", fluidStacks.save(pRegistries)); } @@ -119,7 +155,7 @@ protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistrie @Override protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { super.saveAdditional(pTag, pRegistries); - pTag.put("items",itemStackHandler.serializeNBT(pRegistries)); + pTag.put("items", itemStackHandler.serializeNBT(pRegistries)); if (!this.fluidStacks.isEmpty()) { pTag.put("fluid", fluidStacks.save(pRegistries)); } @@ -139,9 +175,52 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInven public static void serverTick(Level pLevel, BlockPos pPos, BlockState blockState, T t) { SkilletBlockEntity blockEntity = (SkilletBlockEntity) t; boolean flag = blockEntity.isEmpty(); - boolean heat_flag = blockEntity.isHeated(pLevel,pPos); - int MAX_SLOT = blockEntity.MAX_SLOT; - - blockEntity.setChanged(); + boolean heat_flag = blockEntity.isHeated(pLevel, pPos); + int MAX_SLOT = blockEntity.getMAX(); + ItemStackHandler itemStackHandler = blockEntity.getItemStacks(); + + if (heat_flag) { + if (!flag) { + int cookedTime=0,burntTime=0; + for (int i = 0; i < MAX_SLOT; i++) { + ItemStack itemStack = itemStackHandler.getStackInSlot(i); + if (itemStack.isEmpty()) { + continue; + } + CookingFoodData cookingFoodData = itemStack.getItemHolder().getData(DataMapTypes.COOKING_FOOD_ITEM); + if (cookingFoodData != null) { + cookedTime=cookingFoodData.cookedTime(); + burntTime=cookingFoodData.burntTime(); + blockEntity.cookingTime[i]++; + } + } + SkilletRecipeInput input = new SkilletRecipeInput(itemStackHandler,blockEntity.getFluid()); + Optional> optional = pLevel.getRecipeManager().getRecipeFor( + ModRecipes.SKILLET_RECIPE.get(), + input, + pLevel + ); + ItemStack result = optional.map(RecipeHolder::value) + .map(e->e.assemble(input,pLevel.registryAccess())) + .orElse(ItemStack.EMPTY); + if (!result.isEmpty()) { + int size=0; + for (int i = 0; i < MAX_SLOT; i++) { + if(blockEntity.cookingTime[i]>cookedTime*20){ + size++; + } + } + if (size==blockEntity.size()){ + Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY()+0.2, pPos.getZ(), result); + Arrays.fill(blockEntity.cookingTime,0); + blockEntity.consume(); + pLevel.sendBlockUpdated(pPos, blockState, blockState, Block.UPDATE_CLIENTS); + } + }else { + Arrays.fill(blockEntity.cookingTime,0); + } + } + } + blockEntity.setChanged(); + } } -} diff --git a/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java b/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java index a9690e4..eb69e81 100644 --- a/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java +++ b/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java @@ -23,8 +23,10 @@ protected CookingFoodDataGen(PackOutput packOutput, CompletableFuture COOKING_FOOD_ITEM = DataMapType.builder( - ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "cooking_food"), + ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "cooking_food_item"), Registries.ITEM, CookingFoodData.CODEC ).build(); public static final DataMapType COOKING_FOOD_FLUID = DataMapType.builder( - ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "cooking_food"), + ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "cooking_food_fliud"), Registries.FLUID, CookingFoodData.CODEC ).build(); diff --git a/src/main/java/mczme/lingshi/common/event/Registry.java b/src/main/java/mczme/lingshi/common/event/Registry.java index 62edf8d..a66910b 100644 --- a/src/main/java/mczme/lingshi/common/event/Registry.java +++ b/src/main/java/mczme/lingshi/common/event/Registry.java @@ -11,16 +11,17 @@ @EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD) public class Registry { -// data map + // data map @SubscribeEvent private static void registerDataMapTypes(RegisterDataMapTypesEvent event) { event.register(COOKING_FOOD_FLUID); event.register(COOKING_FOOD_ITEM); } -// Capabilities + // Capabilities @SubscribeEvent private static void registerCapabilities(RegisterCapabilitiesEvent event) { } + } diff --git a/src/main/java/mczme/lingshi/common/fluid/ModFluidType.java b/src/main/java/mczme/lingshi/common/fluid/ModFluidType.java new file mode 100644 index 0000000..8968eee --- /dev/null +++ b/src/main/java/mczme/lingshi/common/fluid/ModFluidType.java @@ -0,0 +1,14 @@ +package mczme.lingshi.common.fluid; + +import net.neoforged.neoforge.fluids.FluidType; + +public class ModFluidType extends FluidType { + /** + * Default constructor. + * + * @param properties the general properties of the fluid type + */ + public ModFluidType(Properties properties) { + super(properties); + } +} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/common/fluid/OilBlock.java b/src/main/java/mczme/lingshi/common/fluid/OilBlock.java new file mode 100644 index 0000000..3edc49a --- /dev/null +++ b/src/main/java/mczme/lingshi/common/fluid/OilBlock.java @@ -0,0 +1,11 @@ +package mczme.lingshi.common.fluid; + +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.material.FlowingFluid; + +public class OilBlock extends LiquidBlock { + + public OilBlock(FlowingFluid p_54694_, Properties p_54695_) { + super(p_54694_, p_54695_); + } +} diff --git a/src/main/java/mczme/lingshi/common/fluid/OilFluid.java b/src/main/java/mczme/lingshi/common/fluid/OilFluid.java new file mode 100644 index 0000000..b480e3c --- /dev/null +++ b/src/main/java/mczme/lingshi/common/fluid/OilFluid.java @@ -0,0 +1,52 @@ +package mczme.lingshi.common.fluid; + +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.neoforged.neoforge.fluids.BaseFlowingFluid; + +public abstract class OilFluid extends BaseFlowingFluid { + + protected OilFluid(Properties properties) { + super(properties); + } + + public static class Flowing extends OilFluid { + public Flowing(Properties properties) { + super(properties); + } + + @Override + protected void createFluidStateDefinition(StateDefinition.Builder pBuilder) { + super.createFluidStateDefinition(pBuilder); + pBuilder.add(LEVEL); + } + + @Override + public int getAmount(FluidState pState) { + return pState.getValue(LEVEL); + } + + @Override + public boolean isSource(FluidState pState) { + return false; + } + } + + public static class Source extends OilFluid { + public Source(Properties properties) { + super(properties); + } + + @Override + public int getAmount(FluidState pState) { + return 8; + } + + @Override + public boolean isSource(FluidState pState) { + return true; + } + } + +} diff --git a/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java b/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java index 62a71f2..534fcac 100644 --- a/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java +++ b/src/main/java/mczme/lingshi/common/recipe/SkilletRecipe.java @@ -90,7 +90,7 @@ public RecipeType getType() { } public ItemStack getResult() { - return result; + return result.copy(); } public FluidStack getFluid() { diff --git a/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java b/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java index a965759..085254c 100644 --- a/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java +++ b/src/main/java/mczme/lingshi/common/recipe/input/SkilletRecipeInput.java @@ -3,22 +3,23 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeInput; import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.items.ItemStackHandler; +import org.jetbrains.annotations.NotNull; -import java.util.List; public class SkilletRecipeInput implements RecipeInput { - private final List items; + private final ItemStackHandler items; private final FluidStack fluids; - public SkilletRecipeInput(List items, FluidStack fluid) { + public SkilletRecipeInput(ItemStackHandler items, FluidStack fluid) { this.items = items; this.fluids = fluid; } @Override - public ItemStack getItem(int pIndex) { - return this.items.get(pIndex); + public @NotNull ItemStack getItem(int pIndex) { + return this.items.getStackInSlot(pIndex); } public FluidStack getFluid() { @@ -28,11 +29,16 @@ public FluidStack getFluid() { @Override public int size() { int i = fluids.isEmpty()?0:1; - return items.size()+i; + return items.getSlots() + i; } @Override public boolean isEmpty() { - return this.items.isEmpty() && this.fluids.isEmpty(); + for (int i = 0; i < 5; i++) { + if(!items.getStackInSlot(i).isEmpty()){ + return false; + } + } + return this.fluids.isEmpty(); } } diff --git a/src/main/java/mczme/lingshi/common/registry/ModBlocks.java b/src/main/java/mczme/lingshi/common/registry/ModBlocks.java index 6b2a2f4..70656e8 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModBlocks.java +++ b/src/main/java/mczme/lingshi/common/registry/ModBlocks.java @@ -1,9 +1,11 @@ package mczme.lingshi.common.registry; import mczme.lingshi.common.block.*; +import mczme.lingshi.common.fluid.OilBlock; import mczme.lingshi.lingshi; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.CropBlock; +import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.MapColor; @@ -13,6 +15,7 @@ import java.util.function.Supplier; + public class ModBlocks { public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(lingshi.MODID); @@ -33,6 +36,8 @@ public class ModBlocks { public static final Supplier CHOPPING_BOARD = BLOCKS.registerBlock("chopping_board", ChoppingBoardBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_PLANKS)); + public static final Supplier OIL_LIQUID_BLOCK = BLOCKS.register("oil_liquid_block",()->new OilBlock(ModFluids.OIL_SOURCE.get(),BlockBehaviour.Properties.ofFullCopy(Blocks.WATER))); + public static void register(IEventBus modEventBus) { BLOCKS.register(modEventBus); } diff --git a/src/main/java/mczme/lingshi/common/registry/ModFluids.java b/src/main/java/mczme/lingshi/common/registry/ModFluids.java new file mode 100644 index 0000000..4e76908 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/registry/ModFluids.java @@ -0,0 +1,46 @@ +package mczme.lingshi.common.registry; + +import mczme.lingshi.common.fluid.ModFluidType; +import mczme.lingshi.common.fluid.OilFluid; +import mczme.lingshi.lingshi; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.core.registries.Registries; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.PointedDripstoneBlock; +import net.minecraft.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.Fluid; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.common.SoundActions; +import net.neoforged.neoforge.fluids.BaseFlowingFluid; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.NeoForgeRegistries; + +import java.util.function.Supplier; + +public class ModFluids { + + public static final DeferredRegister FLUID_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.FLUID_TYPES, lingshi.MODID); + + public static final Supplier MOD_FLUID_TYPE = FLUID_TYPES.register("mod_fluid_type", () -> new ModFluidType( + FluidType.Properties.create().descriptionId("block.lingshi.oil") + .fallDistanceModifier(0F) + .canExtinguish(true) + .sound(SoundActions.BUCKET_FILL, SoundEvents.BUCKET_FILL) + .sound(SoundActions.BUCKET_EMPTY, SoundEvents.BUCKET_EMPTY) + .sound(SoundActions.FLUID_VAPORIZE, SoundEvents.FIRE_EXTINGUISH) + .canHydrate(true) + .addDripstoneDripping(PointedDripstoneBlock.WATER_TRANSFER_PROBABILITY_PER_RANDOM_TICK, ParticleTypes.DRIPPING_DRIPSTONE_WATER, Blocks.WATER_CAULDRON, SoundEvents.POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON))); + + public static final DeferredRegister FLUIDS = DeferredRegister.create(Registries.FLUID, lingshi.MODID); + + public static final Supplier OIL_SOURCE = FLUIDS.register("oil_source", ()-> new OilFluid.Source(ModFluids.properties)); + public static final Supplier OIL_FLOWING = FLUIDS.register("oil_flowing",()-> new OilFluid.Flowing(ModFluids.properties)); + public static final BaseFlowingFluid.Properties properties = new BaseFlowingFluid.Properties(MOD_FLUID_TYPE,ModFluids.OIL_SOURCE,ModFluids.OIL_FLOWING).bucket(ModItems.OIL_BUCKET).slopeFindDistance(2).levelDecreasePerBlock(2).block(ModBlocks.OIL_LIQUID_BLOCK); + + public static void register(IEventBus modEventBus) { + FLUID_TYPES.register(modEventBus); + FLUIDS.register(modEventBus); + } +} diff --git a/src/main/java/mczme/lingshi/common/registry/ModItems.java b/src/main/java/mczme/lingshi/common/registry/ModItems.java index 828f010..f2ad34d 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModItems.java +++ b/src/main/java/mczme/lingshi/common/registry/ModItems.java @@ -2,10 +2,7 @@ import mczme.lingshi.common.item.KnifeItem; import mczme.lingshi.lingshi; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.SwordItem; -import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.*; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredRegister; @@ -29,6 +26,7 @@ public class ModItems { public static final Supplier IRON_KNIFE = registerWithCreateTab("iron_knife", () -> new KnifeItem(Tiers.IRON,new Item.Properties().attributes(SwordItem.createAttributes(Tiers.IRON, 3, -2.4F)))); + public static final Supplier OIL_BUCKET = registerWithCreateTab("oil_bucket",()->new BucketItem(ModFluids.OIL_SOURCE.get(),new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1))); private static Supplier registerWithCreateTab(String item_name, Supplier itemSupplier) { Supplier item = ITEMS.register(item_name, itemSupplier); diff --git a/src/main/java/mczme/lingshi/lingshi.java b/src/main/java/mczme/lingshi/lingshi.java index 306828a..44df3ec 100644 --- a/src/main/java/mczme/lingshi/lingshi.java +++ b/src/main/java/mczme/lingshi/lingshi.java @@ -28,6 +28,7 @@ public lingshi(IEventBus modEventBus, ModContainer modContainer) ModRecipes.register(modEventBus); ModSerializer.register(modEventBus); ModMenuTypes.register(modEventBus); + ModFluids.register(modEventBus); }