mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add tool interaction recipe hooks
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package dev.architectury.hooks.item.tool;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.world.item.AxeItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class AxeItemHooks {
|
||||
private AxeItemHooks() {
|
||||
}
|
||||
|
||||
public static void addStrippingRecipe(Block src, Block dst) {
|
||||
if (AxeItem.STRIPPABLES instanceof ImmutableMap) {
|
||||
AxeItem.STRIPPABLES = new HashMap<>(AxeItem.STRIPPABLES);
|
||||
}
|
||||
AxeItem.STRIPPABLES.put(src, dst);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.architectury.hooks.item.tool;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.world.item.HoeItem;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class HoeItemHooks {
|
||||
private HoeItemHooks() {
|
||||
}
|
||||
|
||||
public static void addTillingRecipe(Block src, Predicate<UseOnContext> predicate, Consumer<UseOnContext> action) {
|
||||
if (HoeItem.TILLABLES instanceof ImmutableMap) {
|
||||
HoeItem.TILLABLES = new HashMap<>(HoeItem.TILLABLES);
|
||||
}
|
||||
HoeItem.TILLABLES.put(src, new Pair<>(predicate, action));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.architectury.hooks.item.tool;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.world.item.ShovelItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class ShovelItemHooks {
|
||||
private ShovelItemHooks() {
|
||||
}
|
||||
|
||||
public static void addFlatteningRecipe(Block src, BlockState dst) {
|
||||
if (ShovelItem.FLATTENABLES instanceof ImmutableMap) {
|
||||
ShovelItem.FLATTENABLES = new HashMap<>(ShovelItem.FLATTENABLES);
|
||||
}
|
||||
ShovelItem.FLATTENABLES.put(src, dst);
|
||||
}
|
||||
}
|
||||
@@ -40,4 +40,10 @@ mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAdditio
|
||||
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional;
|
||||
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional;
|
||||
accessible method net/minecraft/world/level/storage/LevelResource <init> (Ljava/lang/String;)V
|
||||
accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier
|
||||
accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier
|
||||
accessible field net/minecraft/world/item/AxeItem STRIPPABLES Ljava/util/Map;
|
||||
mutable field net/minecraft/world/item/AxeItem STRIPPABLES Ljava/util/Map;
|
||||
accessible field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map;
|
||||
mutable field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map;
|
||||
accessible field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;
|
||||
mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;
|
||||
@@ -98,4 +98,10 @@ mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAdditio
|
||||
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional;
|
||||
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional;
|
||||
accessible method net/minecraft/world/level/storage/LevelResource <init> (Ljava/lang/String;)V
|
||||
accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier
|
||||
accessible class net/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier
|
||||
accessible field net/minecraft/world/item/AxeItem STRIPPABLES Ljava/util/Map;
|
||||
mutable field net/minecraft/world/item/AxeItem STRIPPABLES Ljava/util/Map;
|
||||
accessible field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map;
|
||||
mutable field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map;
|
||||
accessible field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;
|
||||
mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;
|
||||
@@ -45,3 +45,6 @@ public net.minecraft.world.level.GameRules$IntegerValue m_46294_(ILjava/util/fun
|
||||
public net.minecraft.client.particle.ParticleEngine f_107296_ # textureAtlas
|
||||
public net.minecraft.client.particle.ParticleEngine$MutableSpriteSet
|
||||
public net.minecraft.client.particle.ParticleEngine$MutableSpriteSet f_107406_ # sprites
|
||||
public-f net.minecraft.world.item.AxeItem f_150683_ # STRIPPABLES
|
||||
public-f net.minecraft.world.item.ShovelItem f_43110_ # FLATTENABLES
|
||||
public-f net.minecraft.world.item.HoeItem f_41332_ # TILLABLES
|
||||
|
||||
@@ -29,6 +29,7 @@ import dev.architectury.test.events.DebugEvents;
|
||||
import dev.architectury.test.gamerule.TestGameRules;
|
||||
import dev.architectury.test.networking.TestModNet;
|
||||
import dev.architectury.test.particle.TestParticles;
|
||||
import dev.architectury.test.recipe.TestRecipes;
|
||||
import dev.architectury.test.registry.TestRegistries;
|
||||
import dev.architectury.test.registry.client.TestKeybinds;
|
||||
import dev.architectury.test.tags.TestTags;
|
||||
@@ -52,6 +53,7 @@ public class TestMod {
|
||||
TestTrades.init();
|
||||
TestParticles.initialize();
|
||||
TestModNet.initialize();
|
||||
TestRecipes.init();
|
||||
if (Platform.getEnvironment() == Env.CLIENT) {
|
||||
initializeClient();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.architectury.test.recipe;
|
||||
|
||||
import dev.architectury.hooks.item.tool.AxeItemHooks;
|
||||
import dev.architectury.hooks.item.tool.HoeItemHooks;
|
||||
import dev.architectury.hooks.item.tool.ShovelItemHooks;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
public final class TestRecipes {
|
||||
private TestRecipes() {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
AxeItemHooks.addStrippingRecipe(Blocks.QUARTZ_PILLAR, Blocks.OAK_LOG);
|
||||
ShovelItemHooks.addFlatteningRecipe(Blocks.IRON_ORE, Blocks.DIAMOND_BLOCK.defaultBlockState());
|
||||
HoeItemHooks.addTillingRecipe(Blocks.COAL_BLOCK, ctx -> {
|
||||
if (!ctx.getLevel().isNight()) {
|
||||
if (!ctx.getLevel().isClientSide) {
|
||||
Player player = ctx.getPlayer();
|
||||
if (player != null)
|
||||
player.sendMessage(new TextComponent("These dark arts can only be done at night!"), Util.NIL_UUID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, ctx -> {
|
||||
BlockPos pos = ctx.getClickedPos();
|
||||
ctx.getLevel().setBlock(pos, Blocks.DIAMOND_BLOCK.defaultBlockState(), 3);
|
||||
if (!ctx.getLevel().isClientSide) {
|
||||
Player player = ctx.getPlayer();
|
||||
if (player != null)
|
||||
player.sendMessage(new TextComponent("Thou has successfully committed the dark arts of alchemy!!"), Util.NIL_UUID);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user