Search in sources :

Example 1 with BlockEditSet

use of watson.db.BlockEditSet in project watson by totemo.

the class Controller method getBlockEditSet.

// --------------------------------------------------------------------------
/**
   * Return the current {@link BlockEditSet} under examination.
   *
   * A separate {@link BlockEditSet} is maintained for each dimension
   * (overworld, nether, end).
   *
   * @return the current {@link BlockEditSet} under examination.
   */
public BlockEditSet getBlockEditSet() {
    // Compute id of the form: address/dimension
    // Note: Minecraft.theWorld.getWorldInfo().getDimension() doesn't update.
    Minecraft mc = Minecraft.getMinecraft();
    StringBuilder idBuilder = new StringBuilder();
    // This code might get referenced at startup when changing display settings
    // if the mod happens to be disabled in the config file. At that time,
    // getServerIP() will be null. Let's avoid that crash.
    String serverIP = getServerIP();
    if (serverIP != null) {
        idBuilder.append(serverIP);
    }
    idBuilder.append('/');
    idBuilder.append(mc.thePlayer.dimension);
    String id = idBuilder.toString();
    // Lookup BlockEditSet or create new mapping if not found.
    BlockEditSet edits = _edits.get(id);
    if (edits == null) {
        edits = new BlockEditSet();
        _edits.put(id, edits);
    }
    return edits;
}
Also used : Minecraft(net.minecraft.client.Minecraft) BlockEditSet(watson.db.BlockEditSet)

Example 2 with BlockEditSet

use of watson.db.BlockEditSet in project watson by totemo.

the class Controller method saveBlockEditFile.

// getBlockEditSet
// --------------------------------------------------------------------------
/**
   * Save the current {@link BlockEditSet} to the specified file in
   * getSaveDirectory().
   *
   * @param fileName the file name to write; if it is null and there is a
   *          current player variable value, a default file name of the form
   *          player-YYYY-MM-DD-hh.mm.ss is used.
   *
   */
