/** * Draws lines for the edges of the bounding box. */ public static void drawOutlinedBoundingBox(CustomHitBox hitbox) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); buffer.begin(1, DefaultVertexFormats.POSITION); // Top and Bottom faces addMainVertex(hitbox, 1, hitbox.middleHeight, buffer); addMainVertex(hitbox, 0, 0, buffer); // Top and Bottom extensions addTopBottomVertex(hitbox, 1, hitbox.sideLength[1], hitbox.middleHeight + hitbox.sideLength[1], buffer); addTopBottomVertex(hitbox, 0, -hitbox.sideLength[0], -hitbox.sideLength[0], buffer); // Vertical Lines addVerticalVertexs(hitbox, buffer); tessellator.draw(); }
private boolean doDuctHighlight(RayTraceResult target, EntityPlayer player, float partialTicks) { if (target.typeOfHit != Type.BLOCK) { return false; } RayTracer.retraceBlock(player.world, player, target.getBlockPos()); TileEntity tile = player.world.getTileEntity(target.getBlockPos()); if (tile instanceof ICustomHitBox) { ICustomHitBox hitbox = (ICustomHitBox) tile; if (hitbox.shouldRenderCustomHitBox(target.subHit, player)) { RenderHitbox.drawSelectionBox(player, target, partialTicks, hitbox.getCustomHitBox(target.subHit, player)); return true; } } return false; }
@Override public CustomHitBox getCustomHitBox(int subHit, EntityPlayer thePlayer) { double v1 = getDuctType().isLargeTube() ? 0.075 : .3; double v = (1 - v1 * 2); CustomHitBox hb = new CustomHitBox(v, v, v, pos.getX() + v1, pos.getY() + v1, pos.getZ() + v1); for (int i = 0; i < 6; i++) { BlockDuct.ConnectionType renderConnectionType = getVisualConnectionType(i); if (renderConnectionType == BlockDuct.ConnectionType.DUCT) { hb.drawSide(i, true); hb.setSideLength(i, v1); } else if (renderConnectionType != BlockDuct.ConnectionType.NONE) { hb.drawSide(i, true); hb.setSideLength(i, .04); } } return hb; }
/** * Draws the selection box for the player. Args: entityPlayer, rayTraceHit, i, itemStack, partialTickTime */ public static void drawSelectionBox(EntityPlayer player, RayTraceResult rayTraceResult, float pTickTime, CustomHitBox customHitBox) { if (rayTraceResult.typeOfHit == Type.BLOCK) { GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F); GlStateManager.glLineWidth(2.0F); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); IBlockState state = player.world.getBlockState(rayTraceResult.getBlockPos()); if (state.getMaterial() != Material.AIR) { //block.setBlockBoundsBasedOnState(thePlayer.worldObj, rayTraceResult.blockX, rayTraceResult.blockY, rayTraceResult.blockZ); double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * pTickTime; double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * pTickTime; double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * pTickTime; drawOutlinedBoundingBox(customHitBox.addExtraSpace(extraSpace).offsetForDraw(-d0, -d1, -d2)); } GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); } }
private boolean doAttachmentHighlight(RayTraceResult target, EntityPlayer player, float partialTicks) { if (!(ItemHelper.getHeldStack(player).getItem() instanceof ItemAttachment) || target.typeOfHit != Type.BLOCK) { return false; } RayTracer.retraceBlock(player.world, player, target.getBlockPos()); ItemStack stack = ItemHelper.getHeldStack(player); Attachment attachment = ItemAttachment.getAttachment(stack, player, player.world, target.getBlockPos(), target.sideHit); if (attachment == null || !attachment.canAddToTile(attachment.baseTile)) { return false; } Cuboid6 c = attachment.getCuboid(); c.max.subtract(c.min); RenderHitbox.drawSelectionBox(player, target, partialTicks, new CustomHitBox(c.max.y, c.max.z, c.max.x, attachment.baseTile.x() + c.min.x, attachment.baseTile.y() + c.min.y, attachment.baseTile.z() + c.min.z)); attachment.drawSelectionExtra(player, target, partialTicks); return true; }