Skip to content

Commit

Permalink
添加:烹饪锅,锅盖
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Aug 22, 2024
1 parent 0044742 commit b497f79
Show file tree
Hide file tree
Showing 41 changed files with 1,511 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 1.21 2024-08-13T03:55:33.7091711 Loot Tables
// 1.21 2024-08-22T18:03:26.4830973 Loot Tables
032b2242788b8411178136ca48214246ef2af8a9 data/lingshi/loot_table/blocks/chopping_board.json
63e60d75a79e0a64eb6338f6bc98dddd6a8d6a0b data/lingshi/loot_table/blocks/cooking_pot.json
67cc122cf5e7e5865ff9bc81fec6e8371225b0d6 data/lingshi/loot_table/blocks/skillet.json
c843630bb0739aad37078f0119c9cc31f5316c3a data/lingshi/loot_table/blocks/tea_leaf.json
3cd0ced47f090fec162cddcb8b2f75284fa134cb data/lingshi/loot_table/blocks/tea_tree.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21 2024-08-21T06:16:10.9126133 Languages: zh_cn for mod: lingshi
18193d8163c50d2682857150071f4b38892474cb assets/lingshi/lang/zh_cn.json
// 1.21 2024-08-22T18:03:26.4900985 Languages: zh_cn for mod: lingshi
2012858b997388159ffda305994f25429de3d030 assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21 2024-08-21T06:32:40.2517736 Recipes
// 1.21 2024-08-22T18:03:26.4870994 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
Expand All @@ -15,7 +15,7 @@ e511f76246f906a279fc1ec531922d8f70dfb68c data/lingshi/advancement/recipes/tools/
bec1047337843fdd073fe87393c3b500ae11a1de data/lingshi/recipe/chopping_board.json
3e41620c4ec5b19f87046dad7fe5c7ed6ede21c2 data/lingshi/recipe/chopping_board/rice.json
e6daac4cca245fc9e220e2fcb1f2b27e410ba503 data/lingshi/recipe/iron_knife.json
6971547c4e197d1f259c4599e8bd99fa9a565095 data/lingshi/recipe/skillet.json
a0c7fd85028ea7997689d7bc093b9d025c522ea6 data/lingshi/recipe/skillet.json
26590681b1777b3be492a971dfc95a36af346fee data/lingshi/recipe/skillet/baked_potato.json
91bf1f4b8acf5c536598059691981e665838ea17 data/lingshi/recipe/skillet/cooked_beef.json
27b62cedc03d158bf611f528d405dd7cfe39b429 data/lingshi/recipe/skillet/cooked_chicken.json
Expand Down
3 changes: 3 additions & 0 deletions src/generated/resources/assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"block.lingshi.chopping_board": "砧板",
"block.lingshi.cooking_pot": "烹饪锅",
"block.lingshi.rice": "稻米",
"block.lingshi.rice_seedling": "稻苗",
"block.lingshi.skillet": "平底锅",
"block.lingshi.tea_tree": "茶树",
"gui.lingshi.cooking_pot_menu": "烹饪锅",
"gui.lingshi.skillet_menu": "平底锅",
"item.lingshi.fried_egg": "煎鸡蛋",
"item.lingshi.iron_knife": "铁菜刀",
"item.lingshi.oil_bucket": "油桶",
"item.lingshi.pot_lid": "锅盖",
"item.lingshi.rice_of_ear": "稻穗",
"item.lingshi.spatula": "锅铲",
"item.lingshi.tea_leaf": "茶叶",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "lingshi:cooking_pot"
}
],
"rolls": 1.0
}
],
"random_sequence": "lingshi:blocks/cooking_pot"
}
5 changes: 4 additions & 1 deletion src/generated/resources/data/lingshi/recipe/skillet.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"#": {
"tag": "minecraft:planks"
},
"A": {
"item": "minecraft:iron_ingot"
},
"X": {
"tag": "minecraft:terracotta"
}
},
"pattern": [
"XX#",
"AA#",
"XX "
],
"result": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

