Jump to content

Recommended Posts

Posted

When i try to render custom bounding box of my block, it just doesn't render. What do i do incorrectly ? Here is my code

 

Block:

public class ChairBlock extends BlockContainer{


int renderType ;
private EntityPlayer player;
private int x,y,z;

public ChairBlock(int par1, Material par2Material ) {
	super(par1, par2Material);
}

@Override
public boolean renderAsNormalBlock() {
	return false;
}



public void registerIcons(IconRegister par1IconRegister)
    {
        this.blockIcon = par1IconRegister.registerIcon("rs:Peripheral");
    }

public boolean hasTileEntity(){
	return true;

}

public boolean isOpaqueCube(){
	return false;

}


@Override
public boolean isBlockSolid(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
	return true;
}
@Override
public int getRenderType() {
	return renderType;
}

public void setRenderType(int id){
	this.renderType = id;
}

@Override
public TileEntity createNewTileEntity(World world){
	if(this.player != null){
		RussyPeripheral tile = new RussyPeripheral();
		tile.setUsername(player.username);
		MyTickHandler.loadedRussyTiles.add(tile);
	    return tile;
	}else{
		RussyPeripheral tile = new RussyPeripheral();
		tile.setUsername("NONE");
		MyTickHandler.loadedRussyTiles.add(tile);
		return tile;
	}
}



public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack){

    int rotation = MathHelper.floor_double((double)((par5EntityLiving.rotationYaw * 4F) / 360F) + 2.5D) & 3;
    par1World.setBlock(par2, par3, par4, this.blockID, rotation, 2);
    this.player = (EntityPlayer) par5EntityLiving;
    
}


public boolean onBlockBroken(World world, int par2, int par3, int par4, EntityPlayer player, int par6, float par7, float par8, float par9)
    {
	return blockConstructorCalled;
    }

public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
    {
	this.setBlockBounds(0, 0, 0, 1, 1, 1);
	super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    }

 

Event Class:

public class Events {
public static float xMin,yMin,zMin,xMax,yMax,zMax = 0;
private static boolean inited = false;

//@SideOnly(Side.CLIENT)
@ForgeSubscribe
public void onDrawBlockHighlight(DrawBlockHighlightEvent e){
	if(e.target.typeOfHit.equals(EnumMovingObjectType.TILE) && e.player.worldObj.getBlockTileEntity(e.target.blockX, e.target.blockY, e.target.blockZ) instanceof RussyPeripheral){
		e.setCanceled(true);
		Vec3 hitV = e.target.hitVec;
		Float[] parts = EnderPeripheralModel.rightValve;
		Block block = e.player.worldObj.getBlockTileEntity(e.target.blockX, e.target.blockY, e.target.blockZ).blockType;
		TileEntity tile =  e.player.worldObj.getBlockTileEntity(e.target.blockX, e.target.blockY, e.target.blockZ);
		if(!inited){
		   /*xMin = tile.xCoord+0.54000175F;
		   yMin = tile.yCoord+0.5040015F;
		   zMin = tile.zCoord+0.4710013F;
		   
		   xMax = tile.xCoord+0.64000175F;
		   yMax = tile.yCoord+0.6040015F;
		   zMax = tile.zCoord+0.5710013F;*/

		   xMin = tile.xCoord;
		   yMin = tile.yCoord;
		   zMin = tile.zCoord;
		   xMax = tile.xCoord+1F;
		   yMax = tile.yCoord+1F;
		   zMax = tile.zCoord+1F;
		   
		   
		   inited = true;
		}
		//this.drawOutlinedBoundingBox(xMin, yMin, zMin, xMax, yMax, zMax);
		this.drawOutlinedBoundingBox((float)tile.xCoord+(float)block.getBlockBoundsMinX(),(float)tile.yCoord+(float) block.getBlockBoundsMinY(),(float)tile.zCoord+(float) block.getBlockBoundsMinZ(),(float)tile.xCoord+(float) block.getBlockBoundsMaxX(),(float)tile.yCoord+(float) block.getBlockBoundsMaxY(),(float)tile.zCoord+(float) block.getBlockBoundsMaxZ());


		//EnderPeripheralModel.drawOutlinedBoundingBox(rValve);
		//EnderPeripheralModel.drawOutlinedBoundingBox(main);

		//this.setBlockBounds(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5]);
		//super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
		//float backX = 0.07500001043081284F;
		//this.setBlockBounds(0.1550000160932541F, 0.011000001803040504F, 0.10499998927116394F, 0.9349998831748962F, 0.8749999403953552F, 0.8849999904632568F);
	    //e.context.drawSelectionBox(par1EntityPlayer, par2MovingObjectPosition, par3, par4);
	}

}

public static void drawOutlinedBoundingBox(float minX,float minY, float minZ, float maxX, float maxY, float maxZ)
  {
	  GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
      GL11.glColor4f(1F, 0.0F, 0.0F, 0.5F);
      GL11.glLineWidth(2.0F);
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      GL11.glDepthMask(false);
      Tessellator tessellator = Tessellator.instance;
      tessellator.startDrawing(3);
      tessellator.addVertex(minX, minY, minZ);
      tessellator.addVertex(maxX, minY, minZ);
      tessellator.addVertex(maxX, minY, maxZ);
      tessellator.addVertex(minX, minY, maxZ);
      tessellator.addVertex(minX, minY, minZ);
      tessellator.draw();
      tessellator.startDrawing(3);
      tessellator.addVertex(minX, maxY, minZ);
      tessellator.addVertex(maxX, maxY, minZ);
      tessellator.addVertex(maxX, maxY, maxZ);
      tessellator.addVertex(minX, maxY,maxZ);
      tessellator.addVertex(minX, maxY, minZ);
      tessellator.draw();
      tessellator.startDrawing(1);
      tessellator.addVertex(minX, minY, minZ);
      tessellator.addVertex(minX, maxY, minZ);
      tessellator.addVertex(maxX, minY, minZ);
      tessellator.addVertex(maxX,maxY, minZ);
      tessellator.addVertex(maxX, minY, maxZ);
      tessellator.addVertex(maxX, maxY, maxZ);
      tessellator.addVertex(minX, minY, maxZ);
      tessellator.addVertex(minX, maxY, maxZ);
      tessellator.draw();
      GL11.glDepthMask(true);
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glDisable(GL11.GL_BLEND);
  }

@ForgeSubscribe
public void onDrawBlockHighlight1(RenderWorldLastEvent e){

}



}

 

 

