Skip to content

Commit

Permalink
添加:配方书添加
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Aug 15, 2024
1 parent 0336a98 commit 5b5c355
Show file tree
Hide file tree
Showing 30 changed files with 816 additions and 80 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ minecraft_version=1.21
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21,1.21.1)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.0.164
neo_version=21.0.167
# The Neo version range can use any version of Neo as bounds
neo_version_range=[21.0.0-beta,)
# The loader version range can only use the major version of FML as bounds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21 2024-08-13T03:55:33.7111786 Languages: zh_cn for mod: lingshi
6691b4e3de41dca51664777d2790f94bd059d1ac assets/lingshi/lang/zh_cn.json
// 1.21 2024-08-15T20:42:41.6040699 Languages: zh_cn for mod: lingshi
ad34dce9233433d976c01585ed4b08af089d10f5 assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// 1.21 2024-08-14T05:22:07.8393123 Recipes
80c03e628f24c66af32ca2f2a7f7efcfedeacb9f data/lingshi/advancement/recipes/skillet/dd.json
4f3b846962abd318042306445c7ecd01a176ef1f data/lingshi/recipe/chopping_board/rice.json
f8fc62d1b3c33ff6e83d1d8f585d6dc4deff2cd3 data/lingshi/recipe/skillet/dd.json
// 1.21 2024-08-16T05:17:35.2742695 Recipes
5bebf6a89fdd6614d0e0b2b0908f76f48afe8ad3 data/lingshi/advancement/recipes/skillet/test00.json
82ba2633d02b797c4ed89708055c8aab59a9cc39 data/lingshi/advancement/recipes/skillet/test01.json
b055e56217dec23b58a0c5f454e5dd060e0ed81a data/lingshi/advancement/recipes/skillet/test02.json
3e41620c4ec5b19f87046dad7fe5c7ed6ede21c2 data/lingshi/recipe/chopping_board/rice.json
9622697bc2a3e83291b218d768aa2c1026c1d38f data/lingshi/recipe/skillet/test00.json
43b74387359bb0f936238fc99d5dce19aa60859a data/lingshi/recipe/skillet/test01.json
49673e41d352c946039d76d4a55b406153e7cc00 data/lingshi/recipe/skillet/test02.json
1 change: 1 addition & 0 deletions src/generated/resources/assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"block.lingshi.rice_seedling": "稻苗",
"block.lingshi.skillet": "平底锅",
"block.lingshi.tea_tree": "茶树",
"gui.lingshi.skillet_menu": "平底锅",
"item.lingshi.iron_knife": "铁菜刀",
"item.lingshi.rice_of_ear": "稻穗",
"item.lingshi.tea_leaf": "茶叶",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "lingshi:chopping_board_serializer",
"type": "lingshi:chopping_board",
"input": {
"item": "lingshi:rice_of_ear"
},
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/mczme/lingshi/ModEnumParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package mczme.lingshi;

import mczme.lingshi.common.registry.ModItems;
import net.minecraft.client.RecipeBookCategories;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.neoforged.fml.common.asm.enumextension.EnumProxy;

import java.util.List;
import java.util.function.Supplier;

public class ModEnumParams {

public static final EnumProxy<RecipeBookCategories> SKILLET_SEARCH_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(Items.COMPASS) );
public static final EnumProxy<RecipeBookCategories> SKILLET_HEAT_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(ModItems.RICE_OF_EAR.get()));
public static final EnumProxy<RecipeBookCategories> PAN_FRY_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(ModItems.RICE.get()));
public static final EnumProxy<RecipeBookCategories> STIR_FRY_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(ModItems.IRON_KNIFE.get()));
public static final EnumProxy<RecipeBookCategories> BOIL_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(Items.WHEAT));
public static final EnumProxy<RecipeBookCategories> MISC_ENUM_PROXY = new EnumProxy<>(RecipeBookCategories.class, params(Items.BUCKET));

private static Supplier<List<ItemStack>> params(Item item){
return ()-> List.of(new ItemStack(item));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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.SkilletBlockEntity;
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.minecraft.world.item.ItemStack;

import java.util.List;

public class SkilletBER implements BlockEntityRenderer<SkilletBlockEntity> {

public SkilletBER(BlockEntityRendererProvider.Context pContext){

}

@Override
public void render(SkilletBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) {
List<ItemStack> itemStack = pBlockEntity.getItemStacks();
Direction direction = pBlockEntity.getBlockState().getValue(ChoppingBoardBlock.FACING);

if(!itemStack.isEmpty()){
for (int i = 0; i <itemStack.size(); i++) {
if(itemStack.get(i).isEmpty()) continue;
pPoseStack.pushPose();
pPoseStack.translate(0.5,0.2+i/10.0,0.5);
pPoseStack.mulPose(Axis.YP.rotationDegrees(-direction.toYRot()));
pPoseStack.mulPose(Axis.XP.rotationDegrees(90.0F));
pPoseStack.scale(0.5F, 0.5F, 0.5F);
Minecraft.getInstance().getItemRenderer().renderStatic(itemStack.get(i), ItemDisplayContext.FIXED, pPackedLight, pPackedOverlay, pPoseStack, pBufferSource, pBlockEntity.getLevel(), (int) pBlockEntity.getBlockPos().asLong());
pPoseStack.popPose();
}
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/mczme/lingshi/client/event/Registry.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
package mczme.lingshi.client.event;

import com.google.common.collect.ImmutableList;
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.ModMenuTypes;
import mczme.lingshi.common.registry.ModRecipes;
import mczme.lingshi.lingshi;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.client.event.RegisterRecipeBookCategoriesEvent;

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)
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
@SubscribeEvent
private static void registerScreens(RegisterMenuScreensEvent event) {
event.register(ModMenuTypes.SKILLET_MENU.get(), SkilletScreen::new);
}

// 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.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();
});
}

}
169 changes: 169 additions & 0 deletions src/main/java/mczme/lingshi/client/menu/SkilletMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package mczme.lingshi.client.menu;

