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

2
index.toml generated
View file

@ -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"

View file

@ -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"

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();