@Override
 protected void drawSlot(int id, int x, int y, int var4, int var5, int var6) {
   Block block = blocks.get(id);
   ItemStack itemStack = new ItemStack(Item.getItemFromBlock(block));
   GlStateManager.enableRescaleNormal();
   GlStateManager.enableBlend();
   RenderHelper.enableGUIStandardItemLighting();
   GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
   if (itemStack.getItem() != null)
     try {
       Minecraft.getMinecraft()
           .getRenderItem()
           .renderItemAndEffectIntoGUI(itemStack, x + 4, y + 4);
     } catch (Exception e) {
       e.printStackTrace();
     }
   else mc.fontRendererObj.drawString("?", x + 10, y + 9, 10526880);
   Minecraft.getMinecraft()
       .getRenderItem()
       .func_175030_a(Minecraft.getMinecraft().fontRendererObj, itemStack, x + 4, y + 4);
   RenderHelper.disableStandardItemLighting();
   GlStateManager.disableRescaleNormal();
   GlStateManager.disableBlend();
   glDisable(GL_LIGHTING);
   mc.fontRendererObj.drawString(
       "Name: "
           + (itemStack.getItem() == null ? block.getLocalizedName() : itemStack.getDisplayName()),
       x + 31,
       y + 3,
       10526880);
   int blockID = Block.getIdFromBlock(block);
   mc.fontRendererObj.drawString("ID: " + blockID, x + 31, y + 15, 10526880);
 }
  @Override
  public void addHackable(Block block, Class<? extends IHackableBlock> iHackable) {
    if (block == null) throw new NullPointerException("Block is null!");
    if (iHackable == null) throw new NullPointerException("IHackableBlock is null!");

    if (Block.class.isAssignableFrom(iHackable)) {
      Log.warning(
          "Blocks that implement IHackableBlock shouldn't be registered as hackable! Registering block: "
              + block.getLocalizedName());
    } else {
      try {
        IHackableBlock hackableBlock = iHackable.newInstance();
        if (hackableBlock.getId() != null)
          stringToBlockHackables.put(hackableBlock.getId(), iHackable);
        hackableBlocks.put(block, iHackable);
      } catch (InstantiationException e) {
        Log.error(
            "Not able to register hackable block: "
                + iHackable.getName()
                + ". Does the class have a parameterless constructor?");
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        Log.error(
            "Not able to register hackable block: "
                + iHackable.getName()
                + ". Is the class a public class?");
        e.printStackTrace();
      }
    }
  }
Exemple #3
0
  public BlockLoader() {
    registerBlock(drinks_store);
    registerBlock(drinks_brewer);
    registerBlock(rain_collector);

    GameRegistry.registerTileEntity(TileEntityDS.class, drinks_store.getLocalizedName());
    GameRegistry.registerTileEntity(TileEntityDB.class, drinks_brewer.getUnlocalizedName());
    GameRegistry.registerTileEntity(TileEntityRC.class, rain_collector.getUnlocalizedName());

    GameRegistry.addRecipe(
        new ItemStack(drinks_store),
        new Object[] {
          "***", "*#*", "*^*", '*', Items.quartz, '#', Blocks.glass_pane, '^', Blocks.piston
        });

    GameRegistry.addRecipe(
        new ItemStack(drinks_brewer, 1),
        new Object[] {
          "***", "*#*", "***", '*', Blocks.cobblestone, '#', Items.glass_bottle,
        });

    GameRegistry.addRecipe(
        new ItemStack(rain_collector, 1),
        new Object[] {
          "***", "*#*", "***", '*', Blocks.cobblestone, '#', Items.bucket,
        });
  }
  /**
   * Generates Ore in a specific pattern
   *
   * @param only if true only the listed bioms else not the listed Bioms
   */
  public void generateIt(
      Random random,
      int chunkX,
      int chunkZ,
      World world,
      IChunkProvider chunkGenerator,
      IChunkProvider chunkProvider,
      Block ID,
      Block target,
      String[] bioms,
      boolean only,
      int tries) {

    boolean nosucsess;
    int trieCount = 0;
    BiomeGenBase b = world.getBiomeGenForCoords(chunkX, chunkZ);
    int yRandom;
    int zRandom;
    int xRandom;

    if (isBiom(bioms, b.biomeName) == only) {
      do {
        zRandom = random.nextInt(16);
        xRandom = random.nextInt(16);

        int S1 = world.getTopSolidOrLiquidBlock(xRandom + chunkX * 16, zRandom + chunkZ * 16);

        if (S1 > 19) {
          yRandom = random.nextInt(S1 - 19);
        } else {
          yRandom = 2;
        }

        int x = chunkX * 16 + xRandom;
        int y = yRandom;
        int z = chunkZ * 16 + zRandom;

        if (world.getBlock(x, y, z).isReplaceableOreGen(world, x, y, z, target)
            && world.getBlock(x, y - 1, z).isReplaceableOreGen(world, x, y - 1, z, target)
            && world.getBlock(x + 1, y, z).isReplaceableOreGen(world, x, y, z, target)
            && world.getBlock(x + 1, y - 1, z).isReplaceableOreGen(world, x, y, z, target)) {

          world.setBlock(x, y, z, ID);
          world.setBlock(x, y - 1, z, ID);
          world.setBlock(x + 1, y, z, ID);
          world.setBlock(x + 1, y - 1, z, ID);
          nosucsess = false;
          LogHelper.debug(
              "Generated " + ID.getLocalizedName() + " at " + " X: " + x + " Y: " + y + " Z: " + z);
        } else {
          nosucsess = true;
          trieCount++;
          LogHelper.debug("Had no sucess,try :" + trieCount + "/" + tries);
        }

      } while (nosucsess && trieCount < tries);
    }
  }
  @SubscribeEvent
  public void onBlockClick(PlayerInteractEvent e) {
    if (!e.world.isRemote) {
      if (e.action == Action.RIGHT_CLICK_BLOCK
          && CmdDumpBlockData.getWaitForBlockClick(e.entityPlayer.getUniqueID())) {
        StringBuilder sb = new StringBuilder();
        Block blc = e.world.getBlock(e.x, e.y, e.z);
        if (blc == null) {
          return;
        }

        int meta = e.world.getBlockMetadata(e.x, e.y, e.z);

        sb.append(
            "BlockID: "
                + GameData.getBlockRegistry().getNameForObject(blc)
                + "("
                + GameData.getBlockRegistry().getIDForObject(blc)
                + ")\n");
        sb.append(
            "Block name: " + blc.getUnlocalizedName() + " = " + blc.getLocalizedName() + "\n");
        sb.append("XYZ: " + e.x + " " + e.y + " " + e.z + "\n");
        sb.append("Metadata: " + meta + "\n");
        sb.append(
            "Lightlevel: "
                + "block: "
                + e.world.getSavedLightValue(EnumSkyBlock.Block, e.x, e.y, e.z)
                + ", sky: "
                + e.world.getSavedLightValue(EnumSkyBlock.Sky, e.x, e.y, e.z)
                + "\n");
        if (blc.hasTileEntity(meta)) {
          TileEntity te = e.world.getTileEntity(e.x, e.y, e.z);
          if (te != null) {
            NBTTagCompound nbt = new NBTTagCompound();
            te.writeToNBT(nbt);
            sb.append("NBT: {" + CmdDumpItemData.getNBTString(nbt, 1) + "}");
          }
        }

        System.out.println("\n" + sb.toString());

        e.setCanceled(true);
      }
    }
  }
 @Override
 public String getDisplayName() {
   return block.getLocalizedName();
 }