50 lines
2.3 KiB
Java
50 lines
2.3 KiB
Java
package com.thebrokenrail.scriptcraft.api.bridge;
|
|
|
|
import com.thebrokenrail.scriptcraft.api.block.CustomBlockEntity;
|
|
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
|
import com.thebrokenrail.scriptcraft.core.ValueUtil;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.entity.BlockEntity;
|
|
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() {
|
|
ScriptCraftCore.addBridge("World.getBlockState", args -> ((World) args[0]).getBlockState(new BlockPos((double) args[1], (double) args[2], (double) args[3])));
|
|
ScriptCraftCore.addBridge("World.setBlockState", args -> ((World) args[0]).setBlockState(new BlockPos((double) args[1], (double) args[2], (double) args[3]), (BlockState) args[4]));
|
|
|
|
ScriptCraftCore.addBridge("World.spawnEntity", args -> {
|
|
Entity entity = Registry.ENTITY_TYPE.get(new Identifier((String) args[4])).create((World) args[0]);
|
|
if (entity != null) {
|
|
entity.updatePosition(ValueUtil.toDouble(args[1], 0), ValueUtil.toDouble(args[2], 0), ValueUtil.toDouble(args[3], 0));
|
|
((World) args[0]).spawnEntity(entity);
|
|
return entity;
|
|
} else {
|
|
return null;
|
|
}
|
|
});
|
|
|
|
ScriptCraftCore.addBridge("World.getBlockEntity", args -> {
|
|
World world = (World) args[0];
|
|
BlockPos pos = new BlockPos(ValueUtil.toDouble(args[1], 0), ValueUtil.toDouble(args[2], 0), ValueUtil.toDouble(args[3], 0));
|
|
return world.getBlockEntity(pos);
|
|
});
|
|
|
|
ScriptCraftCore.addBridge("World.getCustomBlockEntity", args -> {
|
|
World world = (World) args[0];
|
|
BlockPos pos = new BlockPos(ValueUtil.toDouble(args[1], 0), ValueUtil.toDouble(args[2], 0), ValueUtil.toDouble(args[3], 0));
|
|
BlockEntity entity = world.getBlockEntity(pos);
|
|
if (entity instanceof CustomBlockEntity) {
|
|
return ((CustomBlockEntity) entity).getObjID();
|
|
} else {
|
|
return null;
|
|
}
|
|
});
|
|
|
|
ScriptCraftCore.addBridge("World.isClient", args -> ((World) args[0]).isClient());
|
|
}
|
|
}
|