Skip to content

Commit

Permalink
铁砧处理物品配方
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Mar 5, 2024
1 parent 2933998 commit 2a9636e
Show file tree
Hide file tree
Showing 58 changed files with 1,719 additions and 403 deletions.
16 changes: 14 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ base {

repositories {
maven {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org'
name 'ParchmentMC'
url 'https://maven.parchmentmc.org'
}
maven {
name 'REI'
url 'https://maven.shedaniel.me/'
}
maven {
name 'ModMenu'
url 'https://maven.terraformersmc.com/releases/'
}
}

Expand Down Expand Up @@ -42,6 +50,10 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modApi "com.terraformersmc:modmenu:${project.modmenu_version}"
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:${project.rei_version}"
compileOnly "org.projectlombok:lombok:${lombok_version}"
annotationProcessor "org.projectlombok:lombok:${lombok_version}"
}
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ org.gradle.jvmargs=-Xmx1G
# check this on https://modmuss50.me/fabric.html
fabric_version=0.92.0+1.20.1
lombok_version=1.18.30
rei_version=12.0.684
modmenu_version=7.1.0
16 changes: 14 additions & 2 deletions src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package dev.dubhe.anvilcraft;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.datafixers.util.Pair;
import com.mojang.logging.LogUtils;
import dev.dubhe.anvilcraft.api.events.EventManager;
import dev.dubhe.anvilcraft.block.ModBlocks;
import dev.dubhe.anvilcraft.data.crafting.ModRecipeTypes;
import dev.dubhe.anvilcraft.data.recipe.ModRecipeTypes;
import dev.dubhe.anvilcraft.event.listener.AnvilEventListener;
import dev.dubhe.anvilcraft.item.ModItems;
import dev.dubhe.anvilcraft.log.Logger;
import net.fabricmc.api.ModInitializer;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -13,14 +19,20 @@
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

@SuppressWarnings("unused")
public class AnvilCraft implements ModInitializer {
public static final String MOD_ID = "anvilcraft";
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final Logger LOGGER = new Logger(LogUtils.getLogger());
public static final EventManager EVENT_BUS = new EventManager();

@Override
public void onInitialize() {
AnvilCraft.EVENT_BUS.register(new AnvilEventListener());
for (Map.Entry<String, Block> entry : ModBlocks.BLOCK_MAP.entrySet()) {
Registry.register(BuiltInRegistries.BLOCK, AnvilCraft.of(entry.getKey()), entry.getValue());
}
Expand All @@ -38,7 +50,7 @@ public void onInitialize() {
}
}

public static ResourceLocation of(String id) {
public static @NotNull ResourceLocation of(String id) {
return new ResourceLocation(MOD_ID, id);
}
}
51 changes: 51 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/api/events/EventManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.dubhe.anvilcraft.api.events;

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.event.SubscribeEvent;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

@SuppressWarnings("unused")
public class EventManager {
public final Map<Class<?>, List<Consumer<?>>> EVENT_LISTENER = new ConcurrentHashMap<>();

public <E> void listen(Class<E> event, Consumer<E> trigger) {
List<Consumer<?>> triggers = EVENT_LISTENER.getOrDefault(event, new Vector<>());
triggers.add(trigger);
EVENT_LISTENER.putIfAbsent(event, triggers);
}

@SuppressWarnings("all")
public <E> void post(E event) {
List<Consumer<?>> triggers = EVENT_LISTENER.getOrDefault(event.getClass(), new Vector<>());
for (Consumer<?> trigger : triggers) {
((Consumer<E>) trigger).accept(event);
}
}

public void register(@NotNull Object object) {
for (Method method : object.getClass().getMethods()) {
if (method.getParameterCount() != 1) continue;
SubscribeEvent annotation = method.getAnnotation(SubscribeEvent.class);
if (null == annotation) continue;
Class<?> event = method.getParameterTypes()[0];
Consumer<?> trigger = (obj) -> {
try {
method.invoke(object, obj);
} catch (IllegalAccessException | InvocationTargetException e) {
AnvilCraft.LOGGER.printStackTrace(e);
}
};
List<Consumer<?>> triggers = EVENT_LISTENER.getOrDefault(event, new Vector<>());
triggers.add(trigger);
EVENT_LISTENER.putIfAbsent(event, triggers);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/dev/dubhe/anvilcraft/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ModBlocks {

public static final Block MAGNET_BLOCK = registerBlock("magnet_block", Block::new, BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK));
public static final Block HOLLOW_MAGNET_BLOCK = registerBlock("hollow_magnet_block", HollowMagnetBlock::new, BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK));
public static final Block FERRITE_CORE_MAGNET_BLOCK = registerBlock("ferrite_core_magnet_block", FerriteCoreMagnetBlock::new, BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK));
public static final Block FERRITE_CORE_MAGNET_BLOCK = registerBlock("ferrite_core_magnet_block", FerriteCoreMagnetBlock::new, BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK).randomTicks());
public static final Block INTERACT_MACHINE = registerBlock("interact_machine", Block::new, BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK));