public void saveBlockEditFile(String fileName) {
    // Compute default fileName?
    if (fileName == null) {
        String player = (String) getVariables().get("player");
        if (player == null) {
            Chat.localError("No current player set, so you must specify a file name.");
            return;
        } else {
            Calendar calendar = Calendar.getInstance();
            fileName = String.format(Locale.US, "%s-%4d-%02d-%02d-%02d.%02d.%02d", player, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
        }
    }
    // if
    createBlockEditDirectory();
    File file = new File(getBlockEditDirectory(), fileName);
    try {
        BlockEditSet edits = getBlockEditSet();
        int editCount = edits.save(file);
        int annoCount = edits.getAnnotations().size();
        Chat.localOutput(String.format(Locale.US, "Saved %d edits and %d annotations to %s", editCount, annoCount, fileName));
    } catch (IOException ex) {
        Log.exception(Level.SEVERE, "error saving BlockEditSet to " + file, ex);
        Chat.localError("The file " + fileName + " could not be saved.");
    }
}
Also used : Calendar(java.util.Calendar) IOException(java.io.IOException) File(java.io.File) BlockEditSet(watson.db.BlockEditSet)

Example 3 with BlockEditSet

use of watson.db.BlockEditSet in project watson by totemo.

the class AnnoCommand method processCommand.

// --------------------------------------------------------------------------
/**
   * @see net.minecraft.src.ICommand#processCommand(net.minecraft.src.ICommandSender,
   *      java.lang.String[])
   */
@Override
public void processCommand(ICommandSender sender, String[] args) {
    if (args.length == 0) {
        help(sender);
        return;
    } else if (args.length == 1) {
        if (args[0].equals("help")) {
            help(sender);
            return;
        } else if (args[0].equals("list")) {
            BlockEditSet edits = Controller.instance.getBlockEditSet();
            ArrayList<Annotation> annotations = edits.getAnnotations();
            localOutput(sender, String.format(Locale.US, "%d annotation(s)", annotations.size()));
            int index = 1;
            for (Annotation annotation : annotations) {
                String line = String.format(Locale.US, "(%d) (%d,%d,%d) %s", index, annotation.getX(), annotation.getY(), annotation.getZ(), annotation.getText());
                localOutput(sender, line);
                ++index;
            }
            return;
        } else if (args[0].equals("clear")) {
            BlockEditSet edits = Controller.instance.getBlockEditSet();
            ArrayList<Annotation> annotations = edits.getAnnotations();
            localOutput(sender, String.format(Locale.US, "%d annotation(s) cleared.", annotations.size()));
            annotations.clear();
            return;
        }
    } else if (args.length >= 2) {
        if (args[0].equals("tp")) {
            if (args.length == 2) {
                BlockEditSet edits = Controller.instance.getBlockEditSet();
                ArrayList<Annotation> annotations = edits.getAnnotations();
                int index = Integer.parseInt(args[1]) - 1;
                if (index >= 0 && index < annotations.size()) {
                    Annotation annotation = annotations.get(index);
                    Controller.instance.teleport(annotation.getX(), annotation.getY(), annotation.getZ());
                } else {
                    localError(sender, "Annotation index out of range.");
                }
                return;
            }
        } else if (args[0].equals("remove")) {
            if (args.length == 2) {
                BlockEditSet edits = Controller.instance.getBlockEditSet();
                ArrayList<Annotation> annotations = edits.getAnnotations();
                int index = Integer.parseInt(args[1]) - 1;
                if (index >= 0 && index < annotations.size()) {
                    annotations.remove(index);
                    localOutput(sender, String.format(Locale.US, "Removed annotation #%d", (index + 1)));
                } else {
                    localError(sender, "Annotation index out of range.");
                }
                return;
            }
        } else if (args[0].equals("add")) {
            HashMap<String, Object> vars = Controller.instance.getVariables();
            Integer x = (Integer) vars.get("x");
            Integer y = (Integer) vars.get("y");
            Integer z = (Integer) vars.get("z");
            if (x == null || y == null || z == null) {
                localError(sender, "Use the LogBlock tool to set a position.");
            } else {
                BlockEditSet edits = Controller.instance.getBlockEditSet();
                ArrayList<Annotation> annotations = edits.getAnnotations();
                String text = concatArgs(args, 1, args.length, " ");
                Annotation annotation = new Annotation(x, y, z, text);
                annotations.add(annotation);
                String description = String.format(Locale.US, "(%d) (%d,%d,%d) %s", annotations.size(), annotation.getX(), annotation.getY(), annotation.getZ(), annotation.getText());
                localOutput(sender, description);
            }
            return;
        }
    }
    localError(sender, "Invalid command syntax.");
}
Also used : ArrayList(java.util.ArrayList) BlockEditSet(watson.db.BlockEditSet) Annotation(watson.db.Annotation)

Example 4 with BlockEditSet

use of watson.db.BlockEditSet in project watson by totemo.

the class LiteModWatson method onPostRenderEntities.

// onTick
// --------------------------------------------------------------------------
/**
   * @see com.mumfrey.liteloader.PostRenderListener#onPostRenderEntities(float)
   */
@Override
public void onPostRenderEntities(float partialTicks) {
    if (Configuration.instance.isEnabled() && Controller.instance.getDisplaySettings().isDisplayed()) {
        RenderHelper.disableStandardItemLighting();
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.enableBlend();
        GlStateManager.disableTexture2D();
        GlStateManager.disableLighting();
        GlStateManager.depthMask(false);
        GlStateManager.disableDepth();
        boolean foggy = GL11.glIsEnabled(GL11.GL_FOG);
        GlStateManager.disableFog();
        GlStateManager.pushMatrix();
        GlStateManager.translate(-getPlayerX(partialTicks), -getPlayerY(partialTicks), -getPlayerZ(partialTicks));
        BlockEditSet edits = Controller.instance.getBlockEditSet();
        edits.drawOutlines();
        edits.drawVectors();
        Controller.instance.drawSelection();
        // Test code. X marks the spot.
        // GL11.glLineWidth(3.0f);
        // GL11.glColor4f(1.0f, 0.0f, 0.0f, 0.8f);
        // Tessellator tess = Tessellator.instance;
        // tess.startDrawing(GL11.GL_LINES);
        // tess.addVertex(-5, 27, -5);
        // tess.addVertex(5, 27, 5);
        // tess.addVertex(5, 27, -5);
        // tess.addVertex(-5, 27, 5);
        // tess.draw();
        GlStateManager.popMatrix();
        edits.drawAnnotations();
        edits.getOreDB().drawDepositLabels();
        // Or else, fog is *all* you'll see with Optifine.
        if (foggy) {
            GlStateManager.enableFog();
        }
        GlStateManager.enableDepth();
        GlStateManager.depthMask(true);
        GlStateManager.enableLighting();
        GlStateManager.enableTexture2D();
        GlStateManager.disableBlend();
        RenderHelper.enableStandardItemLighting();
    }
}
Also used : BlockEditSet(watson.db.BlockEditSet)

Example 5 with BlockEditSet

use of watson.db.BlockEditSet in project watson by totemo.

the class Controller method loadBlockEditFile.

// saveBlockEditFile
// --------------------------------------------------------------------------
/**
   * Load the set of {@link BlockEdit}s from the specified file.
   *
   * @param fileName the file name, or the start of the file name (beginning of
   *          player name), in the BlockEdit saves directory.
   *
   * @TODO: Does this need to be smarter about which dimension/server we're in?
   */
public void loadBlockEditFile(String fileName) {
    File file = new File(getBlockEditDirectory(), fileName);
    if (!file.canRead()) {
        // Try to find a file that begins with fileName, i.e. treat that as the
        // player name.
        File[] files = getBlockEditFileList(fileName);
        if (files.length > 0) {
            // Chose the most recent matching file.
            file = files[files.length - 1];
        }
    }
    if (file.canRead()) {
        try {
            BlockEditSet edits = getBlockEditSet();
            int editCount = edits.load(file);
            int annoCount = edits.getAnnotations().size();
            Chat.localOutput(String.format(Locale.US, "Loaded %d edits and %d annotations from %s", editCount, annoCount, file.getName()));
        } catch (Exception ex) {
            Log.exception(Level.SEVERE, "error loading BlockEditSet from " + file, ex);
            Chat.localError("The file " + fileName + " could not be loaded.");
        }
    } else {
        Chat.localError("Can't open " + fileName + " to read.");
    }
}
Also used : File(java.io.File) BlockEditSet(watson.db.BlockEditSet) IOException(java.io.IOException)

Aggregations

BlockEditSet (watson.db.BlockEditSet)5 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Minecraft (net.minecraft.client.Minecraft)1 Annotation (watson.db.Annotation)1