#get all chests inside an area
1 messages · Page 1 of 1 (latest)
What you want to do?
I'm asking you so I can optimize the code.
he wants to get all empty chests in a provided area like
let chests = getEmptyChests (-1, -1, 1, 1, 20, 'overworld')
// function getEmptyChests (xStart: number, zStart: number, xEnd, zEnd: number, y: number, dimensionId: string): block[] | undefined
I understand that, but what is the purpose? If he only wants to run it at a certain time, there won't be much of a problem, but if he wants to do it at an interval, it will increase the tps.
i think he wants the run on purpose
import { world, BlockInventoryComponent } from "@minecraft/server";
const dimension = world.getDimension('overworld');
function getEmptyChestsOnArea(inicio, final) {
const chestsEncontrados = [];
for (let x = inicio.x; x <= final.x; x++) {
for (let y = inicio.y; y <= final.y; y++) {
for (let z = inicio.z; z <= final.z; z++) {
const block = dimension.getBlock({ x, y, z });
if (block.typeId === 'minecraft:chest') {
const chestInv = block.getComponent(BlockInventoryComponent.componentId).container;
if (chestInv.emptySlotsCount === 27 || 56) {
chestsEncontrados.push(block);
}
}
}
}
}
return chestsEncontrados;
}
const inicio = { x: -1, y: -61, z: 0 };
const final = { x: -1, y: -61, z: 0 };
const chests = getEmptyChestsOnArea(inicio, final);
for (const chest of chests) {
world.sendMessage(chest.typeId);
}```
If the area is very large it will reduce the tps of the world.
@covert elbow woudl this even work?
Work
i didnt knowed that, nice
Although there could be problems if a large chest has 27 free spaces
can you check if its a large chest?
like
if (emptySlots === (chest.isLarge ? 57 || 27)) { ... }
I'm pretty sure if you can get the specific block, you can check it's inventory size and see if it's larger than 27 or exactly 54
true
If the area is too big this might lag the game and trigger the watchdog. You can use system.runJob in that case.
Do you think you could make this work for me if they are outside of spawn and pvp if I give u the cords and they are in the cords (or a way to make it not run EVERY player cus of it being a 40 player bds server) as a example 2000 100 2000 - -1000 100 2010 like a gaint line
Because I need it to be a system to detect if they are in the vault generating path area and not be laggy
I made the other two types of anti-vault raiding but I need this one
You have very limited options. In order for it to detect and check the vault generating path it will need to check every player in the world. Otherwise, how would it conditionally verify? So if you have 40 players in the world, then that code, which is very expensive, is going to create a lot of lag.
You choosing a specific location to run the code don't prevent that lag. It will only minimize the chances of it happening. Let a bunch of players simultaneously go to that location and you will surely experience it, as will they.
I'm not sure what a Vault is, can you explain?
Ohh so what your saying is to only check in the vault generating line?
My server is a KitPvP and almost every one has Vaults for people to have moe storage as like a Vault in a bank and this is kinda like how they vaults generate
I don't see how this is similar to what the original question asked.
Why would you need to find all the chests in this area?
I dont want to find the chests
I am looking to see if they are in the path because they could .tp and make it there
Wait is it possible to check if they .tp?
You should probably make a different thread if your question isn't about finding chests.
But yeah, you should be able to make it so they can't teleport into a certain area. Or you can make it so they can't access chests in vaults that aren't their own. I'm not sure why you would let players teleport anywhere they want to in a PVP server anyway, but maybe I'm not understanding something.
