#Using BlockVolume to check for a redstone signal around a block
1 messages · Page 1 of 1 (latest)
for (const loc of mc.BlockVolumeUtils.getBlockLocationIterator({ from: vec1, to: vec2 })){
}```
2 questions
- what is the mc. thing
- do BlockVolumeUtils exist cuz I can't seem to import it from server
then its been removed ig
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
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)) {
}
this is just setup
fine 

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
}
;-;
I'm sorry <3
what about the for loop thinb (:
for (const loc of vectorsBetween(loc1, loc2)) {
}
expected. loc1 and loc2 are the locations for what now? block locations where the check is running from, in my case a door?
pintA and pointB
using vec3 yes?
okay cool. then I find block IDs inside that area to then run code, like in my case lever + redstone = code
I can just round it?
floor
alr
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 
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`)
}
}
good point actually
wait this is odd it does not work and no error logs too 
It should work
oh undefined
unloaded chunk?
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
they just moved it
to @minecraft/math
Yea but cant import it yet
you can download it and import it
}
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
there is a native way to get vectors inside a volume
wdym durt
ong
idk wht this tuff no work I ain't got brains for nothin

they didn't remove BlockVolumeUtils
they change it to BlockVolumeBase
need one but I love doing addon
:< oh
I don't keep up with the changelogs
Name changes 
xd
ahhh this gets the door block and not my redstone blocks 
What is the end goal? Are you trying to find out how much redstone power your block has?
nope. Wanna find a redstone signal around the base block (the door)
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
If lever around block (anywhere around block) is powered, base block does something
Yeah, that sounds like what getRedstonePower() would do
Yea but idk how to check around the base block
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
since when did that happen?
It's in beta, but seeing as how you're using BlockVolume you're using beta anyway
yea I am preparing for .80 stable
that then means the "block" as to be a solid
Not sure what you mean here? Every block is just a voxel and the MC functions are agnostic to their solidity unless specifically mentioned
hmm. Yea i did getRedstonePower but it just does nothing for me. I'll see what it returns
my good ol' friend undefined
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
Yeah, it does. Which block is your door's block? The bottom or the top
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
yep
where the volume start and end in
That makes sense. What you want is to check adjacent blocks with getRedstonePower() then.
"15" is what getRedstonePower() returns for the strongest signal
Yea thats what we tried here but this seems to return true if it finds the dorr block instead of a redstone block w a power
idk how to explain
Ah, I see. One moment then (unless someone else comes along and solves it)
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
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.
BlockVolumeUtils is BlockVolumeBase? (based on old message)
Looking at this (use the new BlockVolume instead), this will solve your door problem. So long as your volume is accurately defined.
Use BlockVolume not Base. Base is an abstract class.
It takes two constructors - a from and to. So you'll need to separate the vector object he gave you as well.
Yea I used it when I struggled haha
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.
did that and it resulted in quite a mess
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);
}
I'll give it a try
Remove the = in that code, I don't know why I put it there. It should just be >
typescript 
Sorry, remove the types and it'll work for your JS codebase
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
btw are you using onRandomTick?
ok
idk what I am doing wrong
This returns undefined
think I am doing the entire thing wrong :<
Okay rewrote some of my code and it seems to work
@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);
this keeps returning true for me idk why
wired
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
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
doors open in redstone signal of 1 and above
this is just to test
This is for the bottom part of the door. When I do the same but for the top bit, it freaks out when there are 1 active and 1 disabled redstone block
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)

