oreveins indicators: use api to replace block instead of chat command.

This commit is contained in:
Wroclaw 2022-11-19 21:55:52 +01:00
parent 08e56ccc40
commit 3f08eebabe
3 changed files with 35 additions and 27 deletions

View file

@ -1,9 +1,16 @@
#loader contenttweaker
import crafttweaker.block.IBlock;
import crafttweaker.block.IBlockState;
import crafttweaker.data.IData;
import crafttweaker.world.IBlockPos;
import crafttweaker.world.IWorld;
import mods.contenttweaker.Block;
import mods.contenttweaker.BlockPos;
import mods.contenttweaker.DropHandler;
import mods.contenttweaker.ResourceLocation;
import mods.contenttweaker.VanillaFactory;
import mods.contenttweaker.World;
var nugget_table as string[][] = [
# [name, id, meta]
@ -38,24 +45,29 @@ var nugget_table as string[][] = [
["certus_quartz", "appliedenergistics2:material", "0"]
];
function replaceCommand(blockName as string, item as string, meta as string, blockPos as mods.contenttweaker.BlockPos) as string {
return "execute @a " +
blockPos.getX() as string + " " +
blockPos.getY() as string + " " +
blockPos.getZ() as string + " " +
"detect " +
blockPos.getX() as string + " " +
blockPos.getY() as string + " " +
blockPos.getZ() as string + " " +
"contenttweaker:" + blockName + " * " +
"setblock " +
blockPos.getX() as string + " " +
blockPos.getY() as string + " " +
blockPos.getZ() as string + " " +
"draconicevolution:placed_item " +
"0 " +
"replace " +
"{InventoryStacks: [{ id: \"" + item + "\", Count: 1, Damage: " + meta as string + " }]}";
function replace(
item as string,
meta as string,
blockPos as mods.contenttweaker.BlockPos,
world as World
)
{
if (world.isRemote()) { return null; }
# janky hack, mate
var trueWorld as IWorld = IWorld.getFromID(world.getDimension());
var nbt as IData = {
Facing: 0 as byte,
InventoryStacks: [{
id: item as string,
Count: 1 as byte,
Damage: meta as short
}]
};
var position as IBlockPos = crafttweaker.util.Position3f.create(blockPos.getX(), blockPos.getY(), blockPos.getZ()).asBlockPos();
trueWorld.setBlockState(<blockstate:draconicevolution:placed_item:facing=down>, nbt, position);
}
for i in nugget_table {
@ -77,20 +89,16 @@ for i in nugget_table {
block.setPassable(true);
block.setReplaceable(true);
# janky hack, mate
block.setOnBlockPlace(function(world, blockPos, blockState) {
var command as string = replaceCommand(blockName, item, meta, blockPos);
server.commandManager.executeCommand(server, command);
replace(item, meta, blockPos, world);
});
block.setOnRandomTick(function(world, blockPos, blockState) {
var command as string = replaceCommand(blockName, item, meta, blockPos);
server.commandManager.executeCommand(server, command);
replace(item, meta, blockPos, world);
});
block.setOnUpdateTick(function(world, blockPos, blockState) {
var command as string = replaceCommand(blockName, item, meta, blockPos);
server.commandManager.executeCommand(server, command);
replace(item, meta, blockPos, world);
});
block.register();