コード例 #1
0
public class RendererSchematicChunkSorter implements Comparator {
  private final Settings settings = Settings.instance();

  public int doCompare(
      RendererSchematicChunk par1RendererSchematicChunk,
      RendererSchematicChunk par2RendererSchematicChunk) {
    if (par1RendererSchematicChunk.isInFrustrum && !par2RendererSchematicChunk.isInFrustrum) {
      return -1;
    } else if (!par1RendererSchematicChunk.isInFrustrum
        && par2RendererSchematicChunk.isInFrustrum) {
      return 1;
    } else {
      Vector3f position = new Vector3f();
      Vector3f.sub(this.settings.playerPosition, this.settings.offset, position);
      double dist1 = par1RendererSchematicChunk.distanceToPoint(position);
      double dist2 = par2RendererSchematicChunk.distanceToPoint(position);
      return dist1 > dist2 ? 1 : (dist1 < dist2 ? -1 : 0);
    }
  }

  @Override
  public int compare(Object par1Obj, Object par2Obj) {
    return doCompare((RendererSchematicChunk) par1Obj, (RendererSchematicChunk) par2Obj);
  }
}
コード例 #2
0
class GuiSchematicMaterialsSlot extends GuiSlot {
  private final Settings settings = Settings.instance();
  private final FontRenderer fontRenderer = this.settings.minecraft.fontRenderer;
  private final TextureManager renderEngine = this.settings.minecraft.renderEngine;

  private final GuiSchematicMaterials guiSchematicMaterials;

  protected int selectedIndex = -1;

  public GuiSchematicMaterialsSlot(GuiSchematicMaterials par1) {
    super(Settings.instance().minecraft, par1.width, par1.height, 16, par1.height - 34, 24);
    this.guiSchematicMaterials = par1;
    this.selectedIndex = -1;
  }

  @Override
  protected int getSize() {
    return this.guiSchematicMaterials.blockList.size();
  }

  @Override
  protected void elementClicked(int index, boolean par2) {
    this.selectedIndex = index;
  }

  @Override
  protected boolean isSelected(int index) {
    return index == this.selectedIndex;
  }

  @Override
  protected void drawBackground() {}

  @Override
  protected void drawContainerBackground(Tessellator tessellator) {}

  @Override
  protected void drawSlot(int index, int x, int y, int par4, Tessellator tessellator) {
    ItemStack itemStack = this.guiSchematicMaterials.blockList.get(index);

    String itemName;
    String amount = Integer.toString(itemStack.stackSize);

    if (Item.itemsList[itemStack.itemID] != null) {
      itemName = Item.itemsList[itemStack.itemID].getItemStackDisplayName(itemStack);
    } else {
      itemName =
          String.format(Locale.ENGLISH, "#%04d:%02d", itemStack.itemID, itemStack.getItemDamage());
    }

    drawItemStack(x, y, itemStack);

    this.guiSchematicMaterials.drawString(this.fontRenderer, itemName, x + 24, y + 6, 16777215);
    this.guiSchematicMaterials.drawString(
        this.fontRenderer,
        amount,
        x + 215 - this.fontRenderer.getStringWidth(amount),
        y + 6,
        16777215);
  }

  private void drawItemStack(int x, int y, ItemStack itemStack) {
    drawItemStackSlot(x, y);

    if (itemStack != null && Item.itemsList[itemStack.itemID] != null) {
      GL11.glEnable(GL12.GL_RESCALE_NORMAL);
      RenderHelper.enableGUIStandardItemLighting();
      Settings.renderItem.renderItemIntoGUI(
          this.fontRenderer, this.renderEngine, itemStack, x + 2, y + 2);
      RenderHelper.disableStandardItemLighting();
      GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    }
  }

  private void drawItemStackSlot(int x, int y) {
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.renderEngine.bindTexture(Gui.statIcons);
    Tessellator var10 = Tessellator.instance;
    var10.startDrawingQuads();
    var10.addVertexWithUV(x + 1 + 0, y + 1 + 18, 0, 0 * 0.0078125F, 18 * 0.0078125F);
    var10.addVertexWithUV(x + 1 + 18, y + 1 + 18, 0, 18 * 0.0078125F, 18 * 0.0078125F);
    var10.addVertexWithUV(x + 1 + 18, y + 1 + 0, 0, 18 * 0.0078125F, 0 * 0.0078125F);
    var10.addVertexWithUV(x + 1 + 0, y + 1 + 0, 0, 0 * 0.0078125F, 0 * 0.0078125F);
    var10.draw();
  }
}
コード例 #3
0
 public GuiSchematicMaterialsSlot(GuiSchematicMaterials par1) {
   super(Settings.instance().minecraft, par1.width, par1.height, 16, par1.height - 34, 24);
   this.guiSchematicMaterials = par1;
   this.selectedIndex = -1;
 }
コード例 #4
0
public class GuiSchematicLoad extends GuiScreen {
  private static final FileFilterSchematic FILE_FILTER_FOLDER = new FileFilterSchematic(true);
  private static final FileFilterSchematic FILE_FILTER_SCHEMATIC = new FileFilterSchematic(false);

  private final Settings settings = Settings.instance();
  private final GuiScreen prevGuiScreen;
  private GuiSchematicLoadSlot guiSchematicLoadSlot;

