This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/src/main/java/com/thebrokenrail/scriptcraft/bridge/WorldBridges.java

28 lines
1.2 KiB
Java

package com.thebrokenrail.scriptcraft.bridge;
import com.thebrokenrail.scriptcraft.util.Util;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
class WorldBridges {
static void register() {
Bridges.addBridge("World.getBlockState", args -> ((World) args[0]).getBlockState(new BlockPos((double) args[1], (double) args[2], (double) args[3])));
Bridges.addBridge("World.setBlockState", args -> ((World) args[0]).setBlockState(new BlockPos((double) args[1], (double) args[2], (double) args[3]), (BlockState) args[4]));
Bridges.addBridge("World.spawnEntity", args -> {
Entity entity = Registry.ENTITY_TYPE.get(new Identifier((String) args[4])).create((World) args[0]);
if (entity != null) {
entity.updatePosition(Util.toDouble(args[1], 0), Util.toDouble(args[2], 0), Util.toDouble(args[3], 0));
((World) args[0]).spawnEntity(entity);
return entity;
} else {
return null;
}
});
}
}