public class SkilletBER implements BlockEntityRenderer<SkilletBlockEntity> {

private int StirFryCount = 0;

public SkilletBER(BlockEntityRendererProvider.Context pContext) {

}
Expand All @@ -33,7 +35,7 @@ public void render(SkilletBlockEntity pBlockEntity, float pPartialTick, PoseStac
Direction direction = pBlockEntity.getBlockState().getValue(ChoppingBoardBlock.FACING);
double[] X = {0.5, 0.3, 0.6, 0.3, 0.6};
double[] Z = {0.5, 0.3, 0.3, 0.6, 0.6};
double[] Y = {0.13, 0.125, 0.123, 0.125, 0.122};
double[] Y = {0.13, 0.125, 0.123, 0.124, 0.122};

if (!pBlockEntity.isEmpty()) {
if (!fluidStack.isEmpty()) {
Expand All @@ -60,13 +62,13 @@ public void render(SkilletBlockEntity pBlockEntity, float pPartialTick, PoseStac

private float randomAngel(int stirFry) {
Random rand = new Random();
int seed = switch (stirFry % 3) {
case 1 -> 123456;
case 2 -> 886549;
default -> 0;
};
rand.setSeed(seed);
return seed == 0 ? 0 : rand.nextFloat() * 180;
if(StirFryCount!= stirFry){
StirFryCount = stirFry;
rand.setSeed(StirFryCount);
}else {
rand.setSeed(StirFryCount* 500L);
}
return stirFry==0?0: rand.nextFloat() * 180;
}

}
21 changes: 21 additions & 0 deletions src/main/java/mczme/lingshi/client/event/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mczme.lingshi.client.BlockEntityRenderer.SkilletBER;
import mczme.lingshi.client.recipebook.CookingFoodRecipeLabel;
import mczme.lingshi.client.screen.CookingHud;
import mczme.lingshi.client.screen.CookingPotScreen;
import mczme.lingshi.client.screen.SkilletScreen;
import mczme.lingshi.common.recipe.SkilletRecipe;
import mczme.lingshi.common.registry.BlockEntityTypes;
Expand Down Expand Up @@ -34,6 +35,7 @@
import org.joml.Vector3f;

import static mczme.lingshi.client.recipebook.ModRecipeBookCategories.*;
import static mczme.lingshi.client.recipebook.ModRecipeBookType.COOKING_POT;
import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET;

@EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
Expand All @@ -48,11 +50,13 @@ public static void registerRenderers(EntityRenderersEvent.RegisterRenderers even
@SubscribeEvent
private static void registerScreens(RegisterMenuScreensEvent event) {
event.register(ModMenuTypes.SKILLET_MENU.get(), SkilletScreen::new);
event.register(ModMenuTypes.COOKING_POT_MENU.get(), CookingPotScreen::new);
}

// recipe book
@SubscribeEvent
public static void registerRecipeBook(RegisterRecipeBookCategoriesEvent event) {
// Skillet
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 ->
Expand All @@ -69,6 +73,23 @@ public static void registerRecipeBook(RegisterRecipeBookCategoriesEvent event) {
}
return MISC.get();
});
// Cooking Pot
event.registerBookCategories(COOKING_POT, 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) {
CookingFoodRecipeLabel label = Recipe.getLabel();
return switch (label) {
case HEAT -> SKILLET_HEAT.get();
case PAN_FRY -> SKILLET_PAN_FRY.get();
case STIR_FRY -> SKILLET_STIR_FRY.get();
case BOIL -> SKILLET_BOIL.get();
default -> MISC.get();
};
}
return MISC.get();
});
}

//fluid
Expand Down
158 changes: 158 additions & 0 deletions src/main/java/mczme/lingshi/client/menu/CookingPotMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package mczme.lingshi.client.menu;

import mczme.lingshi.client.menu.Slot.CookingItemStackHandler;
import mczme.lingshi.client.menu.Slot.ResultSlot;
import mczme.lingshi.common.block.entity.CookingPotBlockEntity;
import mczme.lingshi.common.recipe.CookingPotRecipe;
import mczme.lingshi.common.recipe.input.CookingFoodRecipeInput;
import mczme.lingshi.common.registry.ModMenuTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.StackedContents;
import net.minecraft.world.inventory.RecipeBookMenu;
import net.minecraft.world.inventory.RecipeBookType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.items.ItemStackHandler;
import net.neoforged.neoforge.items.SlotItemHandler;

import static mczme.lingshi.client.recipebook.ModRecipeBookType.COOKING_POT;

public class CookingPotMenu extends RecipeBookMenu<CookingFoodRecipeInput, CookingPotRecipe> {

public CookingPotBlockEntity blockEntity;
protected final Level level;
private final CookingItemStackHandler itemStackHandler;

public CookingPotMenu(int pContainerId, Inventory pPlayerInventory, FriendlyByteBuf pContext) {
this(pContainerId, pPlayerInventory,(CookingPotBlockEntity) pPlayerInventory.player.level().getBlockEntity(pContext.readBlockPos()));
}

public CookingPotMenu(int pContainerId,Inventory pPlayerInventory, CookingPotBlockEntity blockEntity) {
super(ModMenuTypes.COOKING_POT_MENU.get(), pContainerId);
checkContainerSize(pPlayerInventory, 1);
this.blockEntity = blockEntity;
this.level = pPlayerInventory.player.level();
this.itemStackHandler = blockEntity.getItemStacks();
this.addWorkSlot(itemStackHandler);
layoutPlayerInventorySlots(pPlayerInventory);
}

private void addWorkSlot(ItemStackHandler itemStacks) {
int[] X = {33, 51, 69,33, 51, 69, 93, 127};
int[] Y = {29, 29, 29,47, 47, 47, 29, 47};
for (int i = 0; i < blockEntity.getMAX(); i++) {
SlotItemHandler slot = new SlotItemHandler(itemStackHandler, i, X[i], Y[i]);
slot.set(itemStacks.getStackInSlot(i));
this.addSlot(slot);
}
itemStackHandler.setStackInSlot(6,blockEntity.container);
this.addSlot(new ResultSlot(itemStackHandler, 6, X[6], Y[6]));
itemStackHandler.setStackInSlot(7,blockEntity.result);
this.addSlot(new ResultSlot(itemStackHandler, 7, X[7], Y[7]));
}

private void layoutPlayerInventorySlots(Inventory playerInventory) {
// Player inventory
for (int i = 0; i < 3; ++i) {
for (int l = 0; l < 9; ++l) {
this.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 84 + i * 18));
}
}
// Hotbar
for (int i = 0; i < 9; ++i) {
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
}
}

