Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ repositories {
maven {
url = 'https://repo.spongepowered.org/maven'
}
maven {
url 'http://maven.tterrag.com/'
allowInsecureProtocol = true
}
maven {
url 'https://cursemaven.com'
content {
Expand All @@ -74,13 +78,6 @@ repositories {
maven {
url = 'https://mvnrepository.com/artifact/org.apache.groovy/groovy'
}
maven {
url 'https://dvs1.progwml6.com/files/maven/'
}
maven {
url 'http://maven.tterrag.com/'
allowInsecureProtocol = true
}
maven {
url = 'http://maven.ic2.player.to/'
allowInsecureProtocol = true
Expand All @@ -105,7 +102,7 @@ dependencies {

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

implementation 'mezz.jei:jei_1.12.2:4.16.1.302'
implementation 'curse.maven:jei-238222:3040523'

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

compileOnly 'slimeknights.mantle:Mantle:1.12-1.3.3.55'
compileOnly rfg.deobf('curse.maven:mantle-74924:2713386')
if (project.debug_inspirations.toBoolean() || project.debug_tinkers.toBoolean()) {
runtimeOnly 'slimeknights.mantle:Mantle:1.12-1.3.3.55'
runtimeOnly rfg.deobf('curse.maven:mantle-74924:2713386')
}

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

compileOnly 'slimeknights.mantle:Mantle:1.12-1.3.3.55'
compileOnly 'slimeknights:TConstruct:1.12.2-2.13.0.190'
compileOnly rfg.deobf('curse.maven:tinkers_construct-74072:2902483')
compileOnly rfg.deobf('curse.maven:constructs-armory-287683:3174535')
compileOnly rfg.deobf('curse.maven:tinkers-complement-272671:2843439')
if (project.debug_tinkers.toBoolean()) {
runtimeOnly 'slimeknights:TConstruct:1.12.2-2.13.0.190'
runtimeOnly rfg.deobf('curse.maven:tinkers_construct-74072:2902483')
runtimeOnly rfg.deobf('curse.maven:constructs-armory-287683:3174535')
runtimeOnly rfg.deobf('curse.maven:tinkers-complement-272671:2843439')
}
Expand Down
38 changes: 38 additions & 0 deletions examples/postInit/in_world_crafting.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

inWorldCrafting.fluidToFluid.recipeBuilder()
.fluidInput(fluid('water'))
.input(item('minecraft:diamond') * 2)
.fluidOutput(fluid('lava'))
.register()

inWorldCrafting.fluidToItem.recipeBuilder()
.fluidInput(fluid('water'))
.input(item('minecraft:netherrack'))
.input(item('minecraft:gold_ingot'), 0.1f)
.output(item('minecraft:nether_star'))
.register()

inWorldCrafting.fluidToBlock.recipeBuilder()
.fluidInput(fluid('water'))
.input(item('minecraft:clay_ball'))
.output(block('minecraft:diamond_block'))
.register()

inWorldCrafting.explosion.recipeBuilder()
.input(item('minecraft:diamond'))
.output(item('minecraft:nether_star'))
.chance(0.4f)
.register()

inWorldCrafting.burning.recipeBuilder()
.input(item('minecraft:netherrack'))
.output(item('minecraft:nether_star'))
//.ticks(40f)
.register()

inWorldCrafting.pistonPush.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:diamond'))
.minHarvestLevel(2)
.maxConversionsPerPush(3)
.register()
4 changes: 2 additions & 2 deletions examples/postInit/vanilla.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ item('minecraft:golden_apple').setRarity(textformat('-1'))


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

// The outer parentheses and inner curly braces are optional.
eventManager.listen { EnderTeleportEvent event ->
Expand Down
8 changes: 4 additions & 4 deletions examples/postInit/woot.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//import ipsis.woot.configuration.EnumConfigKey
//import ipsis.woot.util.WootMobName

//import ipsis.woot.util.WootMobName

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

//import ipsis.woot.configuration.EnumConfigKey

//import ipsis.woot.util.WootMobName

// Note:
// Drops, Spawning, Policy, and Mob Config can also be controlled via .json config file
// Drops can also be modified via `custom_drops.json`,
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.Random;

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

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

public static final Random RND = new Random();

@Mod.EventHandler
public void onConstruction(FMLConstructionEvent event) {
MinecraftForge.EVENT_BUS.register(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.cleanroommc.groovyscript.compat.inworldcrafting;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.compat.inworldcrafting.jei.BurningRecipeCategory;
import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import com.cleanroommc.groovyscript.sandbox.ClosureHelper;
import groovy.lang.Closure;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Optional;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Burning extends VirtualizedRegistry<Burning.BurningRecipe> {

private static final Map<EntityItem, BurningRecipe> runningRecipes = new Object2ObjectOpenHashMap<>();

private final List<BurningRecipe> burningRecipes = new ArrayList<>();

@Optional.Method(modid = "jei")
@GroovyBlacklist
public List<BurningRecipeCategory.RecipeWrapper> getRecipeWrappers() {
return this.burningRecipes.stream().map(BurningRecipeCategory.RecipeWrapper::new).collect(Collectors.toList());
}

@Override
public void onReload() {
this.burningRecipes.addAll(getBackupRecipes());
getScriptedRecipes().forEach(this.burningRecipes::remove);
}

@Override
public void afterScriptLoad() {
super.afterScriptLoad();
this.burningRecipes.sort(Comparator.comparingInt(BurningRecipe::getTicks));
}

public void add(BurningRecipe burningRecipe) {
this.burningRecipes.add(burningRecipe);
addScripted(burningRecipe);
}

public boolean remove(BurningRecipe burningRecipe) {
if (this.burningRecipes.remove(burningRecipe)) {
addBackup(burningRecipe);
return true;
}
return false;
}

public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

public static class BurningRecipe {

private final IIngredient input;
private final ItemStack output;
private final int ticks;
private final Closure<Boolean> startCondition;

public BurningRecipe(IIngredient input, ItemStack output, int ticks, Closure<Boolean> startCondition) {
this.input = input;
this.output = output;
this.ticks = ticks;
this.startCondition = startCondition;
}

public IIngredient getInput() {
return input;
}

public ItemStack getOutput() {
return output;
}

public int getTicks() {
return ticks;
}

public boolean isValidInput(EntityItem entityItem, ItemStack itemStack) {
return this.input.test(itemStack) && (this.startCondition == null || ClosureHelper.call(true, this.startCondition, entityItem));
}
}

public static class RecipeBuilder extends AbstractRecipeBuilder<BurningRecipe> {

private int ticks = 40;
private Closure<Boolean> startCondition;

public RecipeBuilder ticks(int ticks) {
this.ticks = ticks;
return this;
}

public RecipeBuilder startCondition(Closure<Boolean> startCondition) {
this.startCondition = startCondition;
return this;
}

@Override
public String getErrorMsg() {
return "Error adding in world burning recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 1);
validateFluids(msg);
if (this.ticks < 0) {
GroovyLog.get().warn("Burning recipe chance should be greater than 0.");
this.ticks = 40;
}
}

@Override
public @Nullable Burning.BurningRecipe register() {
if (!validate()) return null;
BurningRecipe burningRecipe = new BurningRecipe(this.input.get(0), this.output.get(0), this.ticks, this.startCondition);
VanillaModule.inWorldCrafting.burning.add(burningRecipe);
return burningRecipe;
}
}

@GroovyBlacklist
public BurningRecipe findRecipe(EntityItem entityItem) {
BurningRecipe burningRecipe = runningRecipes.get(entityItem);
if (burningRecipe != null) return burningRecipe;
ItemStack itemStack = entityItem.getItem();
for (BurningRecipe burningRecipe1 : this.burningRecipes) {
if (burningRecipe1.isValidInput(entityItem, itemStack)) {
runningRecipes.put(entityItem, burningRecipe1);
return burningRecipe1;
}
}
return null;
}

@GroovyBlacklist
public void updateRecipeProgress(EntityItem entityItem) {
BurningRecipe burningRecipe = findRecipe(entityItem);
if (burningRecipe == null) return;
int prog = entityItem.getEntityData().getInteger("burn_time") + 1;
entityItem.getEntityData().setInteger("burn_time", prog);
entityItem.setEntityInvulnerable(true);
if (prog >= burningRecipe.ticks) {
ItemStack newStack = burningRecipe.output.copy();
newStack.setCount(entityItem.getItem().getCount());
entityItem.setItem(newStack);
removeBurningItem(entityItem);
}
}

@GroovyBlacklist
public static boolean removeBurningItem(EntityItem entityItem) {
entityItem.getEntityData().removeTag("burn_item");
return runningRecipes.remove(entityItem) != null;
}

public static boolean isRunningRecipe(EntityItem entityItem) {
return runningRecipes.containsKey(entityItem) && entityItem.getEntityData().getInteger("burn_time") > 1;
}
}
Loading