Skip to content

Commit

Permalink
Merge branch 'Gu-ZT:releases/1.20.1' into releases/1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BOTXue authored Apr 12, 2024
2 parents 170e9b7 + 7be36df commit 049ecbd
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import net.minecraft.world.phys.Vec3;

public class StampingRecipesLoader {


public static void init(RegistrateRecipeProvider provider) {
/**
* 初始化配方
*
* @param provider 配方提供器
*/
public static void init(RegistrateRecipeProvider provider) {
stamping(Items.IRON_INGOT, Items.HEAVY_WEIGHTED_PRESSURE_PLATE, provider);
stamping(Items.GOLD_INGOT, Items.LIGHT_WEIGHTED_PRESSURE_PLATE, provider);
stamping(Items.SUGAR_CANE, Items.PAPER, provider);
Expand All @@ -32,23 +35,39 @@ public static void init(RegistrateRecipeProvider provider) {
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.hasBlock(ModBlocks.STAMPING_PLATFORM.get())
.hasItemIngredient(new Vec3(0.0, -0.75, 0.0), Items.HEART_OF_THE_SEA)
.spawnItem(new Vec3(0.0, -0.75, 0.0), ModItems.SEA_HEART_SHELL_SHARD,3)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5,ModItems.SEA_HEART_SHELL_SHARD)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5,ModItems.SEA_HEART_SHELL_SHARD)
.spawnItem(new Vec3(0.0, -0.75, 0.0), ModItems.SEA_HEART_SHELL_SHARD, 3)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5, ModItems.SEA_HEART_SHELL_SHARD)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5, ModItems.SEA_HEART_SHELL_SHARD)
.spawnItem(new Vec3(0.0, -0.75, 0.0), ModItems.SAPPHIRE)
.unlockedBy(AnvilCraftDatagen.hasItem(Items.HEART_OF_THE_SEA), AnvilCraftDatagen.has(Items.HEART_OF_THE_SEA))
.save(provider, AnvilCraft.of("stamping/sea_heart_shell_shard"));
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.hasBlock(ModBlocks.STAMPING_PLATFORM.get())
.hasItemIngredient(new Vec3(0.0, -0.75, 0.0), ModItems.PRISMARINE_CLUSTER)
.spawnItem(new Vec3(0.0, -0.75, 0.0),0.15, ModItems.PRISMARINE_BLADE)
.spawnItem(new Vec3(0.0, -0.75, 0.0), Items.PRISMARINE_CRYSTALS,2)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.15, ModItems.PRISMARINE_BLADE)
.spawnItem(new Vec3(0.0, -0.75, 0.0), Items.PRISMARINE_CRYSTALS, 2)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5, Items.PRISMARINE_CRYSTALS)
.spawnItem(new Vec3(0.0, -0.75, 0.0), Items.PRISMARINE_SHARD)
.unlockedBy(AnvilCraftDatagen.hasItem(ModItems.PRISMARINE_CLUSTER.get()), AnvilCraftDatagen.has(ModItems.PRISMARINE_CLUSTER))
.save(provider, AnvilCraft.of("stamping/prismarine_blade"));
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.hasBlock(ModBlocks.STAMPING_PLATFORM.get())
.hasItemIngredient(new Vec3(0.0, -0.75, 0.0), ModItems.GEODE)
.spawnItem(new Vec3(0.0, -0.75, 0.0), Items.AMETHYST_SHARD, 2)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.25, ModItems.TOPAZ)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.25, ModItems.SAPPHIRE)
.spawnItem(new Vec3(0.0, -0.75, 0.0), 0.25, ModItems.RUBY)
.unlockedBy(AnvilCraftDatagen.hasItem(ModItems.PRISMARINE_CLUSTER.get()), AnvilCraftDatagen.has(ModItems.PRISMARINE_CLUSTER))
.save(provider, AnvilCraft.of("stamping/geode_2_jewel"));
}

