From 3f08eebabecd944a5cdf61e08ac8d1884a24d52b Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 19 Nov 2022 21:55:52 +0100 Subject: [PATCH] oreveins indicators: use api to replace block instead of chat command. --- index.toml | 2 +- pack.toml | 2 +- scripts/ore_veins/indicators.1.zs | 58 ++++++++++++++++++------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/index.toml b/index.toml index 093bcae..f8320fa 100644 --- a/index.toml +++ b/index.toml @@ -2405,7 +2405,7 @@ hash = "a07879875ad20ae8e285c3cb39beeee648bd080ec12985b76583ad707a3de3ee" [[files]] file = "scripts/ore_veins/indicators.1.zs" -hash = "5ddde773d2f8fe5bac324bb03497776b694eadbef6626f23cf7a9e755f4009ee" +hash = "36e4b9ee448ad7503f5df16b788e95a0f69bb24a55041c33a87b45c347e57d7f" [[files]] file = "scripts/ore_veins/indicators.2.zs" diff --git a/pack.toml b/pack.toml index 192cb79..a242d70 100644 --- a/pack.toml +++ b/pack.toml @@ -6,7 +6,7 @@ pack-format = "packwiz:1.1.0" [index] file = "index.toml" hash-format = "sha256" -hash = "504d3886965baa0eab50adab674ea9afbcc3ec12472a90c8c91ce91958499dcf" +hash = "42ca8e723c1e0761d17e371bcd988f0fe299aa09f3c914f0c1183e7c85099d96" [versions] forge = "14.23.5.2860" diff --git a/scripts/ore_veins/indicators.1.zs b/scripts/ore_veins/indicators.1.zs index 2733429..0985180 100644 --- a/scripts/ore_veins/indicators.1.zs +++ b/scripts/ore_veins/indicators.1.zs @@ -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(, 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();