#depot interaction in example script not working

21 messages · Page 1 of 1 (latest)

neon socket
#

trying: #archived-example-scripts message

brisk mistBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

velvet gorgeBOT
#

[Quote ➤](#archived-example-scripts message) Script that allows you to combine items on a Create depot

const Transaction = java('net.fabricmc.fabric.api.transfer.v1.transaction.Transaction')
const ItemVariant = java('net.fabricmc.fabric.api.transfer.v1.item.ItemVariant')

global.recipes = {
    create: {
        manual_depot_application: function (event, output, inputOnDepot, inputInHand) {
            if (event.block == 'create:depot' && event.block.entityData.HeldItem != undefined) {
                let depotItem = Item.of(event.block.entityData.HeldItem.Item.id, event.block.entityData.HeldItem.Item.Count, event.block.entityData.HeldItem.Item.tag)
                let handItem = event.player.mainHandItem
                if (inputOnDepot.equals(depotItem) && inputInHand.equals(handItem)) {
                    event.cancel()
                    tx = Transaction.openOuter()
                    if (depotItem.count > (handItem.count / inputInHand.count)) {
                        // If the remainder of ingredients is on the depot
                        event.player.give(Item.of(output, (handItem.count / inputInHand.count), output.nbt))
                        event.block.entity.getItemStorage(Direction.UP).extract(ItemVariant.of(Item.of(inputOnDepot).itemStack), (handItem.count / inputInHand.count), tx)
                    } else {
                        // If the remainder of the ingredients is in the hand, or equal
                        event.block.entity.getItemStorage(Direction.UP).extract(ItemVariant.of(Item.of(inputOnDepot).itemStack),  depotItem.count, tx)
                        event.block.entity.getItemStorage(Direction.UP).insert(ItemVariant.of(Item.of(output).itemStack), depotItem.count, tx)
                    }
                    handItem.count -= depotItem.count * inputInHand.count
                    tx.commit()
                }
            }
        }
    }
}
global.recipes.createManualDepotApplication = global.recipes.create.manual_depot_application```
neon socket
#
const ItemVariant = Java.loadClass('net.fabricmc.fabric.api.transfer.v1.item.ItemVariant')

global.recipes = {
    create: {
        manual_depot_application: function (event, output, inputOnDepot, inputInHand) {
            if (event.block == 'create:depot' && event.block.entityData.HeldItem != undefined) {
                let depotItem = Item.of(event.block.entityData.HeldItem.Item.id, event.block.entityData.HeldItem.Item.Count, event.block.entityData.HeldItem.Item.tag)
                let handItem = event.player.mainHandItem
                if (inputOnDepot.equals(depotItem) && inputInHand.equals(handItem)) {
                    event.cancel()
                    tx = Transaction.openOuter()
                    if (depotItem.count > (handItem.count / inputInHand.count)) {
                        // If the remainder of ingredients is on the depot
                        event.player.give(Item.of(output, (handItem.count / inputInHand.count), output.nbt))
                        event.block.entity.getItemStorage(Direction.UP).extract(ItemVariant.of(Item.of(inputOnDepot).itemStack), (handItem.count / inputInHand.count), tx)
                    } else {
                        // If the remainder of the ingredients is in the hand, or equal
                        event.block.entity.getItemStorage(Direction.UP).extract(ItemVariant.of(Item.of(inputOnDepot).itemStack),  depotItem.count, tx)
                        event.block.entity.getItemStorage(Direction.UP).insert(ItemVariant.of(Item.of(output).itemStack), depotItem.count, tx)
                    }
                    handItem.count -= depotItem.count * inputInHand.count
                    tx.commit()
                }
            }
        }
    }
}
global.recipes.createManualDepotApplication = global.recipes.create.manual_depot_application```
#

startup

#
    global.recipes.create.manual_depot_application(event,
        // Output
        Item.of('minecraft:sand'),
        // Inputs
        Ingredient.of('minecraft:stick'), // On depot
        Ingredient.of('minecraft:flint') // In hand
    )
})```
#

server

#

when I right click it simply replaces the item on the depot, exactly how it normally happens

#

no idea if something changed in code and this script is no longer valid

#

but it's certainly too complex for me to attempt changing parts of it

terse prism
#

is the error assignment to an unknown variable: tx or smth like that?

#

just add a let before the tx = Transaction.openOuter()

neon socket
#

wouldn't that trigger an error?

#

no difference anyway

#

@vagrant moon

vagrant moon
#

pretty sure Transaction is having an error, but i'm not familiar with Fabric and only made a forge port
you can ask Eldog though

neon socket
#

@rocky remnant

neon socket
#

(daily) bump

neon socket
#

(semi-daily) bump

rocky remnant
#

man i barely know how transactions work

#

i asked someone more knowledgeable about fabric to help me