Skip to content

Commit 494dfdf

Browse files
authored
In world crafting (#83)
* in world crafting fluid to fluid and fluid to item * comments & remover methods * fluid to block * add recipe callbacks * explosion crafting * burn crafting * jei for fluid recipes * jei explosion recipes * get jei from curse maven * burning jei category * piston push recipes * piston push jei category * try new mapping repo * try fix build 2 * dont change visibility with overwrite * rename `beforeRecipe` to `startCondition` * use fluid name in map * fix spawn location * reviews * fix jei chance tooltip * fix fluid recipes not working
1 parent e3e24ff commit 494dfdf

30 files changed

+2113
-25
lines changed

build.gradle

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ repositories {
6565
maven {
6666
url = 'https://repo.spongepowered.org/maven'
6767
}
68+
maven {
69+
url 'http://maven.tterrag.com/'
70+
allowInsecureProtocol = true
71+
}
6872
maven {
6973
url 'https://cursemaven.com'
7074
content {
@@ -74,13 +78,6 @@ repositories {
7478
maven {
7579
url = 'https://mvnrepository.com/artifact/org.apache.groovy/groovy'
7680
}
77-
maven {
78-
url 'https://dvs1.progwml6.com/files/maven/'
79-
}
80-
maven {
81-
url 'http://maven.tterrag.com/'
82-
allowInsecureProtocol = true
83-
}
8481
maven {
8582
url = 'http://maven.ic2.player.to/'
8683
allowInsecureProtocol = true
@@ -105,7 +102,7 @@ dependencies {
105102

106103
embed "org.apache.groovy:groovy:${project.groovy_version}"
107104

108-
implementation 'mezz.jei:jei_1.12.2:4.16.1.302'
105+
implementation 'curse.maven:jei-238222:3040523'
109106

110107
compileOnly rfg.deobf('curse.maven:codechicken_lib_1_8-242818:2779848')
111108
if (project.debug_avaritia.toBoolean() || project.debug_draconic_evolution.toBoolean()) {
@@ -124,9 +121,9 @@ dependencies {
124121
runtimeOnly rfg.deobf('curse.maven:chisel-235279:2915375')
125122
}
126123

127-
compileOnly 'slimeknights.mantle:Mantle:1.12-1.3.3.55'
124+
compileOnly rfg.deobf('curse.maven:mantle-74924:2713386')
128125
if (project.debug_inspirations.toBoolean() || project.debug_tinkers.toBoolean()) {
129-
runtimeOnly 'slimeknights.mantle:Mantle:1.12-1.3.3.55'
126+
runtimeOnly rfg.deobf('curse.maven:mantle-74924:2713386')
130127
}
131128

132129
compileOnly rfg.deobf('curse.maven:mekanism-268560:2835175')
@@ -287,12 +284,11 @@ dependencies {
287284
runtimeOnly rfg.deobf('curse.maven:woot-244049:2712670')
288285
}
289286

290-
compileOnly 'slimeknights.mantle:Mantle:1.12-1.3.3.55'
291-
compileOnly 'slimeknights:TConstruct:1.12.2-2.13.0.190'
287+
compileOnly rfg.deobf('curse.maven:tinkers_construct-74072:2902483')
292288
compileOnly rfg.deobf('curse.maven:constructs-armory-287683:3174535')
293289
compileOnly rfg.deobf('curse.maven:tinkers-complement-272671:2843439')
294290
if (project.debug_tinkers.toBoolean()) {
295-
runtimeOnly 'slimeknights:TConstruct:1.12.2-2.13.0.190'
291+
runtimeOnly rfg.deobf('curse.maven:tinkers_construct-74072:2902483')
296292
runtimeOnly rfg.deobf('curse.maven:constructs-armory-287683:3174535')
297293
runtimeOnly rfg.deobf('curse.maven:tinkers-complement-272671:2843439')
298294
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
inWorldCrafting.fluidToFluid.recipeBuilder()
3+
.fluidInput(fluid('water'))
4+
.input(item('minecraft:diamond') * 2)
5+
.fluidOutput(fluid('lava'))
6+
.register()
7+
8+
inWorldCrafting.fluidToItem.recipeBuilder()
9+
.fluidInput(fluid('water'))
10+
.input(item('minecraft:netherrack'))
11+
.input(item('minecraft:gold_ingot'), 0.1f)
12+
.output(item('minecraft:nether_star'))
13+
.register()
14+
15+
inWorldCrafting.fluidToBlock.recipeBuilder()
16+
.fluidInput(fluid('water'))
17+
.input(item('minecraft:clay_ball'))
18+
.output(block('minecraft:diamond_block'))
19+
.register()
20+
21+
inWorldCrafting.explosion.recipeBuilder()
22+
.input(item('minecraft:diamond'))
23+
.output(item('minecraft:nether_star'))
24+
.chance(0.4f)
25+
.register()
26+
27+
inWorldCrafting.burning.recipeBuilder()
28+
.input(item('minecraft:netherrack'))
29+
.output(item('minecraft:nether_star'))
30+
//.ticks(40f)
31+
.register()
32+
33+
inWorldCrafting.pistonPush.recipeBuilder()
34+
.input(item('minecraft:gold_ingot'))
35+
.output(item('minecraft:diamond'))
36+
.minHarvestLevel(2)
37+
.maxConversionsPerPush(3)
38+
.register()

examples/postInit/vanilla.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ item('minecraft:golden_apple').setRarity(textformat('-1'))
218218

219219

220220
// Use eventManager.listen and listen to the desired event.
221-
eventManager.listen({ BlockEvent.BreakEvent event -> {
221+
/*eventManager.listen({ BlockEvent.BreakEvent event -> {
222222
event.setCanceled(true) // Many events can be canceled.
223223
event.player.sendMessage(new TextComponentString("${event.getState().getBlock().getLocalizedName()} Block was prevent from being broken"))
224-
}})
224+
}})*/
225225

226226
// The outer parentheses and inner curly braces are optional.
227227
eventManager.listen { EnderTeleportEvent event ->

examples/postInit/woot.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//import ipsis.woot.configuration.EnumConfigKey
2-
//import ipsis.woot.util.WootMobName
3-
4-
//import ipsis.woot.util.WootMobName
51

62
if (!isLoaded('woot')) return
73
println 'mod \'woot\' detected, running script'
84

5+
//import ipsis.woot.configuration.EnumConfigKey
6+
7+
//import ipsis.woot.util.WootMobName
8+
99
// Note:
1010
// Drops, Spawning, Policy, and Mob Config can also be controlled via .json config file
1111
// Drops can also be modified via `custom_drops.json`,

src/main/java/com/cleanroommc/groovyscript/GroovyScript.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.nio.file.Files;
6464
import java.nio.file.StandardOpenOption;
6565
import java.util.List;
66+
import java.util.Random;
6667

6768
@GroovyBlacklist
6869
@Mod(modid = GroovyScript.ID, name = GroovyScript.NAME, version = GroovyScript.VERSION)
@@ -89,6 +90,8 @@ public class GroovyScript {
8990

9091
private static final Joiner fileJoiner = Joiner.on(File.separator);
9192

93+
public static final Random RND = new Random();
94+
9295
@Mod.EventHandler
9396
public void onConstruction(FMLConstructionEvent event) {
9497
MinecraftForge.EVENT_BUS.register(this);
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package com.cleanroommc.groovyscript.compat.inworldcrafting;
2+
3+
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
4+
import com.cleanroommc.groovyscript.api.GroovyLog;
5+
import com.cleanroommc.groovyscript.api.IIngredient;
6+
import com.cleanroommc.groovyscript.compat.inworldcrafting.jei.BurningRecipeCategory;
7+
import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule;
8+
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
9+
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
10+
import com.cleanroommc.groovyscript.sandbox.ClosureHelper;
11+
import groovy.lang.Closure;
12+
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
13+
import net.minecraft.entity.item.EntityItem;
14+
import net.minecraft.item.ItemStack;
15+
import net.minecraftforge.fml.common.Optional;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
import java.util.ArrayList;
19+
import java.util.Comparator;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.stream.Collectors;
23+
24+
public class Burning extends VirtualizedRegistry<Burning.BurningRecipe> {
25+
26+
private static final Map<EntityItem, BurningRecipe> runningRecipes = new Object2ObjectOpenHashMap<>();
27+
28+
private final List<BurningRecipe> burningRecipes = new ArrayList<>();
29+
30+
@Optional.Method(modid = "jei")
31+
@GroovyBlacklist
32+
public List<BurningRecipeCategory.RecipeWrapper> getRecipeWrappers() {
33+
return this.burningRecipes.stream().map(BurningRecipeCategory.RecipeWrapper::new).collect(Collectors.toList());
34+
}
35+
36+
@Override
37+
public void onReload() {
38+
this.burningRecipes.addAll(getBackupRecipes());
39+
getScriptedRecipes().forEach(this.burningRecipes::remove);
40+
}
41+
42+
@Override
43+
public void afterScriptLoad() {
44+
super.afterScriptLoad();
45+
this.burningRecipes.sort(Comparator.comparingInt(BurningRecipe::getTicks));
46+
}
47+
48+
public void add(BurningRecipe burningRecipe) {
49+
this.burningRecipes.add(burningRecipe);
50+
addScripted(burningRecipe);
51+
}
52+
53+
public boolean remove(BurningRecipe burningRecipe) {
54+
if (this.burningRecipes.remove(burningRecipe)) {
55+
addBackup(burningRecipe);
56+
return true;
57+
}
58+
return false;
59+
}
60+
61+
public RecipeBuilder recipeBuilder() {
62+
return new RecipeBuilder();
63+
}
64+
65+
public static class BurningRecipe {
66+
67+
private final IIngredient input;
68+
private final ItemStack output;
69+
private final int ticks;
70+
private final Closure<Boolean> startCondition;
71+
72+
public BurningRecipe(IIngredient input, ItemStack output, int ticks, Closure<Boolean> startCondition) {
73+
this.input = input;
74+
this.output = output;
75+
this.ticks = ticks;
76+
this.startCondition = startCondition;
77+
}
78+
79+
public IIngredient getInput() {
80+
return input;
81+
}
82+
83+
public ItemStack getOutput() {
84+
return output;
85+
}
86+
87+
public int getTicks() {
88+
return ticks;
89+
}
90+
91+
public boolean isValidInput(EntityItem entityItem, ItemStack itemStack) {
92+
return this.input.test(itemStack) && (this.startCondition == null || ClosureHelper.call(true, this.startCondition, entityItem));
93+
}
94+
}
95+
96+
public static class RecipeBuilder extends AbstractRecipeBuilder<BurningRecipe> {
97+
98+
private int ticks = 40;
99+
private Closure<Boolean> startCondition;
100+
101+
public RecipeBuilder ticks(int ticks) {
102+
this.ticks = ticks;
103+
return this;
104+
}
105+
106+
public RecipeBuilder startCondition(Closure<Boolean> startCondition) {
107+
this.startCondition = startCondition;
108+
return this;
109+
}
110+
111+
@Override
112+
public String getErrorMsg() {
113+
return "Error adding in world burning recipe";
114+
}
115+
116+
@Override
117+
public void validate(GroovyLog.Msg msg) {
118+
validateItems(msg, 1, 1, 1, 1);
119+
validateFluids(msg);
120+
if (this.ticks < 0) {
121+
GroovyLog.get().warn("Burning recipe chance should be greater than 0.");
122+
this.ticks = 40;
123+
}
124+
}
125+
126+
@Override
127+
public @Nullable Burning.BurningRecipe register() {
128+
if (!validate()) return null;
129+
BurningRecipe burningRecipe = new BurningRecipe(this.input.get(0), this.output.get(0), this.ticks, this.startCondition);
130+
VanillaModule.inWorldCrafting.burning.add(burningRecipe);
131+
return burningRecipe;
132+
}
133+
}
134+
135+
@GroovyBlacklist
136+
public BurningRecipe findRecipe(EntityItem entityItem) {
137+
BurningRecipe burningRecipe = runningRecipes.get(entityItem);
138+
if (burningRecipe != null) return burningRecipe;
139+
ItemStack itemStack = entityItem.getItem();
140+
for (BurningRecipe burningRecipe1 : this.burningRecipes) {
141+
if (burningRecipe1.isValidInput(entityItem, itemStack)) {
142+
runningRecipes.put(entityItem, burningRecipe1);
143+
return burningRecipe1;
144+
}
145+
}
146+
return null;
147+
}
148+
149+
@GroovyBlacklist
150+
public void updateRecipeProgress(EntityItem entityItem) {
151+
BurningRecipe burningRecipe = findRecipe(entityItem);
152+
if (burningRecipe == null) return;
153+
int prog = entityItem.getEntityData().getInteger("burn_time") + 1;
154+
entityItem.getEntityData().setInteger("burn_time", prog);
155+
entityItem.setEntityInvulnerable(true);
156+
if (prog >= burningRecipe.ticks) {
157+
ItemStack newStack = burningRecipe.output.copy();
158+
newStack.setCount(entityItem.getItem().getCount());
159+
entityItem.setItem(newStack);
160+
removeBurningItem(entityItem);
161+
}
162+
}
163+
164+
@GroovyBlacklist
165+
public static boolean removeBurningItem(EntityItem entityItem) {
166+
entityItem.getEntityData().removeTag("burn_item");
167+
return runningRecipes.remove(entityItem) != null;
168+
}
169+
170+
public static boolean isRunningRecipe(EntityItem entityItem) {
171+
return runningRecipes.containsKey(entityItem) && entityItem.getEntityData().getInteger("burn_time") > 1;
172+
}
173+
}

0 commit comments

Comments
 (0)