private static Block registerBlock(String id, @NotNull Function<BlockBehaviour.Properties, Block> blockCreator, BlockBehaviour.Properties properties) {
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/dev/dubhe/anvilcraft/data/MyRecipesGenerator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.dubhe.anvilcraft.data;

import dev.dubhe.anvilcraft.data.crafting.ShapedTagRecipeBuilder;
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.data.recipe.anvil.item.ItemAnvilRecipe;
import dev.dubhe.anvilcraft.data.recipe.anvil.item.ItemAnvilRecipeBuilder;
import dev.dubhe.anvilcraft.data.recipe.crafting_table.ShapedTagRecipeBuilder;
import dev.dubhe.anvilcraft.item.ModItemTags;
import dev.dubhe.anvilcraft.item.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
Expand All @@ -10,6 +13,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;
Expand Down Expand Up @@ -244,8 +248,21 @@ public void buildRecipes(Consumer<FinishedRecipe> exporter) {
.unlockedBy(hasItem(Items.LILY_OF_THE_VALLEY), FabricRecipeProvider.has(Items.LILY_OF_THE_VALLEY))
.unlockedBy(hasItem(Items.WITHER_ROSE), FabricRecipeProvider.has(Items.WITHER_ROSE))
.save(exporter);
SimpleCookingRecipeBuilder.campfireCooking(Ingredient.of(ModItemTags.DOUGH), RecipeCategory.FOOD, Items.BREAD, 0.35f, 600);
SimpleCookingRecipeBuilder.smoking(Ingredient.of(ModItemTags.DOUGH), RecipeCategory.FOOD, Items.BREAD, 0.35f, 100);
SimpleCookingRecipeBuilder.campfireCooking(Ingredient.of(ModItemTags.DOUGH), RecipeCategory.FOOD, Items.BREAD, 0.35f, 600)
.unlockedBy(hasItem(ModItems.DOUGH), FabricRecipeProvider.has(ModItems.DOUGH))
.save(exporter, AnvilCraft.of("campfire_cooking_bread"));
SimpleCookingRecipeBuilder.smoking(Ingredient.of(ModItemTags.DOUGH), RecipeCategory.FOOD, Items.BREAD, 0.35f, 100)
.unlockedBy(hasItem(ModItems.DOUGH), FabricRecipeProvider.has(ModItems.DOUGH))
.save(exporter, AnvilCraft.of("smoking_bread"));
ItemAnvilRecipeBuilder.item(RecipeCategory.TOOLS, ModItems.INTERACT_MACHINE)
.requires(Items.ANVIL)
.requires(Items.DISPENSER)
.component(Blocks.CAULDRON)
.location(ItemAnvilRecipe.Location.IN)
.resultLocation(ItemAnvilRecipe.Location.IN)
.unlockedBy(hasItem(Items.ANVIL), FabricRecipeProvider.has(Items.ANVIL))
.unlockedBy(hasItem(Items.DISPENSER), FabricRecipeProvider.has(Items.DISPENSER))
.save(exporter);
}

public static @NotNull String hasItem(@NotNull Item item) {
Expand Down

This file was deleted.

Loading

0 comments on commit 2a9636e

Please sign in to comment.