Jump to content

[1.10.2] Custom hedge bug


Erfurt

Recommended Posts

Hey guys,

 

I'm working on some hedges, and I have noticed that mobs try to jump over them, even when the hedges is 1½ block high, just as fences and walls are. I have looked at the blockWall class, but that didn't really help me much, as I can't see a hole lot of difference between my hedge code and the code in blockWall. Maybe it's a method I'm missing(have tried the isPassable method didn't help with my problem :) ), or maybe I have to add my hedge class/blocks to a barrier variable somewhere. Any help would be appreciated, as I'm pretty much stuck with this.

 

Here's my code

 

 

Hedge Class

public class Hedge extends Block
{
public static final PropertyBool NORTH = PropertyBool.create("north");
public static final PropertyBool EAST = PropertyBool.create("east");
public static final PropertyBool SOUTH = PropertyBool.create("south");
public static final PropertyBool WEST = PropertyBool.create("west");

protected static final AxisAlignedBB[] BOUNDING_BOX = new AxisAlignedBB[] { new AxisAlignedBB(0.1875, 0.0, 0.1875, 0.8125, 1.0, 0.8125), new AxisAlignedBB(0.1875, 0.0, 0.1875, 0.8125, 1.0, 1.0), new AxisAlignedBB(0.0, 0.0, 0.1875, 0.8125, 1.0, 0.8125), new AxisAlignedBB(0.0, 0.0, 0.1875, 0.8125, 1.0, 1.0), new AxisAlignedBB(0.1875, 0.0, 0.0, 0.8125, 1.0, 0.8125), new AxisAlignedBB(0.1875, 0.0, 0.0, 0.8125, 1.0, 1.0), new AxisAlignedBB(0.0, 0.0, 0.0, 0.8125, 1.0, 0.8125), new AxisAlignedBB(0.0, 0.0, 0.0, 0.8125, 1.0, 1.0), new AxisAlignedBB(0.1875, 0.0, 0.1875, 1.0, 1.0, 0.8125), new AxisAlignedBB(0.1875, 0.0, 0.1875, 1.0, 1.0, 1.0), new AxisAlignedBB(0.0, 0.0, 0.1875, 1.0, 1.0, 0.8125), new AxisAlignedBB(0.0, 0.0, 0.1875, 1.0, 1.0, 1.0), new AxisAlignedBB(0.1875, 0.0, 0.0, 1.0, 1.0, 0.8125), new AxisAlignedBB(0.1875, 0.0, 0.0, 1.0, 1.0, 1.0), new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 0.8125), new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0) };
    protected static final AxisAlignedBB[] CLIP_BOUNDING_BOX = new AxisAlignedBB[] {BOUNDING_BOX[0].setMaxY(1.5D), BOUNDING_BOX[1].setMaxY(1.5D), BOUNDING_BOX[2].setMaxY(1.5D), BOUNDING_BOX[3].setMaxY(1.5D), BOUNDING_BOX[4].setMaxY(1.5D), BOUNDING_BOX[5].setMaxY(1.5D), BOUNDING_BOX[6].setMaxY(1.5D), BOUNDING_BOX[7].setMaxY(1.5D), BOUNDING_BOX[8].setMaxY(1.5D), BOUNDING_BOX[9].setMaxY(1.5D), BOUNDING_BOX[10].setMaxY(1.5D), BOUNDING_BOX[11].setMaxY(1.5D), BOUNDING_BOX[12].setMaxY(1.5D), BOUNDING_BOX[13].setMaxY(1.5D), BOUNDING_BOX[14].setMaxY(1.5D), BOUNDING_BOX[15].setMaxY(1.5D)};
    
private static final AxisAlignedBB COLLISION_BOX_CENTER = new AxisAlignedBB(0.1875, 0.0, 0.1875, 0.8125, 1.5, 0.8125);
private static final AxisAlignedBB COLLISION_BOX_NORTH = CollisionHelper.getBlockBounds(EnumFacing.NORTH, 0.8125, 0.0, 0.1875, 1.0, 1.5, 0.8125);
private static final AxisAlignedBB COLLISION_BOX_EAST = CollisionHelper.getBlockBounds(EnumFacing.EAST, 0.8125, 0.0, 0.1875, 1.0, 1.5, 0.8125);
private static final AxisAlignedBB COLLISION_BOX_SOUTH = CollisionHelper.getBlockBounds(EnumFacing.SOUTH, 0.8125, 0.0, 0.1875, 1.0, 1.5, 0.8125);
private static final AxisAlignedBB COLLISION_BOX_WEST = CollisionHelper.getBlockBounds(EnumFacing.WEST, 0.8125, 0.0, 0.1875, 1.0, 1.5, 0.8125);

