Jump to content

Block collision bounds are "static" (Java term)


Reika

Recommended Posts

As a lot of my machines share blocks, and with the way Minecraft instantiates blocks, every instance of a block takes on the hitbox of the last one interacted with (this is the cause behind the "wireless redstone" bug exploit involving iron bars, glass panes, or upside-down stairs).

 

This means that things with wildly different sizes, like the Spawner Controller (meant to be 0.25 blocks tall), the Heater (0.5), Aerosolizer (0.875) and Item Vacuum (1) all have the same hitbox size. While I can make it account for which machine it is (using IBlockAccess), they all change to the last one placed/looked at. So, for example, if I place an Item Vacuum, it is a full block. But I then place a Heater, and now both are 0.5 blocks. Also, since the block sizes are what control my block's power input sides (they only take in power on a side they extend to, so a block <1 tall cannot take power in the top), this actually affects more than just in-world collision detection (though that is in itself a problem, seeing as how it make make you able to "phase through" machines).

 

BuildCraft does not have this issue (I remember engines having a T-shaped hitbox like the model itself) - how did it do it? Before you say "just look at their GitHub", I have done so and they do not even have ANY hitbox code in the BlockEngine class.

Link to comment
Share on other sites

Also remember setBlockBoundsForItemRender() or the items in inventory slots will change as you point your cursor around the world.

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.

Link to comment
Share on other sites

you can use the method setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int x, int y, int z)

I am. The problem is that all blocks change to the last one active. So if I set metadata 4 to full block and 5 to half block, then look at metadata 5, then both blocks become half-block hitboxes. If I then look at metadata 4, both become full blocks. This can be done at will, back and forth.

 

Also remember setBlockBoundsForItemRender() or the items in inventory slots will change as you point your cursor around the world.

I do not care about rendering - these have TE renderers for them. I need the block bounds set for collision detection and some mathematical calculations.

 

I should have provided this code in advance. Each value of m (determined based on metadata and ID) has different values for the bounds.

@Override
public final void setBlockBoundsBasedOnState(IBlockAccess iba, int x, int y, int z) {
	MachineRegistry m = MachineRegistry.getMachine(iba, x, y, z);
	this.setBlockBounds(m.getMinX(), m.getMinY(), m.getMinZ(), m.getMaxX(), m.getMaxY(), m.getMaxZ());
}

Link to comment
Share on other sites

Look at BlockSnow (the natural snow block), see if you can glean some information from it.

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.

Link to comment
Share on other sites

Look at BlockSnow (the natural snow block), see if you can glean some information from it.

Unfortunately no different (in mechanics) than mine:

    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        this.func_96478_d(par1IBlockAccess.getBlockMetadata(par2, par3, par4));
    }

    protected void func_96478_d(int par1)
    {
        int j = par1 & 7;
        float f = (float)(2 * (1 + j)) / 16.0F;
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f, 1.0F);
    }

Link to comment
Share on other sites

Not sure then, because snow works

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.

Link to comment
Share on other sites

Not sure then, because snow works

I would not be surprised if it also suffered from the bug I am experiencing, but think snow's rarity and the fact it is simply walked on leads to it not being noticed.

 

I was actually using it just fine yesterday.  Open creative mode, give yourself snow, right click on the ground to place an 8th.  Right click on the snow to add additional 8ths.

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.

Link to comment
Share on other sites

the answer is in your question. you somewhere must have a static modifier that keeps changing them.

 

here is my block code for a block with custom bounds.

 

package gravestone.grave;

import gravestone.mod_Gravestone;