/**
* 生成简单冲压配方
*
* @param item 原料
* @param item1 产物
* @param provider 配方提供器
*/
public static void stamping(Item item, Item item1, RegistrateRecipeProvider provider) {
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.hasBlock(ModBlocks.STAMPING_PLATFORM.get())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_prismarine_cluster": {
"conditions": {
"items": [
{
"items": [
"anvilcraft:prismarine_cluster"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "anvilcraft:stamping/geode_2_jewel"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_prismarine_cluster",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"anvilcraft:stamping/geode_2_jewel"
]
},
"sends_telemetry_event": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"type": "anvilcraft:anvil_processing",
"icon": {
"count": 2,
"item": "minecraft:amethyst_shard"
},
"outcomes": [
{
"type": "spawn_item",
"chance": 1.0,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"count": 2,
"item": "minecraft:amethyst_shard"
}
},
{
"type": "spawn_item",
"chance": 0.25,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"item": "anvilcraft:topaz"
}
},
{
"type": "spawn_item",
"chance": 0.25,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"item": "anvilcraft:sapphire"
}
},
{
"type": "spawn_item",
"chance": 0.25,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"item": "anvilcraft:ruby"
}
}
],
"predicates": [
{
"type": "has_block",
"match_block": {
"blocks": [
"anvilcraft:stamping_platform"
]
},
"offset": [
0.0,
-1.0,
0.0
]
},
{
"type": "has_item_ingredient",
"match_item": {
"count": {
"min": 1
},
"items": [
"anvilcraft:geode"
]
},
"offset": [
0.0,
-0.75,
0.0
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.dubhe.anvilcraft.init.ModCommands;
import dev.dubhe.anvilcraft.init.fabric.ModRecipeTypesFabric;
import dev.dubhe.anvilcraft.listener.fabric.AnvilHammerListener;
import dev.dubhe.anvilcraft.listener.fabric.LootTableListener;
import dev.dubhe.anvilcraft.utils.fabric.ServerHooks;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
Expand All @@ -15,6 +16,7 @@ public void onInitialize() {
ServerHooks.init();
ModRecipeTypesFabric.register();
AnvilHammerListener.register();
LootTableListener.register();
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ModCommands.register(dispatcher));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.dubhe.anvilcraft.listener.fabric;

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.init.ModItems;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;

public class LootTableListener {
/**
* 修改战利品表
*/
public static void register() {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
if (Blocks.BUDDING_AMETHYST.getLootTable().equals(id)) {
tableBuilder.withPool(new LootPool.Builder()
.add(LootItem.lootTableItem(ModItems.GEODE))
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(1)))
);
}
if (BuiltInLootTables.SPAWN_BONUS_CHEST.equals(id)) {
tableBuilder.withPool(new LootPool.Builder()
.add(LootItem.lootTableItem(ModItems.GEODE))
.apply(SetItemCountFunction.setCount(UniformGenerator.between(3, 6)))
);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_prismarine_cluster": {
"conditions": {
"items": [
{
"items": [
"anvilcraft:prismarine_cluster"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "anvilcraft:stamping/geode_2_jewel"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_prismarine_cluster",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"anvilcraft:stamping/geode_2_jewel"
]
},
"sends_telemetry_event": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"type": "anvilcraft:anvil_processing",
"icon": {
"count": 2,
"item": "minecraft:amethyst_shard"
},
"outcomes": [
{
"type": "spawn_item",
"chance": 1.0,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"count": 2,
"item": "minecraft:amethyst_shard"
}
},
{
"type": "spawn_item",
"chance": 0.25,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"item": "anvilcraft:topaz"
}
},
{
"type": "spawn_item",
"chance": 0.25,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"item": "anvilcraft:sapphire"
}
},
{
"type": "spawn_item",
"chance": 0.25,
"offset": [
0.0,
-0.75,
0.0
],
"result": {
"item": "anvilcraft:ruby"
}
}
],
"predicates": [
{
"type": "has_block",
"match_block": {
"blocks": [
"anvilcraft:stamping_platform"
]
},
"offset": [
0.0,
-1.0,
0.0
]
},
{
"type": "has_item_ingredient",
"match_item": {
"count": {
"min": 1
},
"items": [
"anvilcraft:geode"
]
},
"offset": [
0.0,
-0.75,
0.0
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public AnvilCraftForge() {
AnvilCraft.init();
bus.register(new ModRecipeTypesForge());
MinecraftForge.EVENT_BUS.addListener(AnvilCraftForge::registerCommand);
MinecraftForge.EVENT_BUS.register(new AnvilHammerListener());

ModLoadingContext.get().registerExtensionPoint(
ConfigScreenHandler.ConfigScreenFactory.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package dev.dubhe.anvilcraft.listener;

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.item.AnvilHammerItem;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.NotNull;

@Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID)
public class AnvilHammerListener {
@SubscribeEvent
public void anvilHammer(PlayerInteractEvent.LeftClickBlock leftClickBlock) {
if (leftClickBlock.getEntity().getItemInHand(leftClickBlock.getEntity().getUsedItemHand()).getItem() instanceof AnvilHammerItem anvilHammer) {
public static void anvilHammer(@NotNull PlayerInteractEvent.LeftClickBlock leftClickBlock) {
if (leftClickBlock.getEntity().getItemInHand(leftClickBlock.getEntity().getUsedItemHand()).getItem()
instanceof AnvilHammerItem anvilHammer) {
anvilHammer.useAttackBlock(leftClickBlock.getEntity(), leftClickBlock.getPos(), leftClickBlock.getLevel());
}
}
Expand Down
Loading

0 comments on commit 049ecbd

Please sign in to comment.