public Hedge(String name)
{
	super(Material.LEAVES);
	setUnlocalizedName(name);
	setRegistryName(name);
	setSoundType(SoundType.PLANT);
	setHardness(1.0F);
	setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
	Blocks.FIRE.setFireInfo(this, 30, 60);
	setCreativeTab(CreativeTabs.DECORATIONS);
}

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

@Override
public boolean isNormalCube(IBlockState state)
{
	return false;
}

@Override
public boolean isFullCube(IBlockState state)
{
	return false;
}

public BlockRenderLayer getBlockLayer()
{
	return Blocks.LEAVES.getBlockLayer();
}
    
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) 
{
	state = this.getActualState(state, source, pos);
	return BOUNDING_BOX[getBoundingBoxId(state)];
}

@Nullable
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
    {
        blockState = this.getActualState(blockState, worldIn, pos);
        return CLIP_BOUNDING_BOX[getBoundingBoxId(blockState)];
    }

private static int getBoundingBoxId(IBlockState state)
    {
        int i = 0;

        if (((Boolean)state.getValue(NORTH)).booleanValue())
        {
            i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
        }

        if (((Boolean)state.getValue(EAST)).booleanValue())
        {
            i |= 1 << EnumFacing.EAST.getHorizontalIndex();
        }

        if (((Boolean)state.getValue(SOUTH)).booleanValue())
        {
            i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
        }

        if (((Boolean)state.getValue(WEST)).booleanValue())
        {
            i |= 1 << EnumFacing.WEST.getHorizontalIndex();
        }

        return i;
    }

@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB axisAligned, List<AxisAlignedBB> axisAlignedList, Entity collidingEntity) 
{
	if (state.getValue(NORTH))
        {
            super.addCollisionBoxToList(pos, axisAligned, axisAlignedList, COLLISION_BOX_NORTH);
        }

        if (state.getValue(EAST))
        {
        	super.addCollisionBoxToList(pos, axisAligned, axisAlignedList, COLLISION_BOX_EAST);
        }

        if (state.getValue(SOUTH))
        {
        	super.addCollisionBoxToList(pos, axisAligned, axisAlignedList, COLLISION_BOX_SOUTH);
        }

        if (state.getValue(WEST))
        {
        	super.addCollisionBoxToList(pos, axisAligned, axisAlignedList, COLLISION_BOX_WEST);
        }
        
        super.addCollisionBoxToList(pos, axisAligned, axisAlignedList, COLLISION_BOX_CENTER);
}

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	return state.withProperty(NORTH, Boolean.valueOf(isHedge(world, pos.north()))).withProperty(EAST, Boolean.valueOf(isHedge(world, pos.east()))).withProperty(SOUTH, Boolean.valueOf(isHedge(world, pos.south()))).withProperty(WEST, Boolean.valueOf(isHedge(world, pos.west())));
}

@Override
public int getMetaFromState(IBlockState state)
{
	return 0;
}

@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[] { NORTH, EAST, SOUTH, WEST });
}

public boolean isHedge(IBlockAccess world, BlockPos pos)
{
	return world.getBlockState(pos).getBlock() instanceof Hedge || world.getBlockState(pos).getBlock() instanceof BlockFenceGate || world.getBlockState(pos).getBlock().isNormalCube(world.getBlockState(pos));
}
}

CollisionHelper Class (not sure if you guys need to see this or not)

public class CollisionHelper
{
public static AxisAlignedBB getBlockBounds(EnumFacing facing, double x1, double y1, double z1, double x2, double y2, double z2)
{
	double[] bounds = fixRotation(facing, x1, z1, x2, z2);
	return new AxisAlignedBB(bounds[0], y1, bounds[1], bounds[2], y2, bounds[3]);
}

private static double[] fixRotation(EnumFacing facing, double var1, double var2, double var3, double var4)
{
	switch (facing)
	{
	case WEST:
		double var_temp_1 = var1;
		var1 = 1.0F - var3;
		double var_temp_2 = var2;
		var2 = 1.0F - var4;
		var3 = 1.0F - var_temp_1;
		var4 = 1.0F - var_temp_2;
		break;
	case NORTH:
		double var_temp_3 = var1;
		var1 = var2;
		var2 = 1.0F - var3;
		var3 = var4;
		var4 = 1.0F - var_temp_3;
		break;
	case SOUTH:
		double var_temp_4 = var1;
		var1 = 1.0F - var4;
		double var_temp_5 = var2;
		var2 = var_temp_4;
		double var_temp_6 = var3;
		var3 = 1.0F - var_temp_5;
		var4 = var_temp_6;
		break;
	default:
		break;
	}
	return new double[] { var1, var2, var3, var4 };
}
}

 

 

Link to comment
Share on other sites

