CraftTweaker / ZenScript

MIT License
77 stars 22 forks source link

I want to put more values in a multidim-Array #14

Closed cyberpunkbln closed 5 years ago

cyberpunkbln commented 6 years ago

Hello,

a short question: i have analyzed code from the great sevtechages-modpack and i have maked an script for drops and dropchances.

drops.zs
#priority 720

import crafttweaker.block.IBlock;
import crafttweaker.item.IItemStack;

static blockHarvestDrops as IItemStack[][string] =
{
    "minecraft:stone":
    [
        <minecraft:stone>,
        <minecraft:dirt>
    ]
};

static blockHarvestDropChance as float[string] =
{
    "minecraft:stone": 0.5
};

blockbreakevent.zs
#priority 500

import crafttweaker.events.IEventManager;
import crafttweaker.event.IBlockEvent;
import crafttweaker.event.BlockHarvestDropsEvent;
import scripts.Drops.blockHarvestDrops;
import scripts.Drops.blockHarvestDropChance;

events.onBlockHarvestDrops (function (event as BlockHarvestDropsEvent)
{
    var blockId = event.block.definition.id;
    if (event.block.meta != 0)
    {
        blockId += ":" ~ event.block.meta;
    }
    if (event.silkTouch)
    {
        return;
    }
    var hasOverride = !isNull(blockHarvestDrops[blockId]);
    if (hasOverride)
    {
        for i, block in blockHarvestDrops[blockId]
        {
            if (i == 0)
            {
                event.drops = block.items;
                if (!isNull (blockHarvestDropChance[block.definition.id])) event.dropChance=blockHarvestDropChance[block.definition.id]);
            }
            else
            {
                event.drops += block;
                if (!isNull (blockHarvestDropChance[block.definition.id])) event.dropChance=blockHarvestDropChance[block.definition.id]);
            }
        }

    }
    else
    {
//to prevent some things happend:)
    }

});

I want to use the static array blockHarvestDrops with one more dims on the array, like dropchance and reset the old drops boolean.

"minecraft:stone": [

, ] with the additional values for dropChance each IItemStack and for the boolean value to reset the old drops from minecraft:stone. Or an choice to bind the both static multi-arrays each other. thx ps: yes i know the dropChance is only for the dropped block and not setable for each drop:(. Also only a variable for the broken block.
kindlich commented 6 years ago

I do not completely understand what you are trying to do, but any data type apart from dictionaries, lists or arrays would not be suited for the basic ZS implementation.

If you join us on Jared's discord though, I can walk you through the way of creating more advanced structures from within ZS. discord.blamejared.com

kindlich commented 5 years ago

Closing this since I do not know what exactly you want and you didn't really answer. If this is still an issue, feel free to join aforementioned discord or add a message here.