Posted

Hi

 

Does it render anything at all?  If not, you're probably drawing the box at the wrong coordinates.

 

You should set up the x,y,z to match what you see in RenderGlobal.drawSelectionBox, see below.

 

The key point is that it calculates an interpolated current position for the player (d0, d1, d2) , and subtracts this from the bounding box coordinates (using getOffsetBoundingBox).

 

-TGG

 

   public void drawSelectionBox(EntityPlayer par1EntityPlayer, MovingObjectPosition par2MovingObjectPosition, int par3, float par4)
    {
        if (par3 == 0 && par2MovingObjectPosition.typeOfHit == EnumMovingObjectType.TILE)
        {
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
            GL11.glLineWidth(2.0F);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDepthMask(false);
            float f1 = 0.002F;
            int j = this.theWorld.getBlockId(par2MovingObjectPosition.blockX, par2MovingObjectPosition.blockY, par2MovingObjectPosition.blockZ);

            if (j > 0)
            {
                Block.blocksList[j].setBlockBoundsBasedOnState(this.theWorld, par2MovingObjectPosition.blockX, par2MovingObjectPosition.blockY, par2MovingObjectPosition.blockZ);
                double d0 = par1EntityPlayer.lastTickPosX + (par1EntityPlayer.posX - par1EntityPlayer.lastTickPosX) * (double)par4;
                double d1 = par1EntityPlayer.lastTickPosY + (par1EntityPlayer.posY - par1EntityPlayer.lastTickPosY) * (double)par4;
                double d2 = par1EntityPlayer.lastTickPosZ + (par1EntityPlayer.posZ - par1EntityPlayer.lastTickPosZ) * (double)par4;
                this.drawOutlinedBoundingBox(Block.blocksList[j].getSelectedBoundingBoxFromPool(this.theWorld, par2MovingObjectPosition.blockX, par2MovingObjectPosition.blockY, par2MovingObjectPosition.blockZ).expand((double)f1, (double)f1, (double)f1).getOffsetBoundingBox(-d0, -d1, -d2));
            }

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

 

 

 

 

Posted

Hi

 

Does it render anything at all?  If not, you're probably drawing the box at the wrong coordinates.

 

You should set up the x,y,z to match what you see in RenderGlobal.drawSelectionBox, see below.

 

The key point is that it calculates an interpolated current position for the player (d0, d1, d2) , and subtracts this from the bounding box coordinates (using getOffsetBoundingBox).

 

-TGG

 

   public void drawSelectionBox(EntityPlayer par1EntityPlayer, MovingObjectPosition par2MovingObjectPosition, int par3, float par4)
    {
        if (par3 == 0 && par2MovingObjectPosition.typeOfHit == EnumMovingObjectType.TILE)
        {
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
            GL11.glLineWidth(2.0F);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDepthMask(false);
            float f1 = 0.002F;
            int j = this.theWorld.getBlockId(par2MovingObjectPosition.blockX, par2MovingObjectPosition.blockY, par2MovingObjectPosition.blockZ);

            if (j > 0)
            {
                Block.blocksList[j].setBlockBoundsBasedOnState(this.theWorld, par2MovingObjectPosition.blockX, par2MovingObjectPosition.blockY, par2MovingObjectPosition.blockZ);
                double d0 = par1EntityPlayer.lastTickPosX + (par1EntityPlayer.posX - par1EntityPlayer.lastTickPosX) * (double)par4;
                double d1 = par1EntityPlayer.lastTickPosY + (par1EntityPlayer.posY - par1EntityPlayer.lastTickPosY) * (double)par4;
                double d2 = par1EntityPlayer.lastTickPosZ + (par1EntityPlayer.posZ - par1EntityPlayer.lastTickPosZ) * (double)par4;
                this.drawOutlinedBoundingBox(Block.blocksList[j].getSelectedBoundingBoxFromPool(this.theWorld, par2MovingObjectPosition.blockX, par2MovingObjectPosition.blockY, par2MovingObjectPosition.blockZ).expand((double)f1, (double)f1, (double)f1).getOffsetBoundingBox(-d0, -d1, -d2));
            }

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

 

 

Thank you !!! It works !!!

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.