import mczme.lingshi.common.block.entity.SkilletBlockEntity;
import mczme.lingshi.common.recipe.SkilletRecipe;
import mczme.lingshi.common.recipe.input.SkilletRecipeInput;
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.*;
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 java.util.List;

import static mczme.lingshi.client.recipebook.ModRecipeBookType.SKILLET;
import static mczme.lingshi.common.utility.ListUtility.copy;

public class SkilletMenu extends RecipeBookMenu<SkilletRecipeInput, SkilletRecipe> {

SkilletBlockEntity blockEntity;
public final ItemStackHandler inventory;
protected final Level level;

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

public SkilletMenu(int pContainerId, Inventory pPlayerInventory,
SkilletBlockEntity blockEntity) {
super(ModMenuTypes.SKILLET_MENU.get(), pContainerId);
checkContainerSize(pPlayerInventory, 1);
this.blockEntity = blockEntity;
this.inventory = blockEntity.getInventory();
this.level = pPlayerInventory.player.level();
this.addWorkSlot(copy(blockEntity.getItemStacks()));
layoutPlayerInventorySlots(pPlayerInventory);
}

private void addWorkSlot(List<ItemStack> itemStacks) {
if (itemStacks.size() < blockEntity.getMAX()) {
for (int i = itemStacks.size(); i < blockEntity.getMAX(); i++)
itemStacks.add(ItemStack.EMPTY);
}
int[] X = {42, 60, 33, 51, 69, 98, 127};
int[] Y = {29, 29, 47, 47, 47, 29, 47};
for (int i = 0; i < blockEntity.getMAX(); i++) {
SlotItemHandler slot = new SlotItemHandler(inventory, i, X[i], Y[i]);
slot.set(itemStacks.get(i));
this.addSlot(slot);
}
this.addSlot(new SlotItemHandler(inventory, 5, X[5], Y[5]));
this.addSlot(new SlotItemHandler(inventory, 6, X[6], Y[6]));
}

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 removed(Player pPlayer) {
blockEntity.getItemStacks().clear();
for (int i = 0; i < blockEntity.getMAX(); i++) {
if (!this.getSlot(i).getItem().isEmpty()) {
blockEntity.setItem(this.getSlot(i).getItem());
}
}
blockEntity.setChanged();
super.removed(pPlayer);
}

@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 >= 7 && pIndex < 43) {
if (!this.moveItemStackTo(rawStack, 0, 5, false)) {
if (pIndex < 32) {
if (!this.moveItemStackTo(rawStack, 34, 43, false)) {
return ItemStack.EMPTY;
}
} else if (!this.moveItemStackTo(rawStack, 7, 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;
}

@Override
public void fillCraftSlotsStackedContents(StackedContents pItemHelper) {

}

@Override
public void clearCraftingContent() {
this.getSlot(0).set(ItemStack.EMPTY);
this.getSlot(2).set(ItemStack.EMPTY);
}

@Override
public boolean recipeMatches(RecipeHolder<SkilletRecipe> pRecipe) {
return true;
}

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

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

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

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

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

@Override
public boolean shouldMoveToInventory(int pSlotIndex) {
return pSlotIndex != 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package mczme.lingshi.client.recipebook;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;

public enum CookingFoodRecipeLabel {
HEAT("heat"),
PAN_FRY("pan_fry"),
STIR_FRY("stir_fry"),
BOIL("boil"),
STEW("stew"),
DEEP_FRY("deep_fly"),
MISC("misc");

public final String string;
public static final Codec<CookingFoodRecipeLabel> CODEC = Codec.STRING.flatXmap(s -> {
CookingFoodRecipeLabel label = isinside(s);
if(s!=null) return DataResult.success(label);
else return DataResult.error(()-> "Unknown cooking food recipe label: " + s);
},label -> DataResult.success(label.toString())
);

CookingFoodRecipeLabel(String string) {
this.string = string;
}

public static CookingFoodRecipeLabel isinside(String s){
CookingFoodRecipeLabel[] t = values();
for(CookingFoodRecipeLabel i : t) {
if (i.toString().equals(s)) return i;
}
return null;
}

@Override
public String toString() {
return string;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mczme.lingshi.client.recipebook;

import com.google.common.base.Suppliers;
import net.minecraft.client.RecipeBookCategories;

import java.util.function.Supplier;

public class ModRecipeBookCategories {
public static final Supplier<RecipeBookCategories> SKILLET_SEARCH = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_SKILLET_SEARCH"));
public static final Supplier<RecipeBookCategories> SKILLET_HEAT = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_SKILLET_HEAT"));
public static final Supplier<RecipeBookCategories> SKILLET_PAN_FRY = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_PAN_FRY"));
public static final Supplier<RecipeBookCategories> SKILLET_STIR_FRY = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_STIR_FRY"));
public static final Supplier<RecipeBookCategories> SKILLET_BOIL = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_BOIL"));
public static final Supplier<RecipeBookCategories> MISC = Suppliers.memoize(() -> RecipeBookCategories.valueOf("lingshi_MISC"));
}
Loading

0 comments on commit 5b5c355

Please sign in to comment.