Skip to content

Commit 11fc73b

Browse files
committed
move scribe grooving logic to recipe
1 parent 1af139e commit 11fc73b

File tree

14 files changed

+337
-123
lines changed

14 files changed

+337
-123
lines changed

src/main/java/galena/oreganized/ModCompat.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ public class ModCompat {
55
public static final String SHIELD_EXPANSION_ID = "shieldexp";
66
public static final String FARMERS_DELIGHT_ID = "farmersdelight";
77
public static final String NETHERS_DELIGHT_ID = "nethersdelight";
8+
public static final String NO_MANS_LAND = "nomansland";
89

910
}

src/main/java/galena/oreganized/Oreganized.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import galena.oreganized.index.OItems;
4040
import galena.oreganized.index.OParticleTypes;
4141
import galena.oreganized.index.OPotions;
42+
import galena.oreganized.index.ORecipeTypes;
4243
import galena.oreganized.index.OSoundEvents;
4344
import galena.oreganized.index.OStructures;
4445
import galena.oreganized.index.OTags;
@@ -127,6 +128,7 @@ public Oreganized(IEventBus modBus, ModContainer container) {
127128
OItems.register();
128129
OCriteriaTriggers.register(modBus);
129130
OSoundEvents.register();
131+
ORecipeTypes.register(modBus);
130132

131133
REGISTRY_HELPER.register(modBus);
132134

src/main/java/galena/oreganized/content/item/ScribeItem.java

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
import galena.oreganized.OreganizedConfig;
88
import galena.oreganized.content.block.ICrystalGlass;
9-
import galena.oreganized.index.OBlocks;
10-
import java.util.HashMap;
11-
import java.util.Map;
12-
import java.util.Set;
13-
import java.util.function.Supplier;
9+
import galena.oreganized.index.ORecipeTypes;
10+
import galena.oreganized.world.recipe.BlockRecipeInput;
1411
import net.minecraft.core.BlockPos;
1512
import net.minecraft.core.Holder;
1613
import net.minecraft.sounds.SoundEvents;
@@ -21,32 +18,16 @@
2118
import net.minecraft.world.item.ItemStack;
2219
import net.minecraft.world.item.Items;
2320
import net.minecraft.world.item.context.UseOnContext;
21+
import net.minecraft.world.item.crafting.RecipeHolder;
2422
import net.minecraft.world.item.enchantment.Enchantment;
2523
import net.minecraft.world.level.Level;
26-
import net.minecraft.world.level.block.AmethystClusterBlock;
2724
import net.minecraft.world.level.block.Block;
28-
import net.minecraft.world.level.block.Blocks;
2925
import net.minecraft.world.level.block.state.BlockState;
26+
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
3027
import net.minecraft.world.level.gameevent.GameEvent;
3128

3229
public class ScribeItem extends Item {
3330

34-
private static final Map<Block, Supplier<Block>> GROOVED_BLOCKS = new HashMap<>();
35-
36-
public static void registerGroovedBlock(Block from, Supplier<Block> to) {
37-
GROOVED_BLOCKS.put(from, to);
38-
}
39-
40-
public static Set<Map.Entry<Block, Supplier<Block>>> getGroovedBlocks() {
41-
return GROOVED_BLOCKS.entrySet();
42-
}
43-
44-
static {
45-
registerGroovedBlock(Blocks.ICE, OBlocks.GROOVED_ICE);
46-
registerGroovedBlock(Blocks.PACKED_ICE, OBlocks.GROOVED_PACKED_ICE);
47-
registerGroovedBlock(Blocks.BLUE_ICE, OBlocks.GROOVED_BLUE_ICE);
48-
}
49-
5031
public ScribeItem(Properties properties) {
5132
super(properties);
5233
}
@@ -76,7 +57,7 @@ private boolean shouldNotSilktouch(ItemStack stack, BlockState state) {
7657

7758
@Override
7859
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
79-
if(OreganizedConfig.COMMON.scribeSilkTouchStone.get()) {
60+
if (OreganizedConfig.COMMON.scribeSilkTouchStone.get()) {
8061
return state.is(SILKTOUCH_WITH_SCRIBE);
8162
} else {
8263
return state.is(MINEABLE_WITH_SCRIBE);
@@ -90,7 +71,7 @@ public boolean isValidRepairItem(ItemStack stack, ItemStack repairStack) {
9071

9172
@Override
9273
public boolean supportsEnchantment(ItemStack stack, Holder<Enchantment> enchantment) {
93-
if(enchantment.is(EnchantmentTags.MINING_EXCLUSIVE)) return true;
74+
if (enchantment.is(EnchantmentTags.MINING_EXCLUSIVE)) return true;
9475
return super.supportsEnchantment(stack, enchantment);
9576
}
9677

@@ -124,16 +105,17 @@ public InteractionResult useOn(UseOnContext context) {
124105
return replaceBlock(context, state.setValue(ICrystalGlass.TYPE, (type + 1) % (ICrystalGlass.MAX_TYPE + 1)), true);
125106
}
126107

127-
var grooved = GROOVED_BLOCKS.get(state.getBlock());
128-
if (grooved != null) {
129-
return replaceBlock(context, grooved.get().defaultBlockState(), true);
130-
}
131-
132-
if (state.getBlock() instanceof AmethystClusterBlock && !state.is(Blocks.SMALL_AMETHYST_BUD)) {
133-
var tool = new ItemStack(Items.IRON_PICKAXE);
134-
tool.applyComponents(context.getItemInHand().getComponents());
135-
Block.dropResources(state, context.getLevel(), context.getClickedPos(), null, context.getPlayer(), tool);
136-
return replaceBlock(context, Blocks.SMALL_AMETHYST_BUD.withPropertiesOf(state), false);
108+
var input = new BlockRecipeInput(new BlockInWorld(context.getLevel(), context.getClickedPos(), false));
109+
var recipe = context.getLevel().getRecipeManager().getRecipeFor(ORecipeTypes.SCRIBE_RECIPE.get(), input, context.getLevel())
110+
.map(RecipeHolder::value)
111+
.orElse(null);
112+
if (recipe != null) {
113+
if (recipe.dropResources()) {
114+
var tool = new ItemStack(Items.IRON_PICKAXE);
115+
tool.applyComponents(context.getItemInHand().getComponents());
116+
Block.dropResources(state, context.getLevel(), context.getClickedPos(), null, context.getPlayer(), tool);
117+
}
118+
return replaceBlock(context, recipe.to().withPropertiesOf(state), !recipe.dropResources());
137119
}
138120

139121
return super.useOn(context);

src/main/java/galena/oreganized/data/OBlockTags.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package galena.oreganized.data;
22

3+
import galena.oreganized.ModCompat;
34
import galena.oreganized.Oreganized;
45
import galena.oreganized.index.DyeColors;
56
import galena.oreganized.index.OBlocks;
@@ -180,17 +181,27 @@ protected void addTags(HolderLookup.Provider provider) {
180181
.add(OBlocks.GROOVED_PACKED_ICE.get())
181182
.add(OBlocks.GROOVED_BLUE_ICE.get());
182183

184+
tag(OTags.Blocks.AMETHYST_CLUSTERS)
185+
.add(Blocks.AMETHYST_CLUSTER)
186+
.add(Blocks.LARGE_AMETHYST_BUD)
187+
.add(Blocks.MEDIUM_AMETHYST_BUD)
188+
.add(Blocks.SMALL_AMETHYST_BUD);
189+
190+
tag(OTags.Blocks.QUARTZITE_CLUSTERS)
191+
.addOptional(ResourceLocation.fromNamespaceAndPath(ModCompat.NO_MANS_LAND, "quartzite_cluster"))
192+
.addOptional(ResourceLocation.fromNamespaceAndPath(ModCompat.NO_MANS_LAND, "large_quartzite_bud"))
193+
.addOptional(ResourceLocation.fromNamespaceAndPath(ModCompat.NO_MANS_LAND, "medium_quartzite_bud"))
194+
.addOptional(ResourceLocation.fromNamespaceAndPath(ModCompat.NO_MANS_LAND, "small_quartzite_bud"));
195+
183196
var scribeMineable = tag(OTags.Blocks.MINEABLE_WITH_SCRIBE)
184197
.addTags(Tags.Blocks.GLASS_BLOCKS)
185198
.addTags(Tags.Blocks.GLASS_PANES)
186199
.addTags(Tags.Blocks.OBSIDIANS)
200+
.addTags(OTags.Blocks.AMETHYST_CLUSTERS)
201+
.addTags(OTags.Blocks.QUARTZITE_CLUSTERS)
187202
.addTags(BlockTags.ICE)
188203
.addTags(BlockTags.CRYSTAL_SOUND_BLOCKS)
189-
.add(Blocks.AMETHYST_BLOCK)
190-
.add(Blocks.AMETHYST_CLUSTER)
191-
.add(Blocks.LARGE_AMETHYST_BUD)
192-
.add(Blocks.MEDIUM_AMETHYST_BUD)
193-
.add(Blocks.SMALL_AMETHYST_BUD);
204+
.add(Blocks.AMETHYST_BLOCK);
194205

195206
scribeMineable
196207
.add(Blocks.QUARTZ_BRICKS)

src/main/java/galena/oreganized/data/ORecipes.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.simibubi.create.content.kinetics.mixer.CompactingRecipe;
1010
import com.simibubi.create.content.kinetics.mixer.MixingRecipe;
1111
import com.simibubi.create.content.processing.recipe.HeatCondition;
12+
import galena.oreganized.ModCompat;
1213
import galena.oreganized.Oreganized;
1314
import galena.oreganized.compat.ColorCompat;
1415
import galena.oreganized.data.provider.ORecipeProvider;
@@ -19,6 +20,7 @@
1920
import java.util.List;
2021
import java.util.concurrent.CompletableFuture;
2122
import net.minecraft.core.HolderLookup;
23+
import net.minecraft.core.registries.BuiltInRegistries;
2224
import net.minecraft.data.PackOutput;
2325
import net.minecraft.data.recipes.RecipeCategory;
2426
import net.minecraft.data.recipes.RecipeOutput;
@@ -166,12 +168,13 @@ protected void buildRecipes(RecipeOutput consumer) {
166168
var unwaxed = ColorCompat.getColoredBlock("concrete_powder", color);
167169
dyed(color, makeWaxed(waxed, unwaxed)).save(consumer);
168170

169-
dyed(color, application(DeployerApplicationRecipe::new, waxed.getId().getPath())
171+
dyed(color, this, () -> application(DeployerApplicationRecipe::new, waxed.getId().getPath())
170172
.output(waxed.get())
171173
.require(unwaxed)
172174
.require(Blocks.HONEYCOMB_BLOCK)
173175
.toolNotConsumed()
174-
).build(consumer);
176+
.build(consumer)
177+
);
175178
});
176179

177180
OBlocks.CRYSTAL_GLASS_PANES.forEach((color, pane) ->
@@ -390,6 +393,15 @@ protected void buildRecipes(RecipeOutput consumer) {
390393

391394
flowerDye(OBlocks.WHITE_DATURA, Items.WHITE_DYE, consumer);
392395
flowerDye(OBlocks.PURPLE_DATURA, Items.PURPLE_DYE, consumer);
396+
397+
scribeConversionAndCutting(consumer, Blocks.ICE, OBlocks.GROOVED_ICE.get());
398+
scribeConversionAndCutting(consumer, Blocks.PACKED_ICE, OBlocks.GROOVED_PACKED_ICE.get());
399+
scribeConversionAndCutting(consumer, Blocks.BLUE_ICE, OBlocks.GROOVED_BLUE_ICE.get());
400+
401+
scribeHarvesting(OTags.Blocks.AMETHYST_CLUSTERS, Blocks.SMALL_AMETHYST_BUD).save(consumer);
402+
scribeHarvesting(OTags.Blocks.QUARTZITE_CLUSTERS, BuiltInRegistries.BLOCK.get(ResourceLocation.fromNamespaceAndPath(ModCompat.NO_MANS_LAND, "small_quartzite_bud")))
403+
.when(ModCompat.NO_MANS_LAND)
404+
.save(consumer);
393405
}
394406

395407
}

src/main/java/galena/oreganized/data/provider/ORecipeProvider.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import galena.oreganized.Oreganized;
1111
import galena.oreganized.index.OItems;
1212
import galena.oreganized.index.OTags;
13+
import galena.oreganized.world.recipe.ScribeRecipe;
1314
import java.util.List;
1415
import java.util.concurrent.CompletableFuture;
1516
import java.util.function.Supplier;
@@ -25,7 +26,6 @@
2526
import net.minecraft.world.level.block.Block;
2627
import net.minecraft.world.level.block.SlabBlock;
2728
import net.neoforged.neoforge.common.Tags;
28-
import net.neoforged.neoforge.common.conditions.ModLoadedCondition;
2929
import vectorwing.farmersdelight.data.builder.CuttingBoardRecipeBuilder;
3030

3131
public abstract class ORecipeProvider extends RecipeProvider {
@@ -243,6 +243,31 @@ public <R extends ItemApplicationRecipe> ItemApplicationRecipe.Builder<R> applic
243243
);
244244
}
245245

246+
public ScribeRecipe.Builder scribeConversion(Block from, Block to) {
247+
return new ScribeRecipe.Builder()
248+
.from(from)
249+
.result(to);
250+
}
251+
252+
public ScribeRecipe.Builder scribeHarvesting(TagKey<Block> from, Block to) {
253+
return new ScribeRecipe.Builder()
254+
.from(from)
255+
.result(to)
256+
.dropResources();
257+
}
258+
259+
public CuttingBoardRecipeBuilder scribeCuttingBoard(ItemLike from, ItemLike to) {
260+
return CuttingBoardRecipeBuilder.cuttingRecipe(Ingredient.of(from), Ingredient.of(OItems.SCRIBE.asItem()), to);
261+
}
262+
263+
public void scribeConversionAndCutting(RecipeOutput output, Block from, Block to) {
264+
var id = RecipeBuilder.getDefaultRecipeId(to);
265+
scribeConversion(from, to).save(output, id);
266+
Conditional.with(this, List.of(new ModLoaded(ModCompat.FARMERS_DELIGHT_ID)), () -> {
267+
scribeCuttingBoard(from, to).save(output, id);
268+
});
269+
}
270+
246271
public void flowerDye(Supplier<? extends ItemLike> flower, ItemLike primary, RecipeOutput consumer) {
247272
var name = getItemName(flower.get());
248273

@@ -257,8 +282,10 @@ public void flowerDye(Supplier<? extends ItemLike> flower, ItemLike primary, Rec
257282
.output(0.05F, Items.GREEN_DYE)
258283
.build(consumer);
259284

260-
CuttingBoardRecipeBuilder.cuttingRecipe(Ingredient.of(flower.get()), Ingredient.of(OTags.Items.TOOLS_KNIVES), primary, 2)
261-
.save(consumer.withConditions(new ModLoadedCondition(ModCompat.FARMERS_DELIGHT_ID)));
285+
Conditional.with(this, List.of(new ModLoaded(ModCompat.FARMERS_DELIGHT_ID)), () -> {
286+
CuttingBoardRecipeBuilder.cuttingRecipe(Ingredient.of(flower.get()), Ingredient.of(OTags.Items.TOOLS_KNIVES), primary, 2)
287+
.save(consumer);
288+
});
262289
}
263290

264291
public <T> T unlessLoaded(T value, String... modIds) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package galena.oreganized.index;
2+
3+
import galena.oreganized.Oreganized;
4+
import galena.oreganized.world.recipe.ScribeRecipe;
5+
import net.minecraft.core.registries.Registries;
6+
import net.minecraft.world.item.crafting.RecipeSerializer;
7+
import net.minecraft.world.item.crafting.RecipeType;
8+
import net.neoforged.bus.api.IEventBus;
9+
import net.neoforged.neoforge.registries.DeferredHolder;
10+
import net.neoforged.neoforge.registries.DeferredRegister;
11+
12+
public class ORecipeTypes {
13+
14+
private static final DeferredRegister<RecipeType<?>> TYPES = DeferredRegister.create(Registries.RECIPE_TYPE, Oreganized.MOD_ID);
15+
private static final DeferredRegister<RecipeSerializer<?>> SERIALIZERS = DeferredRegister.create(Registries.RECIPE_SERIALIZER, Oreganized.MOD_ID);
16+
17+
public static final DeferredHolder<RecipeType<?>, RecipeType<ScribeRecipe>> SCRIBE_RECIPE = TYPES.register("scribe", () -> new RecipeType<>() {
18+
});
19+
public static final DeferredHolder<RecipeSerializer<?>, RecipeSerializer<ScribeRecipe>> SCRIBE_SERIALIZER = SERIALIZERS.register(SCRIBE_RECIPE.getId().getPath(), ScribeRecipe.Serializer::new);
20+
21+
public static void register(IEventBus modBus) {
22+
SERIALIZERS.register(modBus);
23+
TYPES.register(modBus);
24+
}
25+
26+
}

src/main/java/galena/oreganized/index/OTags.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public static class Blocks {
106106
public static final TagKey<Block> BOMB_BREAKABLE = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("supplementaries", "bomb_breakable"));
107107
public static final TagKey<Block> CANNON_TNTS = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("supplementaries", "cannon_tnts"));
108108

109+
public static final TagKey<Block> AMETHYST_CLUSTERS = forgeTag("clusters/amethyst");
110+
public static final TagKey<Block> QUARTZITE_CLUSTERS = forgeTag("clusters/quartzite");
111+
109112
private static TagKey<Block> tag(String name) {
110113
return TagKey.create(Registries.BLOCK, Oreganized.modLoc(name));
111114
}

src/main/java/galena/oreganized/mixin/compat/LogStrippingFakeRecipesMixin.java

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,62 @@
66
import com.simibubi.create.content.processing.recipe.ProcessingOutput;
77
import com.simibubi.create.foundation.data.recipe.LogStrippingFakeRecipes;
88
import galena.oreganized.Oreganized;
9-
import galena.oreganized.content.item.ScribeItem;
109
import galena.oreganized.index.OItems;
10+
import galena.oreganized.index.ORecipeTypes;
1111
import java.util.ArrayList;
1212
import java.util.List;
13-
import net.minecraft.core.registries.BuiltInRegistries;
13+
import java.util.Optional;
14+
import net.minecraft.advancements.critereon.BlockPredicate;
15+
import net.minecraft.client.Minecraft;
16+
import net.minecraft.core.Holder;
17+
import net.minecraft.world.item.Item;
1418
import net.minecraft.world.item.ItemStack;
1519
import net.minecraft.world.item.crafting.Ingredient;
1620
import net.minecraft.world.item.crafting.RecipeHolder;
21+
import net.minecraft.world.level.block.Block;
1722
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Unique;
1824
import org.spongepowered.asm.mixin.injection.At;
1925

2026
@Mixin(value = LogStrippingFakeRecipes.class, remap = false)
2127
public class LogStrippingFakeRecipesMixin {
2228

29+
@Unique
30+
private static Optional<Ingredient> createIngredient(BlockPredicate predicate, Block exclude) {
31+
return predicate.blocks().map(holderSet -> {
32+
var items = holderSet.stream()
33+
.map(Holder::value)
34+
.filter(it -> it != exclude)
35+
.map(Block::asItem)
36+
.map(Item::getDefaultInstance);
37+
return Ingredient.of(items);
38+
}).filter(it -> !it.isEmpty());
39+
}
40+
2341
@ModifyReturnValue(method = "createRecipes", at = @At("RETURN"), require = 0)
2442
private static List<RecipeHolder<ManualApplicationRecipe>> addGroovedRecipes(List<RecipeHolder<ManualApplicationRecipe>> value) {
2543
var newList = new ArrayList<>(value);
2644

27-
ScribeItem.getGroovedBlocks().forEach(entry -> {
28-
var blockId = BuiltInRegistries.BLOCK.getKey(entry.getKey()).getPath();
29-
var id = Oreganized.modLoc("manual_application/" + blockId);
30-
var recipe = new ItemApplicationRecipe.Builder<>(ManualApplicationRecipe::new, id)
31-
.withItemIngredients(Ingredient.of(entry.getKey()), Ingredient.of(OItems.SCRIBE.get()))
32-
.withItemOutputs(new ProcessingOutput(new ItemStack(entry.getValue().get()), 1F))
33-
.toolNotConsumed()
34-
.build();
35-
newList.add(new RecipeHolder<>(id, recipe));
36-
});
45+
var connection = Minecraft.getInstance().getConnection();
46+
if (connection == null) return value;
47+
48+
var manager = connection.getRecipeManager();
49+
var recipes = manager.getAllRecipesFor(ORecipeTypes.SCRIBE_RECIPE.get());
50+
51+
recipes.stream()
52+
.filter(it -> !it.value().dropResources())
53+
.forEach(holder -> {
54+
createIngredient(holder.value().from(), holder.value().to()).ifPresentOrElse(from -> {
55+
var recipe = new ItemApplicationRecipe.Builder<>(ManualApplicationRecipe::new, holder.id())
56+
.withItemIngredients(from, Ingredient.of(OItems.SCRIBE.get()))
57+
.withItemOutputs(new ProcessingOutput(new ItemStack(holder.value().to()), 1F))
58+
.toolNotConsumed()
59+
.build();
60+
newList.add(new RecipeHolder<>(holder.id(), recipe));
61+
}, () -> {
62+
Oreganized.LOGGER.warn("unable to convert scribe recipe {}", holder.id());
63+
});
64+
});
3765

3866
return newList;
3967
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package galena.oreganized.world.recipe;
2+
3+
import net.minecraft.world.item.ItemStack;
4+
import net.minecraft.world.item.crafting.RecipeInput;
5+
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
6+
7+
public record BlockRecipeInput(BlockInWorld block) implements RecipeInput {
8+
9+
@Override
10+
public ItemStack getItem(int i) {
11+
return block.getState().getBlock().asItem().getDefaultInstance();
12+
}
13+
14+
@Override
15+
public int size() {
16+
return 1;
17+
}
18+
19+
}

0 commit comments

Comments
 (0)