#Custom raytracer crashing server

1 messages · Page 1 of 1 (latest)

sour wedge
#

so i have this run every 2 seconds using bukkit scheduler

#
        DBCursor cursor = collection.find();
        try {
            while(cursor.hasNext()) {
                Map res =  cursor.next().toMap();
                int x = (int) res.get("x");
                int y = (int) res.get("y");
                int z = (int) res.get("z");
                String ownerId = (String) res.get("ownerId");
                World world = Bukkit.getWorld(res.get("world").toString());
                Player owner = Bukkit.getPlayer(UUID.fromString(res.get("uuid").toString()));
                Location cameralocation = new Location(world, x, y,z);
                Collection<Entity> possible = Objects.requireNonNull(cameralocation.getWorld()).getNearbyEntities(cameralocation, 10.0, 10.0, 10.0);
                for (Entity entity : possible)
                    if(entity instanceof Player){
//                        if(entity != owner || owner == null){
                        if(true){
                            org.bukkit.util.Vector entityloc = new org.bukkit.util.Vector(entity.getLocation().getBlockX() - cameralocation.getBlockX(), entity.getLocation().getBlockY() - cameralocation.getBlockY(), entity.getLocation().getBlockZ() - cameralocation.getBlockZ());
                            org.bukkit.util.Vector entitylochead = new org.bukkit.util.Vector(entity.getLocation().getBlockX() - cameralocation.getBlockX(), entity.getLocation().getBlockY() - cameralocation.getBlockY() + 1, entity.getLocation().getBlockZ() - cameralocation.getBlockZ());
                            try {
                                List<Block> result = RayTracer.rayTraceBlocks(cameralocation, entityloc, 10);
                                LOGGER.severe(result.toString());
                                while (result.iterator().hasNext()) {
                                    Block item = result.iterator().next();
                                    if (item.getType() == Material.PETRIFIED_OAK_SLAB) {
                                        result.remove(item);
                                        if (result.isEmpty()) {
                                            LOGGER.severe("is empty now");
                                            String id = DiscordSRV.getPlugin().getAccountLinkManager().getDiscordId(UUID.fromString((String) res.get("uuid")));
                                            DiscordSRV.getPlugin().getJda().getUserById(id).openPrivateChannel().flatMap(channel -> channel.sendMessage(entity.getName() + " Is near your camera (" + cameralocation.getBlockX() + ", " + cameralocation.getBlockY() + ", " + cameralocation.getBlockZ() + ") You better log on and check")).queue();
                                            break;
                                        }
                                    }
                                }
                            }catch (Exception e){
                                LOGGER.warning(e.toString());
                            }```
#

ill put full code in paste bin actually

#

this is my scheduler

#

this is ray tracer code

hexed pond
#

can you explain a bit about the logic of your system?

#

like

#

why do you raytrace

#

nesting makes it hard to understand

sour wedge
#

i need to detect if a block(camera) can see a player nearby

#

but it ignores petrified oak slabs

#

if that makes sense

hexed pond
#

Why can't you use World#raytrace

sour wedge
#

if it hits itself the oak slab it says it cant see me

agile swift
#

Theres a while loop

sour wedge
#

and it dont return all blocks it hits only first

hexed pond
#

Set the ray size to a smaller number

sour wedge
sour wedge
#

i added an else for the
if (item.getType() == Material.PETRIFIED_OAK_SLAB) {
so it breaks ill see if that worked

#

ah this code isnt detecting if its hitting a player

#

ill try using just normal ray trace

torn sequoia
sour wedge
#

theres filter im trying to figure it now

#

unless theres different method

#

filter seems to be entity only

hexed pond
#

you can set transparent block types, no?

#

then just set everything as transparent

sour wedge
#

you mean oakslab

#

ill try that

sour wedge