Ok, taking a look at the pathfinding code (which decompiles horribly by the way, see below...) the only way to trigger PathNodeType.FENCE is extending

BlockFence

,

BlockWall

or

BlockFenceGate

.

Extending them is not always viable, so I suggest you submit a pull request to forge to allow a block to specify it's own

PathNodeType

.

 

And now for some code horror:

 

Before

[spoiler=After]JWke5pO.png

 

 

What a mess :P

 

I'll make that suggestion, in the mean time I have been able to extend BlockFence to make my custom Hedges, but as you said that isn't always viable.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So I've been making this custom modpack for a while now, I accidentally updated everything and now it wont even start the game past the launch screen. I'm sure there's a mod I need to remove or turn off--but I'm not sure which or if there is something else going on. As time has gone on (I'm not sure if this is related) but the framerates have been dropping into the single digits. I'm not sure what to do anymore except possibly start over... I've pasted the crash log it gave me below--I can't find what's causing it. Help please? https://mclo.gs/Bml06zJ
    • Hi, if you still want to see all player's commands, you can also use a plugin like Stalker Plugin for example ( see https://hangar.papermc.io/StalkerPlugin/Stalker ) with /stalk <player> you can directly see a player's commands or /stalkall you will see all player's commands (in game)
    • HOW I FOUND FAVOR IN THE HANDS OF SACLUX COMPTECH SPECIALST.    I was a victim of a phishing scam and lost 3.5 BTC to thieves. I had been investing in Bitcoin for a while and had a significant amount stored in my wallet. One day, I received an email that looked like it was from my wallet provider, asking me to log in and update my account information. I didn't think twice and entered my login credentials. Little did I know, the email was from scammers who had created a fake website that looked identical to my wallet provider's site. They stole my login credentials and drained my wallet. I was devastated. I had invested a lot of money and time into Bitcoin, and it was all gone in an instant. I tried to contact my wallet provider, but they couldn't help me recover my stolen Bitcoins. I also reported the incident to the authorities, but they couldn't do much to help. It was a hard lesson learned until I came across a testimony of a woman about how she got her stolen investment recovered by a hacker called SACLUX COMPTECH SPECIALST, I searched the name on Google and got their contact and contacted them, behold they got my stolen money back within  2 hours. Thanks to SACLUX COMPTECH SPECIALST for their great job. I invite you to visit their website at http:sacluxcomptechspecialst.com/ to learn more about their services. 
    • HOW I FOUND FAVOR IN THE HANDS OF SACLUX COMPTECH SPECIALST.    I was a victim of a phishing scam and lost 3.5 BTC to thieves. I had been investing in Bitcoin for a while and had a significant amount stored in my wallet. One day, I received an email that looked like it was from my wallet provider, asking me to log in and update my account information. I didn't think twice and entered my login credentials. Little did I know, the email was from scammers who had created a fake website that looked identical to my wallet provider's site. They stole my login credentials and drained my wallet. I was devastated. I had invested a lot of money and time into Bitcoin, and it was all gone in an instant. I tried to contact my wallet provider, but they couldn't help me recover my stolen Bitcoins. I also reported the incident to the authorities, but they couldn't do much to help. It was a hard lesson learned until I came across a testimony of a woman about how she got her stolen investment recovered by a hacker called SACLUX COMPTECH SPECIALST, I searched the name on Google and got their contact and contacted them, behold they got my stolen money back within  2 hours. Thanks to SACLUX COMPTECH SPECIALST for their great job. I invite you to visit their website at http:sacluxcomptechspecialst.com/ to learn more about their services. 
    • HOW I FOUND FAVOR IN THE HANDS OF SACLUX COMPTECH SPECIALST.    I was a victim of a phishing scam and lost 3.5 BTC to thieves. I had been investing in Bitcoin for a while and had a significant amount stored in my wallet. One day, I received an email that looked like it was from my wallet provider, asking me to log in and update my account information. I didn't think twice and entered my login credentials. Little did I know, the email was from scammers who had created a fake website that looked identical to my wallet provider's site. They stole my login credentials and drained my wallet. I was devastated. I had invested a lot of money and time into Bitcoin, and it was all gone in an instant. I tried to contact my wallet provider, but they couldn't help me recover my stolen Bitcoins. I also reported the incident to the authorities, but they couldn't do much to help. It was a hard lesson learned until I came across a testimony of a woman about how she got her stolen investment recovered by a hacker called SACLUX COMPTECH SPECIALST, I searched the name on Google and got their contact and contacted them, behold they got my stolen money back within  2 hours. Thanks to SACLUX COMPTECH SPECIALST for their great job. I invite you to visit their website at http:sacluxcomptechspecialst.com/ to learn more about their services. 
  • Topics

×
×
  • Create New...

Important Information

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