generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Compact Machines compat * move examples file
- Loading branch information
1 parent
d4565da
commit c413fa2
Showing
6 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
if (!isLoaded('compactmachines3')) return | ||
println 'mod \'compactmachines3\' detected, running script' | ||
|
||
// Miniaturization: | ||
// Consumes a 3d structure in-world based on keys when an item is thrown into the field. | ||
mods.compactmachines.miniaturization.recipeBuilder() | ||
.name('diamond_rectangle') // Optional, String | ||
.input(item('minecraft:clay')) | ||
.output(item('minecraft:clay')) | ||
.symmetrical() // Indicates that the recipe does not have to test all 4 rotations to determine if the multiblock is valid | ||
.ticks(10) // Alias: duration, default 100 | ||
.shape([['www', 'www']]) // Shape is a List<List<String>> | ||
.key('w', blockstate('minecraft:diamond_block')) | ||
// character, blockstate, nbt, metadata-sensitive (default true), display item | ||
//.key('w', blockstate('minecraft:diamond_block'), null, true, item('minecraft:diamond') * 7) | ||
.register() | ||
|
||
mods.compactmachines.miniaturization.recipeBuilder() | ||
.name('groovy_rocket') // Optional, String | ||
.input(item('minecraft:diamond')) | ||
.output(item('minecraft:clay') * 64) | ||
.symmetrical() | ||
.ticks(5400) | ||
// both ` ` and `_` are reserved for empty space, and cannot be used as keys | ||
.key('a', blockstate('minecraft:stained_glass:0')) | ||
.key('b', blockstate('minecraft:stained_glass:1')) | ||
.key('c', blockstate('minecraft:stained_glass:2')) | ||
.key('d', blockstate('minecraft:stained_glass:3')) | ||
.key('e', blockstate('minecraft:diamond_block')) | ||
.key('f', blockstate('minecraft:stained_glass:5')) | ||
.key('g', blockstate('minecraft:stained_glass:6')) // Note: More than 6 keys results in incorrect displays in JEI | ||
.layer(" ", " ", " a ", " aaa ", " a ", " ", " ") // layer adds String... to the shape structure | ||
.layer(" ", " b ", " aaa ", " baaab ", " aaa ", " b ", " ") // adds layers in descending Y order | ||
.layer(" ", " c ", " cac ", " caeac ", " cac ", " c ", " ") | ||
.layer(" ", " a ", " aaa ", " aaeaa ", " aaa ", " a ", " ") | ||
.layer(" ", " a ", " aaa ", " aaeaa ", " aaa ", " a ", " ") | ||
.layer(" ", " a ", " aaa ", " aaeaa ", " aaa ", " a ", " ") | ||
.layer(" ", " g ", " cac ", " caeac ", " cac ", " f ", " ") | ||
.layer(" ", " a ", " aaa ", " aaeaa ", " aaa ", " a ", " ") | ||
.layer(" ", " a ", " aaa ", " aaeaa ", " aaa ", " a ", " ") | ||
.layer(" ", " a ", " aaa ", " aaeaa ", " aaa ", " a ", " ") | ||
.layer(" ", " c ", " cac ", " caeac ", " cac ", " c ", " ") | ||
.layer(" ", " a ", " aaa ", " aaaaa ", " aaa ", " a ", " ") | ||
.layer(" a ", " ccc ", " cdddc ", "acdddca", " cdddc ", " ccc ", " a ") | ||
.register() | ||
|
||
mods.compactmachines.miniaturization.removeByInput(item('minecraft:ender_pearl')) | ||
mods.compactmachines.miniaturization.removeByCatalyst(item('minecraft:redstone')) | ||
mods.compactmachines.miniaturization.removeByOutput(item('compactmachines3:machine:3')) | ||
//mods.compactmachines.miniaturization.removeAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/cleanroommc/groovyscript/compat/mods/compactmachines/CompactMachines.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.compactmachines; | ||
|
||
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer; | ||
|
||
public class CompactMachines extends ModPropertyContainer { | ||
|
||
public final Miniaturization miniaturization = new Miniaturization(); | ||
|
||
public CompactMachines() { | ||
addRegistry(miniaturization); | ||
} | ||
|
||
} |
227 changes: 227 additions & 0 deletions
227
src/main/java/com/cleanroommc/groovyscript/compat/mods/compactmachines/Miniaturization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.compactmachines; | ||
|
||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
import com.cleanroommc.groovyscript.compat.mods.ModSupport; | ||
import com.cleanroommc.groovyscript.helper.SimpleObjectStream; | ||
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; | ||
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; | ||
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import org.dave.compactmachines3.miniaturization.MultiblockRecipes; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Miniaturization extends VirtualizedRegistry<org.dave.compactmachines3.miniaturization.MultiblockRecipe> { | ||
|
||
public RecipeBuilder recipeBuilder() { | ||
return new RecipeBuilder(); | ||
} | ||
|
||
@Override | ||
public void onReload() { | ||
removeScripted().forEach(recipe -> MultiblockRecipes.getRecipes().removeIf(r -> r == recipe)); | ||
restoreFromBackup().forEach(recipe -> MultiblockRecipes.getRecipes().add(recipe)); | ||
} | ||
|
||
public void add(org.dave.compactmachines3.miniaturization.MultiblockRecipe recipe) { | ||
addScripted(recipe); | ||
MultiblockRecipes.getRecipes().add(recipe); | ||
} | ||
|
||
public boolean remove(org.dave.compactmachines3.miniaturization.MultiblockRecipe recipe) { | ||
addBackup(recipe); | ||
return MultiblockRecipes.getRecipes().removeIf(r -> r == recipe); | ||
} | ||
|
||
public void removeByInput(ItemStack input) { | ||
for (org.dave.compactmachines3.miniaturization.MultiblockRecipe recipe : MultiblockRecipes.getRecipes().stream().filter(r -> r.getCatalystStack().isItemEqual(input)).collect(Collectors.toList())) { | ||
addBackup(recipe); | ||
MultiblockRecipes.getRecipes().removeIf(r -> r == recipe); | ||
} | ||
} | ||
|
||
public void removeByCatalyst(ItemStack catalyst) { | ||
removeByInput(catalyst); | ||
} | ||
|
||
public void removeByOutput(ItemStack output) { | ||
for (org.dave.compactmachines3.miniaturization.MultiblockRecipe recipe : MultiblockRecipes.getRecipes().stream().filter(r -> r.getTargetStack().isItemEqual(output)).collect(Collectors.toList())) { | ||
addBackup(recipe); | ||
MultiblockRecipes.getRecipes().removeIf(r -> r == recipe); | ||
} | ||
} | ||
|
||
public void removeAll() { | ||
MultiblockRecipes.getRecipes().forEach(this::addBackup); | ||
MultiblockRecipes.getRecipes().clear(); | ||
} | ||
|
||
public SimpleObjectStream<org.dave.compactmachines3.miniaturization.MultiblockRecipe> streamRecipes() { | ||
return new SimpleObjectStream<>(MultiblockRecipes.getRecipes()).setRemover(this::remove); | ||
} | ||
|
||
public static class RecipeBuilder extends AbstractRecipeBuilder<org.dave.compactmachines3.miniaturization.MultiblockRecipe> { | ||
|
||
private final Char2ObjectOpenHashMap<ReferenceValues> keyMap = new Char2ObjectOpenHashMap<>(); | ||
private final List<String> errors = new ArrayList<>(); | ||
List<List<String>> shape = new ArrayList<>(); | ||
private boolean symmetrical; | ||
private int ticks = 100; | ||
|
||
public RecipeBuilder shape(List<List<String>> shape) { | ||
this.shape = shape; | ||
return this; | ||
} | ||
|
||
public RecipeBuilder layer(List<String> layer) { | ||
this.shape.add(layer); | ||
return this; | ||
} | ||
|
||
public RecipeBuilder layer(String... layer) { | ||
return layer(Arrays.asList(layer)); | ||
} | ||
|
||
// groovy doesn't have char literals | ||
public RecipeBuilder key(String c, IBlockState state, NBTTagCompound nbt, boolean ignoreMeta, ItemStack reference) { | ||
if (c == null || c.length() != 1) { | ||
errors.add("key must be a single char, but found '" + c + "'"); | ||
return this; | ||
} | ||
if (c.equals("_") || c.equals(" ")) { | ||
errors.add("key cannot be an underscore('_') or a space(' ')"); | ||
return this; | ||
} | ||
this.keyMap.put(c.charAt(0), new ReferenceValues(state, nbt, ignoreMeta, reference)); | ||
return this; | ||
} | ||
|
||
public RecipeBuilder key(String c, IBlockState state, NBTTagCompound nbt, boolean ignoreMeta) { | ||
return key(c, state, nbt, ignoreMeta, null); | ||
} | ||
|
||
public RecipeBuilder key(String c, IBlockState state, NBTTagCompound nbt) { | ||
return key(c, state, nbt, false, null); | ||
} | ||
|
||
public RecipeBuilder key(String c, IBlockState state, boolean ignoreMeta) { | ||
return key(c, state, null, ignoreMeta, null); | ||
} | ||
|
||
public RecipeBuilder key(String c, IBlockState state) { | ||
return key(c, state, null, false, null); | ||
} | ||
|
||
public RecipeBuilder symmetrical(boolean symmetrical) { | ||
this.symmetrical = symmetrical; | ||
return this; | ||
} | ||
|
||
public RecipeBuilder symmetrical() { | ||
this.symmetrical = !symmetrical; | ||
return this; | ||
} | ||
|
||
public RecipeBuilder ticks(int ticks) { | ||
this.ticks = ticks; | ||
return this; | ||
} | ||
|
||
public RecipeBuilder duration(int duration) { | ||
return ticks(duration); | ||
} | ||
|
||
@Override | ||
public String getErrorMsg() { | ||
return "Error adding Compact Machines Multiblock recipe"; | ||
} | ||
|
||
@Override | ||
public void validate(GroovyLog.Msg msg) { | ||
validateName(); | ||
validateItems(msg, 1, 1, 1, 1); | ||
validateFluids(msg); | ||
for (String error : errors) { | ||
msg.add(error); | ||
} | ||
String missingKeys = shape.stream().flatMap(l -> l.stream().flatMap(g -> Arrays.stream(g.split("")).map(q -> q.charAt(0)))) | ||
.distinct() | ||
.filter(x -> !(keyMap.containsKey(x) || x == ' ' || x == '_')) | ||
.map(String::valueOf) | ||
.collect(Collectors.joining()); | ||
msg.add(!missingKeys.isEmpty(), "shape must contain only characters that are underscore('_'), space(' '), or declared via a key, but the following keys were not declared: {}", missingKeys); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public org.dave.compactmachines3.miniaturization.MultiblockRecipe register() { | ||
if (!validate()) return null; | ||
|
||
org.dave.compactmachines3.miniaturization.MultiblockRecipe recipe = new org.dave.compactmachines3.miniaturization.MultiblockRecipe( | ||
name.toString(), | ||
output.get(0), | ||
input.get(0).getMatchingStacks()[0].getItem(), | ||
input.get(0).getMatchingStacks()[0].getMetadata(), | ||
input.get(0).getMatchingStacks()[0].getTagCompound(), | ||
symmetrical, | ||
ticks | ||
); | ||
|
||
String[][][] target = shape.stream().map(l -> l.stream().map(g -> g.replace(" ", "_").split("")) | ||
.toArray(String[][]::new)).toArray(String[][][]::new); | ||
|
||
recipe.setPositionMap(target); | ||
|
||
keyMap.forEach((character, value) -> { | ||
String ref = String.valueOf(character); | ||
recipe.addBlockReference(ref, value.getState()); | ||
if (value.getNbt() != null) recipe.addBlockVariation(ref, value.getNbt()); | ||
recipe.setIgnoreMeta(ref, value.isIgnoreMeta()); | ||
if (value.getReference() != null) recipe.setReferenceStack(ref, value.getReference()); | ||
}); | ||
|
||
ModSupport.COMPACT_MACHINES.get().miniaturization.add(recipe); | ||
return recipe; | ||
} | ||
|
||
public static class ReferenceValues { | ||
|
||
private final IBlockState state; | ||
private final NBTTagCompound nbt; | ||
private final boolean ignoreMeta; | ||
private final ItemStack reference; | ||
|
||
public ReferenceValues(IBlockState state, NBTTagCompound nbt, boolean ignoreMeta, ItemStack reference) { | ||
this.state = state; | ||
this.nbt = nbt; | ||
this.ignoreMeta = ignoreMeta; | ||
this.reference = reference; | ||
} | ||
|
||
public IBlockState getState() { | ||
return state; | ||
} | ||
|
||
public NBTTagCompound getNbt() { | ||
return nbt; | ||
} | ||
|
||
public boolean isIgnoreMeta() { | ||
return ignoreMeta; | ||
} | ||
|
||
public ItemStack getReference() { | ||
return reference; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |