public List <AxisAlignedBB> getBlockCollisionBoxes(AxisAlignedBB box) { List <AxisAlignedBB> blocks = new List <AxisAlignedBB>(); var bb = box.union(box); for (int x = (int)bb.min.X, maxX = (int)bb.max.X; x < maxX; x++) { for (int y = (int)bb.min.Y, maxY = (int)bb.max.Y; y < maxY; y++) { for (int z = (int)bb.min.Z, maxZ = (int)bb.max.Z; z < maxZ; z++) { var pos = new BlockPos(x, y, z); var block = Game.INSTANCE.world.getBlock(pos); if (block == EnumBlock.AIR) { continue; } blocks.Add( ModelManager.getModelForBlock(block, getMetadata(pos)).boundingBox.offset(pos.vector)); } } } return(blocks); }
public virtual void Move() { var bb_o = boundingBox.union(boundingBox.offset(motion)); List <AxisAlignedBB> list = Game.INSTANCE.world.getBlockCollisionBoxes(bb_o); var m_orig = motion; for (int i = 0; i < list.Count; i++) { var blockBB = list[i]; motion.Y = blockBB.calculateYOffset(boundingBox, motion.Y); } boundingBox = boundingBox.offset(motion * Vector3.UnitY); for (int i = 0; i < list.Count; i++) { var blockBB = list[i]; motion.X = blockBB.calculateXOffset(boundingBox, motion.X); } boundingBox = boundingBox.offset(motion * Vector3.UnitX); for (int i = 0; i < list.Count; i++) { var blockBB = list[i]; motion.Z = blockBB.calculateZOffset(boundingBox, motion.Z); } boundingBox = boundingBox.offset(motion * Vector3.UnitZ); setPositionToBB(); onGround = Math.Abs(m_orig.Y - motion.Y) > 0.00001f && m_orig.Y < 0.0D; if (Math.Abs(m_orig.X - motion.X) > 0.00001f) { motion.X = 0; } if (Math.Abs(m_orig.Z - motion.Z) > 0.00001f) { motion.Z = 0; } if (onGround && motion.Y < 0) { motion.Y = 0; } }