@Override
public void fillCraftSlotsStackedContents(StackedContents pItemHelper) {
for (int i = 0; i < blockEntity.getMAX(); i++) {
pItemHelper.accountSimpleStack(itemStackHandler.getStackInSlot(i));
}
}

@Override
public void clearCraftingContent() {
for (int i = 0; i < blockEntity.getMAX()-2; i++) {
this.getSlot(i).set(ItemStack.EMPTY);
}
}

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

@Override
public int getResultSlotIndex() {
return 7;
}

@Override
public int getGridWidth() {
return 6;
}

@Override
public int getGridHeight() {
return 1;
}

@Override
public int getSize() {
return 8;
}

@Override
public RecipeBookType getRecipeBookType() {
return COOKING_POT;
}

@Override
public boolean shouldMoveToInventory(int pSlotIndex) {
return pSlotIndex != this.getResultSlotIndex();
}

@Override
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
ItemStack quickMovedStack = ItemStack.EMPTY;
Slot quickMovedSlot = this.slots.get(pIndex);
if (quickMovedSlot.hasItem()) {
ItemStack rawStack = quickMovedSlot.getItem();
quickMovedStack = rawStack.copy();
if (pIndex >= 8 && pIndex < 43) {
if (!this.moveItemStackTo(rawStack, 0, 6, false)) {
if (pIndex < 32) {
if (!this.moveItemStackTo(rawStack, 34, 43, false)) {
return ItemStack.EMPTY;
}
} else if (!this.moveItemStackTo(rawStack, 8, 34, false)) {
return ItemStack.EMPTY;
}
}
} else if (!this.moveItemStackTo(rawStack, 7, 43, false)) {
return ItemStack.EMPTY;
}

if (rawStack.isEmpty()) {
quickMovedSlot.set(ItemStack.EMPTY);
} else {
quickMovedSlot.setChanged();
}
if (rawStack.getCount() == quickMovedStack.getCount()) {
return ItemStack.EMPTY;
}
quickMovedSlot.onTake(pPlayer, rawStack);
}
return quickMovedStack;
}

@Override
public boolean stillValid(Player pPlayer) {
return true;
}
}
14 changes: 9 additions & 5 deletions src/main/java/mczme/lingshi/client/menu/SkilletMenu.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package mczme.lingshi.client.menu;

import mczme.lingshi.client.menu.Slot.CookingItemStackHandler;
import mczme.lingshi.client.menu.Slot.ResultSlot;
import mczme.lingshi.common.block.entity.SkilletBlockEntity;
import mczme.lingshi.common.recipe.SkilletRecipe;
import mczme.lingshi.common.recipe.input.SkilletRecipeInput;
import mczme.lingshi.common.recipe.input.CookingFoodRecipeInput;
import mczme.lingshi.common.registry.ModMenuTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -17,7 +19,7 @@

import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET;

public class SkilletMenu extends RecipeBookMenu<SkilletRecipeInput, SkilletRecipe> {
public class SkilletMenu extends RecipeBookMenu<CookingFoodRecipeInput, SkilletRecipe> {

public SkilletBlockEntity blockEntity;
protected final Level level;
Expand Down Expand Up @@ -46,8 +48,10 @@ private void addWorkSlot(ItemStackHandler itemStacks) {
slot.set(itemStacks.getStackInSlot(i));
this.addSlot(slot);
}
this.addSlot(new SlotItemHandler(itemStackHandler, 5, X[5], Y[5]));
this.addSlot(new SlotItemHandler(itemStackHandler, 6, X[6], Y[6]));
itemStackHandler.setStackInSlot(5,blockEntity.container);
this.addSlot(new ResultSlot(itemStackHandler, 5, X[5], Y[5]));
itemStackHandler.setStackInSlot(6,blockEntity.result);
this.addSlot(new ResultSlot(itemStackHandler, 6, X[6], Y[6]));
}

private void layoutPlayerInventorySlots(Inventory playerInventory) {
Expand Down Expand Up @@ -121,7 +125,7 @@ public void clearCraftingContent() {

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

@Override
Expand Down
Loading

0 comments on commit b497f79

Please sign in to comment.