2020-04-25 13:33:17 +00:00
|
|
|
package com.thebrokenrail.scriptcraft.bridge;
|
|
|
|
|
|
|
|
import com.thebrokenrail.scriptcraft.util.Util;
|
|
|
|
import net.minecraft.block.BlockState;
|
2020-04-26 17:23:16 +00:00
|
|
|
import net.minecraft.block.entity.BlockEntity;
|
2020-04-25 13:33:17 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2020-04-26 17:23:16 +00:00
|
|
|
|
|
|
|
Bridges.addBridge("World.markBlockEntityDirty", args -> {
|
|
|
|
World world = (World) args[0];
|
|
|
|
BlockPos pos = new BlockPos(Util.toDouble(args[1], 0), Util.toDouble(args[2], 0), Util.toDouble(args[3], 0));
|
|
|
|
BlockEntity entity = world.getBlockEntity(pos);
|
|
|
|
if (entity != null) {
|
|
|
|
entity.markDirty();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2020-04-25 13:33:17 +00:00
|
|
|
}
|
|
|
|
}
|