Jump to content

Recommended Posts

Posted

Hi, I made a new block using this tutorial http://www.minecraftforge.net/wiki/Rendering_a_Techne_Model_as_a_Block .The model was a 2x2x2 block. Everything was ok until I placed the block, I can walk throw the block... The bounds are all ok but I don't know why the only part y can't walk throw is the right corner

 

BigBoxBlock

package deantonious.blocks;

import java.util.List;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;


public class BigBoxBlock extends BlockContainer {

        //Treat it like a normal block here. The Block Bounds are a good idea - the first three are X Y and Z of the botton-left corner,
        //And the second three are the top-right corner.
        public BigBoxBlock(int id) {
                super(id, Material.iron);
                this.setCreativeTab(CreativeTabs.tabBlock);
                this.setBlockBounds(0.0F, 0.0F, 0.0F, 2.0F, 2.0F, 2.0F);               
        }
               

        //Make sure you set this as your TileEntity class relevant for the block!
        @Override
        public TileEntity createNewTileEntity(World world) {
                return new BigBoxEntity();
        }
        
        //You don't want the normal render type, or it wont render properly.
        @Override
        public int getRenderType() {
                return -1;
        }
        
        //It's not an opaque cube, so you need this.
        @Override
        public boolean isOpaqueCube() {
                return false;
        }
        
        //It's not a normal block, so you need this too.
        public boolean renderAsNormalBlock() {
                return false;
        }
        
        //This is the icon to use for showing the block in your hand.
        public void registerIcons(IconRegister icon) {
                this.blockIcon = icon.registerIcon("bigbox");
        }

}

 

BigBoxEntity

package deantonious.blocks;

import net.minecraft.tileentity.TileEntity;

public class BigBoxEntity extends TileEntity {

}

 

BigBoxModel

package deantonious.blocks;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class BigBoxModel extends ModelBase
{
  //fields
    ModelRenderer Shape1;
  
  public BigBoxModel()
  {
    textureWidth = 128;
    textureHeight = 128;
    
      Shape1 = new ModelRenderer(this, 0, 0);
      Shape1.addBox(0F, 0F, 0F, 32, 32, 32);
      Shape1.setRotationPoint(-24F, -8F, -7F);
      Shape1.setTextureSize(128, 128);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Shape1.render(f5);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }

}

 

BigBoxRenderer

package deantonious.blocks;

import org.lwjgl.opengl.GL11;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class BigBoxRenderer extends TileEntitySpecialRenderer {
        
        //The model of your block
        private final BigBoxModel model;
        
        public BigBoxRenderer() {
                this.model = new BigBoxModel();
        }
        
        private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
                int meta = world.getBlockMetadata(x, y, z);
                GL11.glPushMatrix();
                GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
                GL11.glPopMatrix();
        }
        
        @Override
        public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        //The PushMatrix tells the renderer to "start" doing something.
                GL11.glPushMatrix();
        //This is setting the initial location.
                GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        //This is the texture of your block. It's pathed to be the same place as your other blocks here.
       //Use in 1.6.2  this
        bindTexture(new ResourceLocation("textures/blocks/bigboxtext.png")); 
        //the ':' is very important

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                       
                GL11.glPushMatrix();
                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        //A reference to your Model file. Again, very important.
                this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        //Tell it to stop rendering for both the PushMatrix's
                GL11.glPopMatrix();
                GL11.glPopMatrix();
        }

	//Set the lighting stuff, so it changes it's brightness properly.       
        private void adjustLightFixture(World world, int i, int j, int k, Block block) {
                Tessellator tess = Tessellator.instance;
                float brightness = block.getBlockBrightness(world, i, j, k);
                int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
                int modulousModifier = skyLight % 65536;
                int divModifier = skyLight / 65536;
                tess.setColorOpaque_F(brightness, brightness, brightness);
                OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
        }
}

 

Sorry for my english and thanks for any help

Twitter: @deantonious || TeamSpeak Server: ts3.deantonious.es

Posted
    /**
     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
     * cleared to be reused)
     */
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
    }

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

    /**
     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
     * cleared to be reused)
     */
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
    }

 

I know that, the problem was how to use it... (Thanks for the reply)

Twitter: @deantonious || TeamSpeak Server: ts3.deantonious.es

Posted

Return a new AABB that is the right size.  The collission box, the boundary size, and the MovingObjectPosition collisionRayTrace box are all used for different purposes.

 

You'll need to set all three of them to being your 2x2x2 box.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

AxisAlignedBB.getAABBPool().getAABB(double, double, double, double, double, double)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

The problem is the getCollisionBoundingBoxFromPool() is only called and used when the entity is within the block. You can verify this by adding a print in the getCollisionBoundingBoxFromPool()  method, or placing a breakpoint. So the problem is that the entity isn't realizing that it's colliding with the block when it's outside the normal block bounds. My solution would be to add 'ghost blocks'. Invisible blocks that have a collision box.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

