Skip to content

Commit

Permalink
添加:液体 油 油桶
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Aug 18, 2024
1 parent 0bc2bbe commit 08c49fb
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

73 changes: 68 additions & 5 deletions src/main/java/mczme/lingshi/client/event/Registry.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
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) {
event.registerBlockEntityRenderer(BlockEntityTypes.CHOPPING_BOARD_BLOCKENTITY.get(), ChoppingBoardBER::new);
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) {
Expand All @@ -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());
}

}
13 changes: 1 addition & 12 deletions src/main/java/mczme/lingshi/client/menu/SkilletMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkilletRecipeInput, SkilletRecipe> {
Expand Down Expand Up @@ -124,7 +121,7 @@ public void clearCraftingContent() {

@Override
public boolean recipeMatches(RecipeHolder<SkilletRecipe> pRecipe) {
return pRecipe.value().matches(new SkilletRecipeInput(getInputSlotItem(),blockEntity.getFluid()), this.level);
return pRecipe.value().matches(new SkilletRecipeInput(itemStackHandler,blockEntity.getFluid()), this.level);
}

@Override
Expand Down Expand Up @@ -156,12 +153,4 @@ public RecipeBookType getRecipeBookType() {
public boolean shouldMoveToInventory(int pSlotIndex) {
return pSlotIndex != this.getResultSlotIndex();
}

public List<ItemStack>getInputSlotItem(){
List<ItemStack> inputSlotItem = new ArrayList<>();
for (int i = 0; i < 5; i++) {
inputSlotItem.add(this.getSlot(i).getItem());
}
return inputSlotItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -37,27 +50,27 @@ 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;
}
}
return fluidStacks.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;
}
}
Expand All @@ -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;
}
Expand All @@ -101,7 +137,7 @@ public Packet<ClientGamePacketListener> 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));
}
Expand All @@ -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));
}
Expand All @@ -139,9 +175,52 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInven
public static <T extends BlockEntity> 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<RecipeHolder<SkilletRecipe>> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ protected CookingFoodDataGen(PackOutput packOutput, CompletableFuture<HolderLook

@Override
protected void gather() {
addCookingFood(Items.APPLE,5,20);
addCookingFood(Items.APPLE,5,15);
addCookingFood(ModItems.RICE,15,25);
addCookingFood(Items.IRON_BLOCK,5,20);
addCookingFood(Items.GOLD_BLOCK,10,20);
}

protected void addCookingFood(Item item , int cookedTime,int burntTime){
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mczme/lingshi/common/data/ItemModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected void registerModels() {
basicItem(ModItems.RICE_OF_EAR.get());
basicItem(ModItems.RICE_SEEDLING.get());

basicItem(ModItems.OIL_BUCKET.get());

withExistingParent(String.valueOf(ModItems.CHOPPING_BOARD.get()), modLoc("block/chopping_board"));
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"));
Expand Down
Loading

0 comments on commit 08c49fb

Please sign in to comment.