  private GuiSmallButton btnOpenDir = null;
  private GuiSmallButton btnDone = null;

  private final String strTitle = StatCollector.translateToLocal("schematica.gui.title");
  private final String strFolderInfo = StatCollector.translateToLocal("schematica.gui.folderInfo");

  protected File currentDirectory = this.settings.schematicDirectory;
  protected final List<GuiSchematicEntry> schematicFiles = new ArrayList<GuiSchematicEntry>();

  public GuiSchematicLoad(GuiScreen guiScreen) {
    this.prevGuiScreen = guiScreen;
  }

  @Override
  public void initGui() {
    int id = 0;

    this.btnOpenDir =
        new GuiSmallButton(
            id++,
            this.width / 2 - 154,
            this.height - 36,
            StatCollector.translateToLocal("schematica.gui.openFolder"));
    this.buttonList.add(this.btnOpenDir);

    this.btnDone =
        new GuiSmallButton(
            id++,
            this.width / 2 + 4,
            this.height - 36,
            StatCollector.translateToLocal("schematica.gui.done"));
    this.buttonList.add(this.btnDone);

    this.guiSchematicLoadSlot = new GuiSchematicLoadSlot(this);

    reloadSchematics();
  }

  @Override
  protected void actionPerformed(GuiButton guiButton) {
    if (guiButton.enabled) {
      if (guiButton.id == this.btnOpenDir.id) {
        boolean success = false;

        try {
          Class c = Class.forName("java.awt.Desktop");
          Object m = c.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]);
          c.getMethod("browse", new Class[] {URI.class})
              .invoke(m, new Object[] {Settings.schematicDirectory.toURI()});
        } catch (Throwable e) {
          success = true;
        }

        if (success) {
          Settings.logger.logInfo("Opening via Sys class!");
          Sys.openURL("file://" + Settings.schematicDirectory.getAbsolutePath());
        }
      } else if (guiButton.id == this.btnDone.id) {
        loadSchematic();
        this.mc.displayGuiScreen(this.prevGuiScreen);
      } else {
        this.guiSchematicLoadSlot.actionPerformed(guiButton);
      }
    }
  }

  @Override
  public void drawScreen(int x, int y, float partialTicks) {
    this.guiSchematicLoadSlot.drawScreen(x, y, partialTicks);

    drawCenteredString(this.fontRenderer, this.strTitle, this.width / 2, 4, 0x00FFFFFF);
    drawCenteredString(
        this.fontRenderer, this.strFolderInfo, this.width / 2 - 78, this.height - 12, 0x00808080);

    super.drawScreen(x, y, partialTicks);
  }

  @Override
  public void onGuiClosed() {
    // loadSchematic();
  }

  protected void changeDirectory(String directory) {
    this.currentDirectory = new File(this.currentDirectory, directory);

    reloadSchematics();
  }

  protected void reloadSchematics() {
    String name = null;
    int itemID = -1;

    this.schematicFiles.clear();

    try {
      if (!this.currentDirectory
          .getCanonicalPath()
          .equals(Settings.schematicDirectory.getCanonicalPath())) {
        this.schematicFiles.add(new GuiSchematicEntry("..", 327, 0, true));
      }
    } catch (IOException e) {
      Settings.logger.logSevereException("Failed to add GuiSchematicEntry!", e);
    }

    for (File file : this.currentDirectory.listFiles(FILE_FILTER_FOLDER)) {
      name = file.getName();

      itemID = file.listFiles().length == 0 ? 325 : 326;

      this.schematicFiles.add(new GuiSchematicEntry(name, itemID, 0, file.isDirectory()));
    }

    File[] files = this.currentDirectory.listFiles(FILE_FILTER_SCHEMATIC);
    if (files.length == 0) {
      this.schematicFiles.add(
          new GuiSchematicEntry(
              StatCollector.translateToLocal("schematica.gui.noschematic"), 3, 0, false));
    } else {
      for (File file : files) {
        name = file.getName();

        this.schematicFiles.add(
            new GuiSchematicEntry(
                name, readSchematicIcon(file.getAbsolutePath()), file.isDirectory()));
      }
    }
  }

  private ItemStack readSchematicIcon(String filename) {
    try {
      InputStream stream = new FileInputStream(filename);
      NBTTagCompound tagCompound = CompressedStreamTools.readCompressed(stream);

      if (tagCompound != null) {
        if (tagCompound.hasKey("Icon")) {
          ItemStack itemStack = Settings.defaultIcon.copy();
          itemStack.readFromNBT(tagCompound.getCompoundTag("Icon"));
          return itemStack;
        }
      }
    } catch (Exception e) {
      Settings.logger.logSevereException("Failed to read schematic icon!", e);
    }

    return Settings.defaultIcon.copy();
  }

  private void loadSchematic() {
    int selectedIndex = this.guiSchematicLoadSlot.selectedIndex;

    try {
      if (selectedIndex >= 0 && selectedIndex < this.schematicFiles.size()) {
        GuiSchematicEntry schematic = this.schematicFiles.get(selectedIndex);
        this.settings.loadSchematic(
            (new File(this.currentDirectory, schematic.getName())).getCanonicalPath());
      }
    } catch (Exception e) {
      Settings.logger.logSevereException("Failed to load schematic!", e);
    }
    this.settings.moveHere();
  }
}