Skip to content

Commit 29ac71f

Browse files
authored
Enhanced Furnace Compat (#331)
* extract the hash strategy, rename field * add custom time and fuel conversion * add defaultValue documentation for furnace * remove unused method * change reload logic for time * create custom class for itemstack set logic * apply that class * fix inputs being added to set when invalid * adjust removal methods and dont modify metadata * move time to proxy map * proxy to getInt * adjust error message, fix example * removeFuelConversionBySmeltedStack * remove unused file
1 parent ae1eac1 commit 29ac71f

File tree

10 files changed

+336
-170
lines changed

10 files changed

+336
-170
lines changed

examples/postInit/minecraft.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ mods.minecraft.crafting.shapelessBuilder()
159159
// mods.minecraft.crafting.replaceShapeless('minecraft:pink_dye_from_pink_tulp', item('minecraft:clay'), [item('minecraft:nether_star')])
160160

161161
// Furnace:
162-
// Converts an input item into an output itemstack after a set amount of time, with the ability to give experience and
163-
// using fuel to run.
162+
// Converts an input item into an output itemstack after a configurable amount of time, with the ability to give experience
163+
// and using fuel to run. Can also convert the item in the fuel slot.
164164

165-
mods.minecraft.furnace.removeByInput(item('minecraft:clay'))
165+
mods.minecraft.furnace.removeByInput(item('minecraft:clay:*'))
166166
mods.minecraft.furnace.removeByOutput(item('minecraft:brick'))
167+
mods.minecraft.furnace.removeFuelConversionBySmeltedStack(item('minecraft:sponge', 1))
167168
// mods.minecraft.furnace.removeAll()
169+
// mods.minecraft.furnace.removeAllFuelConversions()
168170

169171
mods.minecraft.furnace.recipeBuilder()
170172
.input(ore('ingotGold'))
@@ -175,6 +177,8 @@ mods.minecraft.furnace.recipeBuilder()
175177

176178
// mods.minecraft.furnace.add(ore('ingotIron'), item('minecraft:diamond'))
177179
mods.minecraft.furnace.add(item('minecraft:nether_star'), item('minecraft:clay') * 64, 13)
180+
mods.minecraft.furnace.add(item('minecraft:diamond'), item('minecraft:clay'), 2, 50)
181+
mods.minecraft.furnace.addFuelConversion(item('minecraft:diamond'), item('minecraft:bucket').transform(item('minecraft:lava_bucket')))
178182

179183
// Default GameRules:
180184
// Create or assign a default value to GameRules.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.cleanroommc.groovyscript.compat.vanilla;
2+
3+
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
4+
import com.cleanroommc.groovyscript.api.IIngredient;
5+
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
6+
import com.cleanroommc.groovyscript.helper.ingredient.itemstack.ItemStack2IntProxyMap;
7+
import com.github.bsideup.jabel.Desugar;
8+
import net.minecraft.init.Blocks;
9+
import net.minecraft.init.Items;
10+
import net.minecraft.item.Item;
11+
import net.minecraft.item.ItemStack;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
@GroovyBlacklist
17+
public class CustomFurnaceManager {
18+
19+
/**
20+
* Time an itemstack takes to smelt.
21+
* <p>
22+
* By default, minecraft uses 200 ticks for everything, GroovyScript uses a mixin to allow variable times to smelt.
23+
*
24+
* @see com.cleanroommc.groovyscript.core.mixin.furnace.TileEntityFurnaceMixin TileEntityFurnaceMixin
25+
*/
26+
public static final ItemStack2IntProxyMap TIME_MAP = new ItemStack2IntProxyMap();
27+
28+
/**
29+
* Recipes for converting the fuel slot of a furnace into another item when a valid item is smelted.
30+
* <p>
31+
* By default, minecraft has custom logic to make smelting a wet sponge convert an empty bucket into a water bucket.
32+
*
33+
* @see com.cleanroommc.groovyscript.core.mixin.furnace.TileEntityFurnaceMixin TileEntityFurnaceMixin
34+
* @see FuelConversionRecipe
35+
*/
36+
public static final List<FuelConversionRecipe> FUEL_TRANSFORMERS = new ArrayList<>();
37+
38+
static {
39+
// reproduce the vanilla logic for converting empty buckets into water buckets on smelting wet sponge
40+
// in groovyscript this would be `furnace.addFuelConversion(item('minecraft:sponge', 1), item('minecraft:bucket').transform(item('minecraft:water_bucket')))`
41+
var bucket = IngredientHelper.toIIngredient(((ItemStackMixinExpansion) (Object) (new ItemStack(Items.BUCKET))).transform(new ItemStack(Items.WATER_BUCKET)));
42+
var wetSponge = IngredientHelper.toIIngredient(new ItemStack(Item.getItemFromBlock(Blocks.SPONGE), 1, 1));
43+
FUEL_TRANSFORMERS.add(new FuelConversionRecipe(wetSponge, bucket));
44+
}
45+
46+
/**
47+
* When the smelted ItemStack passes the {@link #smelted} filter and the {@link #fuel} filter,
48+
* the {@link #fuel} IIngredient will use {@link IIngredient#applyTransform(ItemStack)} to convert the fuel stack.
49+
*
50+
* @param smelted an IIngredient that is checked against the item being smelted
51+
* @param fuel an IIngredient that is checked against the fuel item, and if it passes uses {@link IIngredient#applyTransform(ItemStack)} to convert the fuel item.
52+
*/
53+
@Desugar
54+
public record FuelConversionRecipe(IIngredient smelted, IIngredient fuel) {
55+
56+
}
57+
58+
}

0 commit comments

Comments
 (0)