The problem is the getCollisionBoundingBoxFromPool() is only called and used when the entity is within the block. You can verify this by adding a print in the getCollisionBoundingBoxFromPool()  method, or placing a breakpoint. So the problem is that the entity isn't realizing that it's colliding with the block when it's outside the normal block bounds. My solution would be to add 'ghost blocks'. Invisible blocks that have a collision box.

I know what you mean, but I don't know how to make it... I've looked for it, but no result

Twitter: @deantonious || TeamSpeak Server: ts3.deantonious.es

Posted

Well, let me help you then.

 

I think you should know how to create a block that's invisible. So I'm assuming you now have a block called GhostBigBoxBlock. When you place down a BigBoxBlock, you want to place down 7 GhostBigBoxBlocks as well. So in your BigBoxBlock you can override onBlockAdded() :

public void onBlockAdded(World world, int x, int y, int z)
    {
     world.setBlock(x + 1, y      , z      , GhostBigBoxBlock.blockID, 0, 3);
     world.setBlock(x      , y      , z + 1, GhostBigBoxBlock.blockID, 1, 3);
     world.setBlock(x + 1, y      , z + 1, GhostBigBoxBlock.blockID, 2, 3);
     world.setBlock(x      , y + 1, z      , GhostBigBoxBlock.blockID, 3, 3);
     world.setBlock(x + 1, y + 1, z      , GhostBigBoxBlock.blockID, 4, 3);
     world.setBlock(x      , y + 1, z + 1, GhostBigBoxBlock.blockID, 5, 3);
     world.setBlock(x + 1, y + 1, z + 1, GhostBigBoxBlock.blockID, 6, 3);
}

As you can see, for every one of the ghost blocks added, I set a different metadata. This we can use in the next part. The next part is the breaking of the block. When you break any of the ghost blocks (or BigBoxBlock) you need to remove every other ghost block as well. And we use the metadata here for the GhostBigBoxBlocks to let them know in which position they are in relation to the BigBoxBlock. And if one of the ghost blocks get broken, we remove the BigBoxBlock which then will remove every GhostBigBoxBlock on his part. To do this override breakBlock() of the GhostBigBoxBlock :

public void breakBlock(World world, int x, int y, int z, int blockID, int metadata)
    {
         super.breakBlock(world, x, y, z, blockID, metadata);
         switch(metadata){
             case 0:
                  world.setBlockToAir(x - 1, y, z);
                  break;
             case 1:
                  world.setBlockToAir(x, y, z - 1);
                  break;
             //TODO do this for every of the 7 cases
         }
    }

So this will break the BigBoxBlock when one of the Ghost Blocks get broken. Now to break every Ghost block override breakBlock in BigBoxBlock:

public void breakBlock(World world, int x, int y, int z, int blockID, int metadata)
    {
         super.breakBlock(world, x, y, z, blockID, metadata);
         for(int i = x; i < x + 2; i++) for(int j = y; j < y + 2; j++) for(int k = z; k < z + 2; k++) world.setBlockToAir(i, j, k);
    }

 

That's how I would do it, if others have better solutions I'm happy to hear them :).

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

Well, let me help you then.

 

I think you should know how to create a block that's invisible. So I'm assuming you now have a block called GhostBigBoxBlock. When you place down a BigBoxBlock, you want to place down 7 GhostBigBoxBlocks as well. So in your BigBoxBlock you can override onBlockAdded() :

public void onBlockAdded(World world, int x, int y, int z)
    {
     world.setBlock(x + 1, y      , z      , GhostBigBoxBlock.blockID, 0, 3);
     world.setBlock(x      , y      , z + 1, GhostBigBoxBlock.blockID, 1, 3);
     world.setBlock(x + 1, y      , z + 1, GhostBigBoxBlock.blockID, 2, 3);
     world.setBlock(x      , y + 1, z      , GhostBigBoxBlock.blockID, 3, 3);
     world.setBlock(x + 1, y + 1, z      , GhostBigBoxBlock.blockID, 4, 3);
     world.setBlock(x      , y + 1, z + 1, GhostBigBoxBlock.blockID, 5, 3);
     world.setBlock(x + 1, y + 1, z + 1, GhostBigBoxBlock.blockID, 6, 3);
}

As you can see, for every one of the ghost blocks added, I set a different metadata. This we can use in the next part. The next part is the breaking of the block. When you break any of the ghost blocks (or BigBoxBlock) you need to remove every other ghost block as well. And we use the metadata here for the GhostBigBoxBlocks to let them know in which position they are in relation to the BigBoxBlock. And if one of the ghost blocks get broken, we remove the BigBoxBlock which then will remove every GhostBigBoxBlock on his part. To do this override breakBlock() of the GhostBigBoxBlock :

