Search in sources :

Example 1 with RadarObject

use of com.builtbroken.mc.lib.world.radar.data.RadarObject in project Engine by VoltzEngine-Project.

the class RadarMap method update.

/**
     * Called at the end of every world tick to do checks on
     * data stored.
     */
public void update() {
    debug.start("Update", "Objects: " + allEntities.size() + "  Chunks: " + chunk_to_entities.size());
    if (ticks++ >= UPDATE_DELAY && chunk_to_entities.size() > 0) {
        ticks = 0;
        //TODO consider multi-threading if number of entries is too high (need to ensure runs in less than 10ms~)
        debug.start("Looking for invalid radar objects and updating position data");
        HashMap<RadarObject, ChunkCoordIntPair> removeList = new HashMap();
        List<RadarObject> addList = new ArrayList();
        for (Map.Entry<ChunkCoordIntPair, List<RadarObject>> entry : chunk_to_entities.entrySet()) {
            if (entry.getValue() != null) {
                for (RadarObject object : entry.getValue()) {
                    if (entry.getKey() != object.getChunkCoordIntPair()) {
                        debug.log("Removed from map: " + object);
                        removeList.put(object, entry.getKey());
                        if (object.isValid()) {
                            addList.add(object);
                            debug.log("Queued for re-add");
                        }
                    }
                }
            }
        }
        debug.end();
        debug.start("Removing objects from map");
        for (Map.Entry<RadarObject, ChunkCoordIntPair> entry : removeList.entrySet()) {
            allEntities.remove(entry.getKey());
            List<RadarObject> list = chunk_to_entities.get(entry.getValue());
            if (list != null) {
                list.remove(entry.getKey());
                if (list.size() > 0) {
                    chunk_to_entities.put(entry.getValue(), list);
                } else {
                    chunk_to_entities.remove(entry.getValue());
                }
            } else {
                chunk_to_entities.remove(entry.getValue());
            }
        }
        debug.end();
        debug.start("Adding entries: " + addList.size());
        addList.forEach(this::add);
        debug.end();
        debug.start("Removing invalid objects");
        Iterator<RadarObject> it = allEntities.iterator();
        while (it.hasNext()) {
            RadarObject object = it.next();
            if (!object.isValid()) {
                debug.log("Removed: " + object);
                it.remove();
            }
        }
        debug.end();
    }
    debug.end();
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) RadarObject(com.builtbroken.mc.lib.world.radar.data.RadarObject)

Example 2 with RadarObject

use of com.builtbroken.mc.lib.world.radar.data.RadarObject in project Engine by VoltzEngine-Project.

the class CommandDebugMap method handleEntityPlayerCommand.

@Override
public boolean handleEntityPlayerCommand(EntityPlayer player, String[] args) {
    if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
        if (args[0].equalsIgnoreCase("radar")) {
        } else if (args[0].equalsIgnoreCase("tile") && args.length > 1) {
            if (args[1].equalsIgnoreCase("enableDebug")) {
                if (args.length > 2) {
                    RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                    if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("t")) {
                        map.setDebugEnabled(true);
                        player.addChatComponentMessage(new ChatComponentText("Debug enabled for tile map in your world."));
                    } else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("f")) {
                        map.setDebugEnabled(false);
                        player.addChatComponentMessage(new ChatComponentText("Debug disabled for tile map in your world."));
                    } else {
                        player.addChatComponentMessage(new ChatComponentText("Could not parse [" + args[2] + "], enable status can only be true or false"));
                    }
                    return true;
                } else {
                    RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                    if (!map.debugRadarMap) {
                        map.setDebugEnabled(true);
                        player.addChatComponentMessage(new ChatComponentText("Debug enabled for tile map in your world."));
                    } else {
                        map.setDebugEnabled(false);
                        player.addChatComponentMessage(new ChatComponentText("Debug disabled for tile map in your world."));
                    }
                    return true;
                }
            } else if (args[1].equalsIgnoreCase("objects")) {
                RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                if (map.allEntities.size() > 0) {
                    player.addChatComponentMessage(new ChatComponentText("There are " + map.allEntities.size() + " tiles in the map."));
                } else {
                    player.addChatComponentMessage(new ChatComponentText("No tiles detected in global tile list."));
                }
                return true;
            } else if (args[1].equalsIgnoreCase("chunks")) {
                RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                if (map.chunk_to_entities.size() > 0) {
                    player.addChatComponentMessage(new ChatComponentText("There are " + map.chunk_to_entities.size() + " chunk locations in the map."));
                } else {
                    player.addChatComponentMessage(new ChatComponentText("No chunks detected in map."));
                }
                return true;
            } else if (args[1].equalsIgnoreCase("around")) {
                int range = 100;
                if (args.length > 2) {
                    try {
                        range = Integer.parseInt(args[2]);
                    } catch (NumberFormatException e) {
                        player.addChatComponentMessage(new ChatComponentText("Invalid range number"));
                        return true;
                    }
                }
                RadarMap map = TileMapRegistry.getRadarMapForWorld(player.worldObj);
                List<RadarObject> list = map.getRadarObjects(player.posX, player.posZ, range);
                if (list.size() > 0) {
                    player.addChatComponentMessage(new ChatComponentText("There are " + list.size() + " tiles within " + range + " meters"));
                } else {
                    player.addChatComponentMessage(new ChatComponentText("No tiles detected in within " + range + " meters"));
                }
                return true;
            }
            return handleHelp(player, args);
        } else if (args[0].equalsIgnoreCase("heat")) {
        }
    }
    return handleHelp(player, args);
}
Also used : RadarMap(com.builtbroken.mc.lib.world.radar.RadarMap) RadarObject(com.builtbroken.mc.lib.world.radar.data.RadarObject) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

RadarObject (com.builtbroken.mc.lib.world.radar.data.RadarObject)2 RadarMap (com.builtbroken.mc.lib.world.radar.RadarMap)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)1