
IllegalAccessError when trying to check for blocks in world
Partonetrain opened this issue ยท 1 comments
I'm trying to check for certain blocks in the world through some clever scripting, like so:
import mods.zensummoning.SummoningDirector;
import mods.zensummoning.SummoningAttempt;
import mods.zensummoning.SummoningInfo;
import mods.zensummoning.MobInfo;
import crafttweaker.api.block.Block;
import crafttweaker.api.util.math.BlockPos;
import crafttweaker.api.world.Level;
SummoningDirector.addSummonInfo(
SummoningInfo.create()
.setCatalyst(<item:minecraft:stick>)
.setConsumeCatalyst(false)
.setReagents([<item:minecraft:diamond>])
.addMob(MobInfo.create()
.setMob(<entityType:minecraft:cow>)
.setCount(4)
.setOffset(0,4,0)
.setSpread(1,1,1)
)
.setMutator((attempt as SummoningAttempt) => {
if (CheckBlocks(attempt, 0, -1, 0) == <block:minecraft:iron_block>) {
attempt.success = false;
attempt.message = "Need an iron block!";
} else {
attempt.message = "Woohoo!";
}
})
);
function CheckBlocks(attempt as SummoningAttempt, x as int, y as int, z as int) as Block{
return ((attempt.world.getBlockState(attempt.pos.offset(x, y, z)).block));
}
But this crashes the game:
Error: java.lang.IllegalAccessError: class j_util_function_Consumer_1 tried to access method 'net.minecraft.world.level.block.Block scripts.summons.CheckBlocks(ca.teamdman.zensummoning.common.summoning.SummoningAttempt, int, int, int)' (j_util_function_Consumer_1 and scripts.summons are in unnamed module of loader org.openzen.zenscript.javabytecode.JavaBytecodeRunUnit$ScriptClassLoader @132ba2ab)
I recognize this is probably not an intended feature of the mod, but it would be really nice to have. Let me know if there's a better way to do this, or if I shouldn't be trying at all :P
This is definitely an intended feature, seems the problem is that the mutator lambda can't see the method.
I was able to get it to work with this
import mods.zensummoning.SummoningDirector;
import mods.zensummoning.SummoningAttempt;
import mods.zensummoning.SummoningInfo;
import mods.zensummoning.MobInfo;
import crafttweaker.api.block.Block;
import crafttweaker.api.util.math.BlockPos;
import crafttweaker.api.world.Level;
SummoningDirector.addSummonInfo(
SummoningInfo.create()
.setCatalyst(<item:minecraft:stick>)
.setConsumeCatalyst(false)
.setReagents([<item:minecraft:diamond>])
.addMob(MobInfo.create()
.setMob(<entityType:minecraft:cow>)
.setCount(4)
.setOffset(0,4,0)
.setSpread(1,1,1)
)
.setMutator((attempt as SummoningAttempt) => {
if (attempt.world.getBlockState(attempt.pos.offset(0,-1,0)).block != <block:minecraft:iron_block>) {
attempt.success = false;
attempt.message = "Need an iron block!";
} else {
attempt.message = "Woohoo!";
}
})
);
(I also fixed the equality check in the if
statement)
LMK if still has issues :D