Пример #1
0
  @Override
  public void invalidate() {
    super.invalidate();
    try {
      renderer.deleteAllDisplayLists();
    } catch (NullPointerException ex) {

    }
    PortalgunMod.portalList.remove(this);
  }
  @SubscribeEvent
  @SideOnly(Side.CLIENT)
  public void renderCeramicsSelection(DrawBlockHighlightEvent event) {
    if (event.target.subHit == -1) {
      return;
    }
    Coord c = Coord.fromMop(event.player.worldObj, event.target);
    TileEntityGreenware clay = c.getTE(TileEntityGreenware.class);
    if (clay == null) {
      return;
    }
    if (event.target.subHit < 0 || event.target.subHit >= clay.parts.size()) {
      return;
    }
    event.setCanceled(true);
    EntityPlayer player = event.player;
    double partial = event.partialTicks;
    ClayLump lump = clay.parts.get(event.target.subHit);
    Block block = new Block(Material.rock);
    lump.toRotatedBlockBounds(clay, block);
    double widen = 0.002;
    double oX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partial;
    double oY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partial;
    double oZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partial;
    AxisAlignedBB bb =
        block
            .getSelectedBoundingBox(c.w, c.toBlockPos())
            .expand(widen, widen, widen)
            .offset(-oX, -oY, -oZ);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(false);
    float r = 0xFF;
    GL11.glLineWidth(2.0F);
    GL11.glColor4f(0, 0, 0, 0.4F);
    // GL11.glColor4f(0x4D/r, 0x34/r, 0x7C/r, 0.8F); //#4D347C
    RenderGlobal.drawSelectionBoundingBox(bb);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);

    // TODO: If the rotation tool is selected, may draw the axis?
    // Oooooh, we could also draw the offset position for *EVERY* tool...
  }
