Fix flowers bounding box not aligned correctly with rendering

This commit is contained in:
Cheeserolls 2015-05-02 00:45:32 +01:00
parent aeae6cb2f5
commit ee2fd6ab6d
3 changed files with 27 additions and 7 deletions

View File

@ -105,23 +105,23 @@ public class BlockBOPFlower1 extends BlockDecoration {
switch ((FlowerType) world.getBlockState(pos).getValue(VARIANT))
{
case CLOVER:
this.setBlockBoundsByRadiusAndHeight(0.5F, 0.015625F);
this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.5F, 0.015625F, pos);
break;
case ORANGE_COSMOS:
this.setBlockBoundsByRadiusAndHeight(0.2F, 0.8F);
this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.2F, 0.8F, pos);
break;
case PINK_DAFFODIL: case DANDELION:
this.setBlockBoundsByRadiusAndHeight(0.2F, 0.6F);
this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.2F, 0.6F, pos);
break;
case WHITE_ANEMONE:
this.setBlockBoundsByRadiusAndHeight(0.2F, 0.5F);
this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.2F, 0.5F, pos);
break;
default:
this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F);
this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.4F, 0.8F, pos);
break;
}
}

View File

@ -93,7 +93,7 @@ public class BlockBOPFlower2 extends BlockDecoration {
switch ((FlowerType) world.getBlockState(pos).getValue(VARIANT))
{
default:
this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F);
this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.4F, 0.8F, pos);
break;
}
}

View File

@ -63,12 +63,32 @@ public class BlockDecoration extends Block implements IBOPBlock
// utility function for setting the block bounds - typically decoration blocks are smaller than full block size
public void setBlockBoundsByRadiusAndHeight(float radius, float height)
{
this.setBlockBoundsByRadiusAndHeight(radius,height,false);
this.setBlockBoundsByRadiusAndHeight(radius, height, false);
}
public void setBlockBoundsByRadiusAndHeight(float radius, float height, boolean fromTop)
{
this.setBlockBounds(0.5F - radius, (fromTop ? 1.0F - height : 0.0F), 0.5F - radius, 0.5F + radius, (fromTop ? 1.0F : height), 0.5F + radius);
}
// some decoration blocks have a random XZ offset applied - if we set block bounds based on state, we may need these functions to correct for the offset
public void setBlockBoundsByRadiusAndHeightWithXZOffset(float radius, float height, BlockPos pos)
{
this.setBlockBoundsByRadiusAndHeightWithXZOffset(radius, height, false, pos);
}
public void setBlockBoundsByRadiusAndHeightWithXZOffset(float radius, float height, boolean fromTop, BlockPos pos)
{
// some Minecraft weirdness to get over here: in BlockModelRenderer there are 2 alternative quad drawers
// renderModelAmbientOcclusionQuads and renderModelStandardQuads, and they use very nearly but not quite the same functions for the XZ offset
// both versions rely on getting an unpredictable long 'hash' of the BlockPos coordinates
// the ambient one uses long i = MathHelper.getPositionRandom(pos) (which equates to long i = (long)(x * 3129871) ^ (long)z * 116129781L ^ (long)y; )
// the standard one uses long i = (long)(x * 3129871) ^ (long)z * 116129781L; (no dependence on y)
// we use the standard one here, because that's the one being used to draw the plants
// it looks like a mistake to me. I think they probably intended to use MathHelper.getPositionRandom for both, but maybe there is some reason behind it
long i = (long)(pos.getX() * 3129871) ^ (long)pos.getZ() * 116129781L;
i = i * i * 42317861L + i * 11L;
float dx = (((float)(i >> 16 & 15L) / 15.0F) - 0.5F) * 0.5F;
float dz = (((float)(i >> 24 & 15L) / 15.0F) - 0.5F) * 0.5F;
this.setBlockBounds(0.5F - radius + dx, (fromTop ? 1.0F - height : 0.0F), 0.5F - radius + dz, 0.5F + radius + dx, (fromTop ? 1.0F : height), 0.5F + radius + dz);
}
// add a canBlockStay() check before placing this block
@Override