import java.util.Random;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockGrave extends BlockContainer{

Random rand = new Random();
String name = "";
public BlockGrave(int par1) {
	super(par1, Material.rock);
	this.setBlockBounds(0.4f, 0.0F, 0.4F, 0.6f, 1.0f, 0.6f);
	this.setTickRandomly(true);
}

@Override
public void registerIcons(IconRegister par1IconRegister) {
	this.blockIcon = par1IconRegister.registerIcon("stonebrick");
}

@Override
public TileEntity createNewTileEntity(World world) {
	return new TEGrave();
}

@Override
public int quantityDropped(Random par1Random)
{
	return 0;
}
@Override
public int idDropped(int par1, Random par2Random, int par3)
{
	return -1;
}

@Override
public int getRenderType()
{
	return mod_Gravestone.instance.renderID;
}

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

@Override
public boolean renderAsNormalBlock() {
	return false;
}
public void setName(String name)
{
	this.name = name;
}

@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
	TEGrave te = (TEGrave)par1World.getBlockTileEntity(x, y, z);	

	if(par5EntityPlayer.getCurrentEquippedItem() != null)
	{

	}else{
		if(te != null)
		{
			if(!par5EntityPlayer.isSneaking())
			{
				if(te.theMeta > 0)
				{
					switch(te.playername.length())
					{
					case 0:
						mod_Gravestone.proxy.openGui(1, par5EntityPlayer, "!Empty!",te);
						break;
					default:
						mod_Gravestone.proxy.openGui(1, par5EntityPlayer, te.playername,te);
						break;
					}
				}
				else
				{
					te.theMeta =1;
					if(!par1World.isRemote)
						par5EntityPlayer.sendChatToPlayer("You didn't set a grave Model! Repairing...");
				}
			}
			else
			{
				if(te.ModelRotation < 348.75)
				{
					te.ModelRotation +=11.25f;
				}
				else
				{
					te.ModelRotation =0;
				}
			}
		}
	}
	return false;
}

public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int x, int y, int z) {
	TEGrave te = (TEGrave)par1IBlockAccess.getBlockTileEntity(x,y,z);
	int meta = te.theMeta;
	switch (meta) {
	case 1:
		this.setBlockBounds(0.4f, 0.0F, 0.4F, 0.6f, 1.0f, 0.6f);
		break;
	case 2:
		this.setBlockBounds(0.43f, 0.0F, 0.14F, 0.57f, 1.05f, 0.86f);
		break;
	case 3:
		this.setBlockBounds(0.33f, 0.0F, 0.25F, 0.67f, 0.95f, 0.75f);
		break;
	case 4:
		this.setBlockBounds(0.2f, 0.0F, 0.2F, 0.8f, 1.25f, 0.8f);
		break;
	case 5:
		this.setBlockBounds(0.2f, 0.0F, 0.2F, 0.8f, 1.25f, 0.8f);
		break;
	case 7:
		this.setBlockBounds(0.2f, 0.0F, 0.2F, 0.8f, 1.25f, 0.8f);
		break;
	case 6:
		this.setBlockBounds(0.4f, 0.0F, 0.4F, 0.6f, 1.0f, 0.6f);
		break;
	case 8:
		this.setBlockBounds(0.2f, 0.0F, 0.2F, 0.8f, 1.5f, 0.8f);
		break;
	case 9:
		this.setBlockBounds(0.2f, 0.0F, 0.2F, 0.8f, 1.5f, 0.8f);
		break;
	default:
		this.setBlockBounds(0.4f, 0.0F, 0.4F, 0.6f, 1.0f, 0.6f);
		break;
	}
}

public void breakBlock(World world, int x, int y, int z, int par5, int par6) {

	world.removeBlockTileEntity(x,y,z);
}
}

 

Link to comment
Share on other sites

I was actually using it just fine yesterday.  Open creative mode, give yourself snow, right click on the ground to place an 8th.  Right click on the snow to add additional 8ths.

Yes, but there is no way of telling with snow if its hitboxes are globally being reassigned as new blocks are interacted with, as the only use of the hitbox in snow is the collision detection.

My machines use it for other things, such as determining which sides are valid power input sides.

 

the answer is in your question. you somewhere must have a static modifier that keeps changing them.

here is my block code for a block with custom bounds.

I have double-checked and I do not. Also, my code is fundamentally the same as yours.

Link to comment
Share on other sites

  • 3 months later...

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.