Skip to content

Instantly share code, notes, and snippets.

@TeamDman
Last active September 27, 2019 05:00
Show Gist options
  • Select an option

  • Save TeamDman/fd376abeec54b3e1fb175d8b70ccd0ff to your computer and use it in GitHub Desktop.

Select an option

Save TeamDman/fd376abeec54b3e1fb175d8b70ccd0ff to your computer and use it in GitHub Desktop.
ZS No such member
import mods.zentriggers.events.WorldTickEvent;
import mods.zentriggers.WorldTickHandler;
import mods.zentriggers.WorldTickPredicateBuilder;
import mods.zentriggers.world.World;
WorldTickHandler.onWorldTick(
WorldTickPredicateBuilder.create()
.isDay()
.negateLatest()
,function(event as WorldTickEvent) {
event.world.setWorldTime(24000 as long);
}
);
[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]: asd.zs} as we are currently loading with a different loader
[PREINITIALIZATION][CLIENT][INFO] [preinit | SIDE_CLIENT]: Skipping file {[0:crafttweaker]: zoop.zs} as we are currently loading with a different loader
[PREINITIALIZATION][CLIENT][INFO] Completed script loading in: 4ms
[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]: asd.zs}
[INITIALIZATION][CLIENT][ERROR] asd.zs:11 > No such member in mods.zentriggers.world.World: setWorldTime
[INITIALIZATION][CLIENT][ERROR] [crafttweaker]: Error executing {[0:crafttweaker]: asd.zs}: Bad type on operand stack
Exception Details:
Location:
ZenClassCrafttweakerAsd0.handle(Lzentriggers/zentriggers/wrappers/MCWorldTickEvent;)V @12: dup
Reason:
Type long_2nd (current frame, stack[5]) is not assignable to category1 type
Current Frame:
bci: @12
flags: { }
locals: { 'ZenClassCrafttweakerAsd0', 'zentriggers/zentriggers/wrappers/MCWorldTickEvent' }
stack: { null, '[Lstanhebben/zenscript/value/IAny;', '[Lstanhebben/zenscript/value/IAny;', integer, long, long_2nd }
Bytecode:
0x0000000: 0112 0ebd 0010 5912 1114 0012 59c7 0008
0x0000010: 5701 a700 06b8 0019 b800 1f53 b900 2302
0x0000020: 0057 b1
Stackmap Table:
full_frame(@21,{Object[#2],Object[#37]},{Null,Object[#39],Object[#39],Integer,Long})
full_frame(@24,{Object[#2],Object[#37]},{Null,Object[#39],Object[#39],Integer,Long})
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
ZenClassCrafttweakerAsd0.handle(Lzentriggers/zentriggers/wrappers/MCWorldTickEvent;)V @12: dup
Reason:
Type long_2nd (current frame, stack[5]) is not assignable to category1 type
Current Frame:
bci: @12
flags: { }
locals: { 'ZenClassCrafttweakerAsd0', 'zentriggers/zentriggers/wrappers/MCWorldTickEvent' }
stack: { null, '[Lstanhebben/zenscript/value/IAny;', '[Lstanhebben/zenscript/value/IAny;', integer, long, long_2nd }
Bytecode:
0x0000000: 0112 0ebd 0010 5912 1114 0012 59c7 0008
0x0000010: 5701 a700 06b8 0019 b800 1f53 b900 2302
0x0000020: 0057 b1
Stackmap Table:
full_frame(@21,{Object[#2],Object[#37]},{Null,Object[#39],Object[#39],Integer,Long})
full_frame(@24,{Object[#2],Object[#37]},{Null,Object[#39],Object[#39],Integer,Long})
at Asd.__script__(asd.zs:6)
at __ZenMain__.run(Asd)
at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:225)
at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:105)
at crafttweaker.mc1120.events.CommonEventHandler.registerRecipes(CommonEventHandler.java:69)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_56_CommonEventHandler_registerRecipes_Register.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:789)
at net.minecraftforge.common.crafting.CraftingHelper.loadRecipes(CraftingHelper.java:624)
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:742)
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:336)
at net.minecraft.client.Minecraft.init(Minecraft.java:582)
at net.minecraft.client.Minecraft.run(Minecraft.java:422)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:25)
[INITIALIZATION][CLIENT][INFO] [crafttweaker | SIDE_CLIENT]: Loading Script: {[0:crafttweaker]: zoop.zs}
[INITIALIZATION][CLIENT][INFO] ---------------Zen Events Start------------------
[INITIALIZATION][CLIENT][INFO] ZenSummoning took unknown duration, no timestamp found for the given identifier
[INITIALIZATION][CLIENT][INFO] Completed script loading in: 606ms
[POSTINITIALIZATION][CLIENT][INFO] Removing recipes for various outputs
[AVAILABLE][CLIENT][INFO] Fixed the RecipeBook
package zentriggers.zentriggers.wrappers;
import crafttweaker.annotations.ZenRegister;
import net.minecraft.world.World;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenSetter;
import zentriggers.zentriggers.ZenTriggers;
@ZenRegister
@ZenClass(ZenTriggers.ZEN_PACKAGE + ".world.World")
public class MCWorld extends crafttweaker.mc1120.world.MCWorld {
private World world;
public MCWorld(World world) {
super(world);
this.world = world;
}
@ZenGetter("worldTime")
public long getWorldTime() {
return world.getWorldTime();
}
@ZenSetter("worldTime")
public void setWorldTime(long time) {
world.setWorldTime(time);
}
@ZenGetter("totalWorldTime")
public long getTotalWorldTime() {
return world.getTotalWorldTime();
}
@ZenSetter("totalWorldTime")
public void setTotalWorldTime(long time) {
world.setTotalWorldTime(time);
}
}
package zentriggers.zentriggers.wrappers;
import crafttweaker.annotations.ZenRegister;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import zentriggers.zentriggers.ZenTriggers;
@ZenRegister
@ZenClass(ZenTriggers.ZEN_PACKAGE + ".events.WorldTickEvent")
public class MCWorldTickEvent {
private final MCWorld world;
public MCWorldTickEvent(MCWorld world) {
this.world = world;
}
@ZenGetter("world")
public MCWorld getWorld() {
return world;
}
}
package zentriggers.zentriggers;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.util.IEventHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import zentriggers.zentriggers.wrappers.MCWorld;
import zentriggers.zentriggers.wrappers.MCWorldTickEvent;
import java.util.HashMap;
import java.util.Map;
@ZenClass(ZenTriggers.ZEN_PACKAGE + ".WorldTickHandler")
@ZenRegister
@Mod.EventBusSubscriber
public class WorldTickHandler {
private static Map<WorldTickPredicateBuilder, IEventHandler<MCWorldTickEvent>> rawHandlers = new HashMap<>();
private static int rawInterval = 10;
@SubscribeEvent
public static void onTick(TickEvent.WorldTickEvent e) {
if (e.phase != TickEvent.Phase.START)
return;
if (e.world == null)
return;
if (e.world.getTotalWorldTime() % rawInterval != 0)
return;
if (rawHandlers.isEmpty())
return;
rawHandlers.forEach((predicates, handler) -> {
if (predicates.test(e.world)) {
try {
handler.handle(new MCWorldTickEvent(new MCWorld(e.world)));
} catch (Throwable t) {
System.out.println("Error occurred invoking raw handler for onTick");
t.printStackTrace();
}
}
});
}
@ZenMethod
public static void onWorldTick(WorldTickPredicateBuilder builder, IEventHandler<MCWorldTickEvent> handler) {
if (builder == null || handler == null)
System.out.println("Builder or handler null trying to register ZenTriggers event, skipping. [Builder: " + builder + ", Handler: " + handler + "]");
rawHandlers.put(builder, handler);
}
@ZenMethod
public static void setRawInterval(int interval) {
rawInterval = interval;
}
}
package zentriggers.zentriggers;
import crafttweaker.annotations.ZenRegister;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import java.util.ArrayDeque;
import java.util.Random;
import java.util.function.Predicate;
@ZenClass(ZenTriggers.ZEN_PACKAGE + ".WorldTickPredicateBuilder")
@ZenRegister
public class WorldTickPredicateBuilder {
private static final Random rand = new Random();
static {
rand.setSeed(1);
}
private final ArrayDeque<Predicate<World>> predicates = new ArrayDeque<>();
@ZenMethod
public static WorldTickPredicateBuilder create() {
return new WorldTickPredicateBuilder();
}
public boolean test(World world) {
return predicates.stream().allMatch(p -> p.test(world));
}
@ZenMethod
public WorldTickPredicateBuilder negateLatest() {
predicates.push(predicates.pop().negate());
return this;
}
@ZenMethod
public WorldTickPredicateBuilder isNthTick(int x) {
predicates.push((world) -> world.getTotalWorldTime() % x == 0);
return this;
}
@ZenMethod
public WorldTickPredicateBuilder isRandom(double chance) {
predicates.push((world) -> rand.nextDouble() < chance);
return this;
}
@ZenMethod
public WorldTickPredicateBuilder isRemote() {
predicates.push((world) -> world.isRemote);
return this;
}
@ZenMethod
public WorldTickPredicateBuilder isDay() {
predicates.push(World::isDaytime);
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment