#Using BlockVolume to check for a redstone signal around a block

1 messages · Page 1 of 1 (latest)

quick needle
#

Lots of forums from me haha. Wanna keep #1067535382285135923 clean. But uhh yea as the title says. How does one do that? I do lack particular skills to do this myself :P

Thiny I use: new BlockVolume({ x: +1, y: +1, z: +1 }, { x: -1, y: -1, z: -1 }).getBlockLocationIterator()

#

I might seem really stupid right now lol

copper trail
#
for (const loc of mc.BlockVolumeUtils.getBlockLocationIterator({ from: vec1, to: vec2 })){
    
}```
quick needle
copper trail
#

then its been removed ig

quick needle
#

what do I do then

#

BlockVolume.getBlockLocationIterator({from: { x: +1, y: +1, z: +1 }}, {to: { x: -1, y: -1, z: -1 }}) returns not a function

#
for (const loc of new BlockVolume({ x: +1, y: +1, z: +1 }, { x: -1, y: -1, z: -1 }).getBlockLocationIterator()){
                console.warn(`${JSON.stringify(loc)}`)
            }```

This seemed to have worked. Now I need to find a block w redstone
copper trail
#
Object.defineProperty(Vector, 'locationsBetween', {
    value(loc1, loc2) {
        const locations = []
        const { x: min_x, y: min_y, z: min_z } = this.min(loc1, loc2)
        const { x: max_x, y: max_y, z: max_z } = this.max(loc1, loc2)

        for (let x = min_x; x < max_x + 1; x++) {
            for (let y = min_y; y < max_y + 1; y++) {
                for (let z = min_z; z < max_z + 1; z++) {
                    locations.push({ x, y, z })
                }
            }
        }
        return locations
    }
})
#
for (const loc of Vector.locationsBetween(loc1, loc2)) {

}
quick needle
#

wow

#

big code

quick needle
#

Wow this is complicated then

#

they removed vector in one of the .80 previews

copper trail
#

rip

#

use vec3 then

quick needle
#

Yah, been using that since

#

im a noob idk what to do here CRY

copper trail
#

fine ok

quick needle
copper trail
#

function vectorsBetween(loc1, loc2) {
    const locations = []
    const [min_x, max_x] = loc1.x < loc2.x ? [loc1.x, loc2.x] : [loc2.x, loc1.x]
    const [min_y, max_y] = loc1.y < loc2.y ? [loc1.y, loc2.y] : [loc2.y, loc1.y]
    const [min_z, max_z] = loc1.z < loc2.z ? [loc1.z, loc2.z] : [loc2.z, loc1.z]

    for (let x = min_x; x < max_x + 1; x++) {
        for (let y = min_y; y < max_y + 1; y++) {
            for (let z = min_z; z < max_z + 1; z++) {
                locations.push({ x, y, z })
            }
        }
    }
    return locations
}
#

;-;

quick needle
#

I'm sorry <3

copper trail
#

im in the mood np

quick needle
#

what about the for loop thinb (:

copper trail
#
for (const loc of vectorsBetween(loc1, loc2)) {

}
quick needle
#

expected. loc1 and loc2 are the locations for what now? block locations where the check is running from, in my case a door?

copper trail
#

pintA and pointB

quick needle
#

using vec3 yes?

copper trail
#

yes

#

location works

quick needle
#

okay cool. then I find block IDs inside that area to then run code, like in my case lever + redstone = code

copper trail
#

make sure it's block.location

#

w/o float

quick needle
#

I can just round it?

copper trail
#

floor

quick needle
#

yea that obe

#

I'll send the code here when done :p

copper trail
#

alr

quick needle
#

oop :<

for (const loc of vectorsBetween({x:-1, y:0, z:-1},{x:1, y:3, z:1})) {
                if(e.block.typeId == 'minecraft:stone' && loc){
                    console.warn(`test`)
                }
            }

I uhh ba_flustered

copper trail
#

e.block.dimension.getBlock(loc).typeId

#

why not use up(), down() etc

#
const dim = e.block.dimension
for (const loc of vectorsBetween({ x: -1, y: 0, z: -1 }, { x: 1, y: 3, z: 1 })) {
    if (dim.getBlock(loc).typeId == 'minecraft:stone') {
        console.warn(`test`)
    }
}
quick needle
#

wait this is odd it does not work and no error logs too wolfconfused

#

It should work

#

oh undefined

copper trail
#

unloaded chunk?

quick needle
#

could it be x: -1, y: 0, z: -1?

#

should probs use e.block.above and so on

#

nope it has to be numbers

#

oh right 😭 floor

grizzled slate
#

to @minecraft/math

quick needle
#

Yea but cant import it yet

grizzled slate
#

you can download it and import it

quick needle
# copper trail ```js const dim = e.block.dimension for (const loc of vectorsBetween({ x: -1, y:...
}
            const dim = e.block.dimension
            for (const loc of vectorsBetween({ x: Math.floor(e.block.location.x -1), y: 0, z: Math.floor(e.block.location.z -1) }, { x: Math.floor(e.block.location.x +1), y: 3, z: Math.floor(e.block.location.z +1) })) {
                console.warn(dim.getBlock(loc)?.typeId == 'dirt')
            if (dim.getBlock(loc)?.typeId == 'dirt') {
                console.warn(`testtt`)
    }

dim.getBlock(loc)?.typeId == 'dirt' seems to always return false even if there is a dirt block inside the volume

grizzled slate
#

there is a native way to get vectors inside a volume

copper trail
#

minecraft:durt

#

Blud needs a break ong

quick needle
copper trail
#

ong

quick needle
#

idk wht this tuff no work I ain't got brains for nothin

quick needle
grizzled slate
quick needle
#

need one but I love doing addon

quick needle
#

I don't keep up with the changelogs

copper trail
#

Name changes REEEEE

grizzled slate
#

xd

quick needle
onyx willow
#

What is the end goal? Are you trying to find out how much redstone power your block has?

quick needle
#

nope. Wanna find a redstone signal around the base block (the door)

onyx willow
#

Am I misunderstanding? E.g. if your block is being powered by redstone? Or just if things around it are?

#

Because it sounds like you want to just use getRedstonePower() to find the signal sum around your block

quick needle
#

If lever around block (anywhere around block) is powered, base block does something

onyx willow
#

Yeah, that sounds like what getRedstonePower() would do

quick needle
#

Yea but idk how to check around the base block

onyx willow
#

You don't need to? getRedstonePower() sums up all redstone power that is being applied to the block you call it on

#

It handles the adjacent block checks for you

quick needle
#

since when did that happen?

onyx willow
#

It's in beta, but seeing as how you're using BlockVolume you're using beta anyway

quick needle
#

yea I am preparing for .80 stable

quick needle
onyx willow
quick needle
#

hmm. Yea i did getRedstonePower but it just does nothing for me. I'll see what it returns

#

my good ol' friend undefined

onyx willow
#

Can you send a screenshot of what you're describing the set-up to look like? I can provide a better answer if I understand what you're talking about; because I haven't really understood your descriptions so far

quick needle
#

idk if it helps

onyx willow
#

Yeah, it does. Which block is your door's block? The bottom or the top

quick needle
#

both are the same

#

1 block 2 states

onyx willow
#

Mm, I see. And you want something to happen when any redstone is powered into your door blocks - such as the level or the pressure plate

quick needle
#

yep

grizzled slate
#

where the volume start and end in

quick needle
#

around the door

#

start: x -1 z -1
end: x1 y3, x1

#

from door location

onyx willow
# quick needle yep

That makes sense. What you want is to check adjacent blocks with getRedstonePower() then.

#

"15" is what getRedstonePower() returns for the strongest signal

quick needle
#

idk how to explain

onyx willow
#

Ah, I see. One moment then (unless someone else comes along and solves it)

grizzled slate
#

try this

const vol = {from:{x:6,y:-52,z:29},to:{x:6,y:-52,z:47}} //your volume 
const vectors = BlockVolumeUtils.getBlockLocationIterator(vol)
const isPowered = isRedstonePowered(vectors,door.dimension)

function isRedstonePowered(vectors,dimension) {
    for(const vec of vectors){
        const block = dimension.getBlock(vec)
        if(block.getRedstonePower() !== 0) return true;
    }
    return false
}

import BlockVolumeUtils BlockVolumeBase

onyx willow
#

Because you need more than just adjacent blocks - as levers are outside the range (since they're attached to blocks) Strike that, levers give redstone to the block they pull on.

quick needle
onyx willow
onyx willow
#

It takes two constructors - a from and to. So you'll need to separate the vector object he gave you as well.

quick needle
#

Yea I used it when I struggled haha

onyx willow
#

Actually, I'm not entirely sure why the need for the volume at all. You can just check the east(), west(), north(), south() adjacent blocks of each door block.

quick needle
#

did that and it resulted in quite a mess

onyx willow
#

That sounds like an implementation problem, because it would work quite cleanly.

function isBlockPowered(block: Block): boolean{
    return 
        (block.east()?.getRedstonePower() >= 0)
        || (block.south()?.getRedstonePower() >= 0)
        || (block.west()?.getRedstonePower() >= 0)
        || (block.north()?.getRedstonePower() >= 0);
}
quick needle
#

I'll give it a try

onyx willow
#

Remove the = in that code, I don't know why I put it there. It should just be >

onyx willow
#

Sorry, remove the types and it'll work for your JS codebase

quick needle
#
  function isBlockPowered(block) {
                
                    (block.east()?.getRedstonePower() >= 0)
                    || (block.south()?.getRedstonePower() >= 0)
                    || (block.west()?.getRedstonePower() >= 0)
                    || (block.north()?.getRedstonePower() >= 0);
return 
            }```
#
 const state = permutation.getState("test:door_open");
 if (!isBlockPowered(e.block) == false && state == true) {
                if (e.block.permutation.getState("test:door_open") == false) {
                    e.block.dimension.runCommand('playsound close.wooden_door @p')
                }
                above.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state).withState("pog:custom_door", "top_bit"));
                e.block.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state));

            }```

This is what I use to listen for redstone. Might be wrong or im just dumb
grizzled slate
#

btw are you using onRandomTick?

quick needle
#

onTick

#

range from 0.1 to 0.2

#

so like instant

#

ticks every tick

grizzled slate
#

ok

quick needle
#

idk what I am doing wrong

quick needle
quick needle
#

think I am doing the entire thing wrong :<

#

Okay rewrote some of my code and it seems to work

grizzled slate
#

@quick needle
this is working for me
blockVolume is not a good idea since it check corners

    const lowerBlock = block;
    const upperBlock = lowerBlock.above();
    const blocks = [
        lowerBlock,
        lowerBlock.north(),
        lowerBlock.south(),
        lowerBlock.east(),
        lowerBlock.below(),
        upperBlock,
        upperBlock.north(),
        upperBlock.south(),
        upperBlock.east(),
        upperBlock.west(),
        upperBlock.above(),
    ];
    const redstonePowered = blocks.some(block => block.getRedstonePower() !== 0);
    console.warn(redstonePowered);
quick needle
grizzled slate
#

wired

quick needle
#

is there a way to make it check for 1 redstone signal of 15 and not all?

#

Cuz when I do this. the door at the lever side keeps opening and closing until redstone is lost there from either the plate or lever

grizzled slate
#

that what array.some dose

#

bruh
now console.warn sroped working

quick needle
#
  if (((left == 15) || (right == 15) ||( forward == 15) ||( bacward == 15))) {

                if(state == true) return
                if(e.block.permutation.getState("pog:custom_door") == "default") {
                above.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state).withState("pog:custom_door", "top_bit"));
                e.block.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state));
               }
                if (e.block.permutation.getState("test:door_open") == false) {
                    e.block.dimension.runCommand('playsound close.wooden_door @p')
                }
            }```

Code I use rn
grizzled slate
#

doors open in redstone signal of 1 and above

quick needle
#

this is just to test

quick needle
#
 if (((left == 15) || (right == 15) ||( forward == 15) ||( bacward == 15))) {

                if(state == true) return
                if(e.block.permutation.getState("pog:custom_door") == "default") {
                above.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state).withState("pog:custom_door", "top_bit"));
                e.block.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state));
               }
                if (e.block.permutation.getState("test:door_open") == false) {
                    e.block.dimension.runCommand('playsound close.wooden_door @p')
                }
            } else
            if (((left == 0) || (right == 0) ||( forward == 0) ||( bacward == 0))) {

                if(state == false) return
                if(e.block.permutation.getState("pog:custom_door") == "default") {
                above.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state).withState("pog:custom_door", "top_bit"));
                e.block.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state));
               }
                if (e.block.permutation.getState("test:door_open") == false) {
                    e.block.dimension.runCommand('playsound close.wooden_door @p')
                }
            }

            if (((left == 15) || (right == 15) ||( forward == 15) ||( bacward == 15))) {

                if(state == true) return
                if(e.block.permutation.getState("pog:custom_door") == "top_bit") {
                below.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state).withState("pog:custom_door", "default"));
                e.block.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state));
               }
                if (e.block.permutation.getState("test:door_open") == false) {
                    e.block.dimension.runCommand('playsound close.wooden_door @p')
                }
            } else
            if (((left == 0) || (right == 0) ||( forward == 0) ||( bacward == 0))) {

                if(state == false) return
                if(e.block.permutation.getState("pog:custom_door") == "top_bit") {
                below.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state).withState("pog:custom_door", "default"));
                e.block.setPermutation(BlockPermutation.resolve("better_on_bedrock:chorus_door_bottom", e.block.permutation.getAllStates()).withState("test:door_open", !state));
               }
                if (e.block.permutation.getState("test:door_open") == false) {
                    e.block.dimension.runCommand('playsound close.wooden_door @p')
                }
            }```

(Ugly code ik)
quick needle
#

never figured it out

#

I think I need blockstates for redstone. Will do this tomorrow tho.