public void breakBlock(World world, int x, int y, int z, int blockID, int metadata)
    {
         super.breakBlock(world, x, y, z, blockID, metadata);
         switch(metadata){
             case 0:
                  world.setBlockToAir(x - 1, y, z);
                  break;
             case 1:
                  world.setBlockToAir(x, y, z - 1);
                  break;
             //TODO do this for every of the 7 cases
         }
    }

So this will break the BigBoxBlock when one of the Ghost Blocks get broken. Now to break every Ghost block override breakBlock in BigBoxBlock:

public void breakBlock(World world, int x, int y, int z, int blockID, int metadata)
    {
         super.breakBlock(world, x, y, z, blockID, metadata);
         for(int i = x; i < x + 2; i++) for(int j = y; j < y + 2; j++) for(int k = z; k < z + 2; k++) world.setBlockToAir(i, j, k);
    }

 

That's how I would do it, if others have better solutions I'm happy to hear them :).

 

Thanks, it really helped me. The only thing I don't understand is the way of removing the hole block with one click. I don't know how to make the other cases...

Twitter: @deantonious || TeamSpeak Server: ts3.deantonious.es

Posted

The way I would do it is to look at BlockHalfSlab, and use the methods that make it's shape smaller. I think its


public BlockHalfSlab(int par1, boolean par2, Material par3Material)
    {
        super(par1, par3Material);
        this.isDoubleSlab = par2;


        if (par2)
        {
            opaqueCubeLookup[par1] = true;
        }
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
        }


        this.setLightOpacity(255);
    }


    /**
     * Updates the blocks bounds based on its current state. Args: world, x, y, z
     */
    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        if (this.isDoubleSlab)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        else
        {
            boolean flag = (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & != 0;


            if (flag)
            {
                this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F);
            }
            else
            {
                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
            }
        }
    }

/**
     * Sets the block's bounds for rendering it as an item
     */
    public void setBlockBoundsForItemRender()
    {
        if (this.isDoubleSlab)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
        }
    }


    /**
     * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
     * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
     */
    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
    {
        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    }


    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return this.isDoubleSlab;
    }

My mod was a while ago, so I don't exactly remember, but playing around with this and looking at the methods and their arguments will yield results. Anyway, that's what I used for my mod, to make a block a little smaller than a half slab. You could also look at the enchantment table, it's less that a full block. Or BlockSkull, since it's both lower and smaller than a normal block. Good luck with it! Hope I was some help.

Posted

Problem here is that his block is bigger than a block. And then you have that problem that the entity doesn't even check if it's colliding a block if it isn't in the block.

 

I won't just give the other cases of the switch, as I want you to understand my thinking. What I'm doing here is that I'm using metadata to let the ghost block know in what position the ghost block is in relation to the base block. If you look at what happens when the metadata is 0:

 world.setBlock(x + 1, y      , z      , GhostBigBoxBlock.blockID, 0, 3);//The block is placed 1 further on the x-axis than the base block

So the ghost block now 'knows' that if it has metadata 0 it is placed 1 block further on the x-axis than the base block. So the base block is at x - 1, y, z. So when we break the ghost block, we break the base block as well by doing:

world.setBlockToAir(x - 1, y, z);

I hope you understand now.

 

This solution isn't finished yet. You now could replace blocks in the world by placing a BigBoxBlock next to it. You can prevent this from happening, and you could look at BlockCactus.java how it's done for the cactus. Look at the canPlaceBlockAt() method.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

I fixed it! Code for checking if there is any block near the block:

 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
        {
            return !super.canPlaceBlockAt(par1World, par2, par3, par4) ? false : this.canBlockStay(par1World, par2, par3, par4);
        }

        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
        {
           
            if (par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2 +1 , par3, par4 + 1).isSolid())
            {
                return false;
            }
            else
            {
                int l = par1World.getBlockId(par2, par3 - 1, par4);
                return true;
            }
        }

Twitter: @deantonious || TeamSpeak Server: ts3.deantonious.es

Posted

You're nearly there yes!:) You've only covered 3/7 cases though! You forgot to check all the positions on y+1 ;).

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

You're nearly there yes!:) You've only covered 3/7 cases though! You forgot to check all the positions on y+1 ;).

 

This was the one of my 2x2x1 block xD. The right one is this:

public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
        {
            return !super.canPlaceBlockAt(par1World, par2, par3, par4) ? false : this.canBlockStay(par1World, par2, par3, par4);
        }

        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
        {
           
            if (par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2 +1 , par3, par4 + 1).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2 + 1, par3 + 1, par4).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2, par3 + 1, par4 + 1).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2 + 1, par3 + 1, par4 + 1).isSolid())
            {
                return false;
            }
            
            else if (par1World.getBlockMaterial(par2, par3 + 1, par4).isSolid())
            {
                return false;
            }
            
            else
            {
                int l = par1World.getBlockId(par2, par3 - 1, par4);
                return true;
            }
        }

Twitter: @deantonious || TeamSpeak Server: ts3.deantonious.es

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.