From c6a80ded4b7eac7f108663d5f9899b0a6e9a013e Mon Sep 17 00:00:00 2001 From: yueh Date: Sun, 18 Dec 2016 06:47:42 +0800 Subject: [PATCH] Calculuate the correct AABB for a rotated skychest. --- .../appeng/block/storage/BlockSkyChest.java | 65 ++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/src/main/java/appeng/block/storage/BlockSkyChest.java b/src/main/java/appeng/block/storage/BlockSkyChest.java index fb5e12e1..bf557b98 100644 --- a/src/main/java/appeng/block/storage/BlockSkyChest.java +++ b/src/main/java/appeng/block/storage/BlockSkyChest.java @@ -22,7 +22,6 @@ package appeng.block.storage; import appeng.api.AEApi; import appeng.block.AEBaseTileBlock; import appeng.client.render.blocks.RenderBlockSkyChest; -import appeng.core.features.AEFeature; import appeng.core.sync.GuiBridge; import appeng.helpers.ICustomCollision; import appeng.tile.storage.TileSkyChest; @@ -45,23 +44,34 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import java.util.Collections; -import java.util.EnumSet; import java.util.List; public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision { - public BlockSkyChest() + private static final double AABB_OFFSET_BOTTOM = .0625d; + private static final double AABB_OFFSET_SIDES = 0; + private static final double AABB_OFFSET_TOP = .125d; + + + public enum SkyChestType + { + STONE, BLOCK + } + + + public final SkyChestType type; + + public BlockSkyChest( final SkyChestType type ) { super( Material.rock ); this.setTileEntity( TileSkyChest.class ); this.isOpaque = this.isFullSize = false; this.lightOpacity = 0; - this.hasSubtypes = true; this.setHardness( 50 ); this.blockResistance = 150.0f; - this.setFeature( EnumSet.of( AEFeature.Core, AEFeature.SkyStoneChests ) ); + this.type = type; } @Override @@ -70,6 +80,7 @@ public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision return metadata; } + @Override public ItemStack getPickBlock( final MovingObjectPosition target, final World world, final int x, final int y, final int z, final EntityPlayer player ) { @@ -133,29 +144,39 @@ public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision return this.getUnlocalizedName(); } - @Override - public Iterable getSelectedBoundingBoxesFromPool( final World w, final int x, final int y, final int z, final Entity e, final boolean isVisual ) + public Iterable getSelectedBoundingBoxesFromPool( final World w, final int x, final int y, final int z, final Entity thePlayer, final boolean isVisual ) { - final TileSkyChest sk = this.getTileEntity( w, x, y, z ); - ForgeDirection o = ForgeDirection.UNKNOWN; - - if( sk != null ) - { - o = sk.getUp(); - } - - final double offsetX = o.offsetX == 0 ? 0.06 : 0.0; - final double offsetY = o.offsetY == 0 ? 0.06 : 0.0; - final double offsetZ = o.offsetZ == 0 ? 0.06 : 0.0; - - final double sc = 0.06; - return Collections.singletonList( AxisAlignedBB.getBoundingBox( Math.max( 0.0, offsetX - o.offsetX * sc ), Math.max( 0.0, offsetY - o.offsetY * sc ), Math.max( 0.0, offsetZ - o.offsetZ * sc ), Math.min( 1.0, ( 1.0 - offsetX ) - o.offsetX * sc ), Math.min( 1.0, ( 1.0 - offsetY ) - o.offsetY * sc ), Math.min( 1.0, ( 1.0 - offsetZ ) - o.offsetZ * sc ) ) ); + return Collections.singletonList( computeAABB( w, x, y, z ) ); } @Override public void addCollidingBlockToList( final World w, final int x, final int y, final int z, final AxisAlignedBB bb, final List out, final Entity e ) { - out.add( AxisAlignedBB.getBoundingBox( 0.05, 0.05, 0.05, 0.95, 0.95, 0.95 ) ); + out.add( computeAABB( w, x, y, z ) ); + } + + private AxisAlignedBB computeAABB( final World w, final int x, final int y, final int z ) + { + final TileSkyChest sk = this.getTileEntity( w, x, y, z ); + ForgeDirection o = ForgeDirection.UP; + + if( sk != null ) + o = sk.getUp(); + + final double offsetX = o.offsetX == 0 ? AABB_OFFSET_BOTTOM : AABB_OFFSET_SIDES; + final double offsetY = o.offsetY == 0 ? AABB_OFFSET_BOTTOM : AABB_OFFSET_SIDES; + final double offsetZ = o.offsetZ == 0 ? AABB_OFFSET_BOTTOM : AABB_OFFSET_SIDES; + + // x/z needs to be multiplied by -1, thus we simply add not substract. + final double minX = Math.max( 0.0, offsetX + o.offsetX * AABB_OFFSET_TOP ); + final double minY = Math.max( 0.0, offsetY - o.offsetY * AABB_OFFSET_TOP ); + final double minZ = Math.max( 0.0, offsetZ + o.offsetZ * AABB_OFFSET_TOP ); + + final double maxX = Math.min( 1.0, ( 1.0 - offsetX ) + o.offsetX * AABB_OFFSET_TOP ); + final double maxY = Math.min( 1.0, ( 1.0 - offsetY ) - o.offsetY * AABB_OFFSET_TOP ); + final double maxZ = Math.min( 1.0, ( 1.0 - offsetZ ) + o.offsetZ * AABB_OFFSET_TOP ); + + return AxisAlignedBB.getBoundingBox( minX, minY, minZ, maxX, maxY, maxZ ); } }