Пример #3
0
  public static void renderEntityBounds(Entity entity, float partialTick) {
    Minecraft mc = Minecraft.getMinecraft();

    if (!mc.gameSettings.hideGUI) {
      // Render bounding box around entity if it is being looked at.
      MovingObjectPosition lookingAt = mc.objectMouseOver;

      if (lookingAt != null
          && lookingAt.typeOfHit == MovingObjectType.ENTITY
          && lookingAt.entityHit == entity) {
        GL11.glPushAttrib(GL11.GL_CURRENT_BIT);

        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        GlStateManager.color(0, 0, 0, 0.4F);
        GL11.glLineWidth(2);
        GlStateManager.disableTexture2D();
        GlStateManager.depthMask(false);
        float expand = entity.getCollisionBorderSize() + 0.002F;

        double offX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTick;
        double offY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTick;
        double offZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTick;
        RenderGlobal.drawOutlinedBoundingBox(
            entity
                .getEntityBoundingBox()
                .expand(expand, expand, expand)
                .offset(-offX, -offY, -offZ),
            -1);

        GlStateManager.depthMask(true);
        GlStateManager.enableTexture2D();
        GlStateManager.disableBlend();

        GL11.glPopAttrib();
      }
    }
  }
  //	public static ArrayListMultimap<ChunkCoordinates, AxisAlignedBB> additionalBlockBounds =
  // ArrayListMultimap.create();
  //	public static void addAdditionalBlockBounds(ChunkCoordinates cc, AxisAlignedBB aabb)
  //	{
  //		for(AxisAlignedBB aabb1 : additionalBlockBounds.get(cc))
  //			if(aabb1.toString().equals(aabb.toString()))
  //				return;
  //		additionalBlockBounds.put(cc, aabb);
  //	}
  @SubscribeEvent()
  public void renderAdditionalBlockBounds(DrawBlockHighlightEvent event) {
    if (event.subID == 0 && event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
      float f1 = 0.002F;
      double d0 =
          event.player.lastTickPosX
              + (event.player.posX - event.player.lastTickPosX) * (double) event.partialTicks;
      double d1 =
          event.player.lastTickPosY
              + (event.player.posY - event.player.lastTickPosY) * (double) event.partialTicks;
      double d2 =
          event.player.lastTickPosZ
              + (event.player.posZ - event.player.lastTickPosZ) * (double) event.partialTicks;
      //			if(additionalBlockBounds.containsKey(new
      // ChunkCoordinates(event.target.blockX,event.target.blockY,event.target.blockZ)))
      if (event.player.worldObj.getBlock(
              event.target.blockX, event.target.blockY, event.target.blockZ)
          instanceof IEBlockInterfaces.ICustomBoundingboxes) {
        ChunkCoordinates cc =
            new ChunkCoordinates(event.target.blockX, event.target.blockY, event.target.blockZ);
        IEBlockInterfaces.ICustomBoundingboxes block =
            (IEBlockInterfaces.ICustomBoundingboxes)
                event.player.worldObj.getBlock(
                    event.target.blockX, event.target.blockY, event.target.blockZ);
        Set<AxisAlignedBB> set =
            block.addCustomSelectionBoxesToList(
                event.player.worldObj, cc.posX, cc.posY, cc.posZ, event.player);
        if (!set.isEmpty()) {
          //
          //	if(!(event.player.worldObj.getTileEntity(event.target.blockX,event.target.blockY,event.target.blockZ) instanceof IEBlockInterfaces.ICustomBoundingboxes))
          //				{
          //					additionalBlockBounds.removeAll(cc);
          //					return;
          //				}
          GL11.glEnable(GL11.GL_BLEND);
          OpenGlHelper.glBlendFunc(770, 771, 1, 0);
          GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
          GL11.glLineWidth(2.0F);
          GL11.glDisable(GL11.GL_TEXTURE_2D);
          GL11.glDepthMask(false);
          for (AxisAlignedBB aabb : set)
            //				for(AxisAlignedBB aabb : additionalBlockBounds.get(cc))
            if (aabb != null)
              RenderGlobal.drawOutlinedBoundingBox(
                  aabb.getOffsetBoundingBox(cc.posX, cc.posY, cc.posZ)
                      .expand((double) f1, (double) f1, (double) f1)
                      .getOffsetBoundingBox(-d0, -d1, -d2),
                  -1);

          GL11.glDepthMask(true);
          GL11.glEnable(GL11.GL_TEXTURE_2D);
          GL11.glDisable(GL11.GL_BLEND);
          event.setCanceled(true);
        }
      }

      ItemStack stack = event.player.getCurrentEquippedItem();
      World world = event.player.worldObj;
      if (stack != null
          && stack.getItem() instanceof ItemDrill
          && ((ItemDrill) stack.getItem())
              .isEffective(
                  world
                      .getBlock(event.target.blockX, event.target.blockY, event.target.blockZ)
                      .getMaterial())) {
        ItemStack head = ((ItemDrill) stack.getItem()).getHead(stack);
        if (head != null) {
          int side = event.target.sideHit;
          int diameter =
              ((IDrillHead) head.getItem()).getMiningSize(head)
                  + ((ItemDrill) stack.getItem()).getUpgrades(stack).getInteger("size");
          int depth =
              ((IDrillHead) head.getItem()).getMiningDepth(head)
                  + ((ItemDrill) stack.getItem()).getUpgrades(stack).getInteger("depth");

          int startX = event.target.blockX;
          int startY = event.target.blockY;
          int startZ = event.target.blockZ;
          if (diameter % 2 == 0) // even numbers
          {
            float hx = (float) event.target.hitVec.xCoord - event.target.blockX;
            float hy = (float) event.target.hitVec.yCoord - event.target.blockY;
            float hz = (float) event.target.hitVec.zCoord - event.target.blockZ;
            if ((side < 2 && hx < .5) || (side < 4 && hx < .5)) startX -= diameter / 2;
            if (side > 1 && hy < .5) startY -= diameter / 2;
            if ((side < 2 && hz < .5) || (side > 3 && hz < .5)) startZ -= diameter / 2;
          } else // odd numbers
          {
            startX -= (side == 4 || side == 5 ? 0 : diameter / 2);
            startY -= (side == 0 || side == 1 ? 0 : diameter / 2);
            startZ -= (side == 2 || side == 3 ? 0 : diameter / 2);
          }

          GL11.glColor4f(0.1F, 0.1F, 0.1F, 0.4F);
          GL11.glLineWidth(1F);
          GL11.glDisable(GL11.GL_TEXTURE_2D);

          //					AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(startX,startY,startZ,
          // startX+(side==4||side==5?1:diameter),startY+(side==0||side==1?1:diameter),startZ+(side==2||side==3?1: diameter));
          //					RenderGlobal.drawOutlinedBoundingBox(aabb.expand((double)f1, (double)f1,
          // (double)f1).getOffsetBoundingBox(-d0, -d1, -d2), -1);
          for (int dd = 0; dd < depth; dd++)
            for (int dw = 0; dw < diameter; dw++)
              for (int dh = 0; dh < diameter; dh++) {
                int x = startX + (side == 4 || side == 5 ? dd : dw);
                int y = startY + (side == 0 || side == 1 ? dd : dh);
                int z = startZ + (side == 0 || side == 1 ? dh : side == 4 || side == 5 ? dw : dd);
                Block block = event.player.worldObj.getBlock(x, y, z);
                if (block != null
                    && !block.isAir(world, x, y, z)
                    && block.getPlayerRelativeBlockHardness(event.player, world, x, y, z) != 0) {
                  if (!((ItemDrill) stack.getItem())
                      .canBreakExtraBlock(
                          world,
                          block,
                          x,
                          y,
                          z,
                          world.getBlockMetadata(x, y, z),
                          event.player,
                          stack,
                          head,
                          false)) continue;
                  AxisAlignedBB aabb =
                      block.getSelectedBoundingBoxFromPool(event.player.worldObj, x, y, z);
                  if (aabb != null) {
                    RenderGlobal.drawOutlinedBoundingBox(
                        aabb.expand((double) f1, (double) f1, (double) f1)
                            .getOffsetBoundingBox(-d0, -d1, -d2),
                        -1);
                  }
                }
              }
          GL11.glDepthMask(true);
          GL11.glEnable(GL11.GL_TEXTURE_2D);
          GL11.glDisable(GL11.GL_BLEND);
        }
      }
    }
  }