Skip to content

Instantly share code, notes, and snippets.

@kindlich
Created July 26, 2019 08:37
Show Gist options
  • Save kindlich/126050db970ec37cbeb1062e90526765 to your computer and use it in GitHub Desktop.
Save kindlich/126050db970ec37cbeb1062e90526765 to your computer and use it in GitHub Desktop.
[PREINITIALIZATION][CLIENT][INFO] Current loaders after merging: [[preinit]]
[PREINITIALIZATION][CLIENT][INFO] Loading scripts for loader with names [preinit]
[PREINITIALIZATION][CLIENT][INFO] [preinit | SIDE_CLIENT]: Skipping file {[0:crafttweaker]: discord_functional.zs} as we are currently loading with a different loader
[PREINITIALIZATION][CLIENT][INFO] Completed script loading in: 3ms
[INITIALIZATION][CLIENT][INFO] CraftTweaker: Building registry
[INITIALIZATION][CLIENT][INFO] CraftTweaker: Successfully built item registry
[INITIALIZATION][CLIENT][INFO] Current loaders after merging: [[preinit], [recipeevent | crafttweaker]]
[INITIALIZATION][CLIENT][INFO] Loading scripts for loader with names [crafttweaker | recipeevent]
[INITIALIZATION][CLIENT][INFO] [crafttweaker | SIDE_CLIENT]: Loading Script: {[0:crafttweaker]: discord_functional.zs}
[INITIALIZATION][CLIENT][INFO] aa
[INITIALIZATION][CLIENT][INFO] bb
[INITIALIZATION][CLIENT][INFO] cc
[INITIALIZATION][CLIENT][INFO] aa
[INITIALIZATION][CLIENT][INFO] bb
[INITIALIZATION][CLIENT][INFO] cc
[INITIALIZATION][CLIENT][INFO] SimpleRecipe[a]
[INITIALIZATION][CLIENT][INFO] SimpleRecipe[b]
[INITIALIZATION][CLIENT][INFO] SimpleRecipe[c]
[INITIALIZATION][CLIENT][INFO] Completed script loading in: 433ms
[POSTINITIALIZATION][CLIENT][INFO] Removing recipes for various outputs
[AVAILABLE][CLIENT][INFO] Fixed the RecipeBook
import crafttweaker.tests_functional.RecipeList;
import crafttweaker.tests_functional.SimpleRecipe;
RecipeList.getString()
.map(function(x as string){return x ~ x;})
.filter(function(x as string) {return !(x has "d");})
.forEach(function(x as string) {print(x);});
RecipeList.getString2()
.map(function(x as string){return x ~ x;})
.filter(function(x as string) {return !(x has "d");})
.forEach(function(x as string) {print(x);});
RecipeList.getSimpleRecipes()
.filter(function(x as SimpleRecipe) {return !(x.id has "d");})
.forEach(function(x as SimpleRecipe) {x.print();});
package crafttweaker.api.tests.functional;
import crafttweaker.annotations.*;
import stanhebben.zenscript.annotations.*;
@ZenClass("crafttweaker.tests_functional.RecipeFilter")
@ZenRegister
@FunctionalInterface
public interface RecipeFilter<T> {
boolean doFilter(T recipe);
}
package crafttweaker.api.tests.functional;
import crafttweaker.annotations.*;
import stanhebben.zenscript.annotations.*;
@ZenClass("crafttweaker.tests_functional.RecipeForEach")
@ZenRegister
@FunctionalInterface
public interface RecipeForEach<T> {
void apply(T obj);
}
package crafttweaker.api.tests.functional;
import crafttweaker.annotations.*;
import stanhebben.zenscript.annotations.*;
import java.util.stream.*;
@ZenClass("crafttweaker.tests_functional.RecipeList")
@ZenRegister
public class RecipeList<T> {
private Stream<T> internalStream;
public RecipeList(Stream<T> internalStream) {
this.internalStream = internalStream;
}
@ZenMethod
public static RecipeList<String> getString() {
return new RecipeList<>(Stream.of("a", "b", "c", "d"));
}
@ZenMethod
public static RecipeList<String> getString2() {
return new RecipeList<>(Stream.of("a", "b", "c", "d"));
}
@ZenMethod
public static RecipeList<SimpleRecipe> getSimpleRecipes() {
return new RecipeList<>(Stream.of("a", "b", "c", "d").map(SimpleRecipe::new));
}
@ZenMethod
@ReturnsSelf
public RecipeList<T> filter(RecipeFilter<T> filter) {
internalStream = internalStream.filter(filter::doFilter);
return this;
}
@ZenMethod
@ReturnsSelf
public RecipeList<T> map(RecipeMapper<T> mapper) {
internalStream = internalStream.map(mapper::doMap);
return this;
}
@ZenMethod
public void forEach(RecipeForEach<T> applyFn) {
internalStream.forEach(applyFn::apply);
}
}
package crafttweaker.api.tests.functional;
import crafttweaker.annotations.*;
import stanhebben.zenscript.annotations.*;
@ZenClass("crafttweaker.tests_functional.RecipeMapper")
@ZenRegister
@FunctionalInterface
public interface RecipeMapper<T> {
T doMap(T obj);
}
package crafttweaker.api.tests.functional;
import crafttweaker.*;
import crafttweaker.annotations.*;
import stanhebben.zenscript.annotations.*;
import java.util.*;
@ZenClass("crafttweaker.tests_functional.SimpleRecipe")
@ZenRegister
public class SimpleRecipe {
private final String id;
public SimpleRecipe(String id) {
this.id = id;
}
@ZenGetter("id")
public String getId() {
return id;
}
@ZenMethod
public void print() {
CraftTweakerAPI.logInfo(String.format(Locale.ENGLISH, "SimpleRecipe[%s]", id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment