Java Code Examples for net.minecraft.block.state.IBlockState#getCollisionBoundingBox()

The following examples show how to use net.minecraft.block.state.IBlockState#getCollisionBoundingBox() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecipeLogicSteam.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void tryDoVenting() {
    BlockPos machinePos = metaTileEntity.getPos();
    EnumFacing ventingSide = getVentingSide();
    BlockPos ventingBlockPos = machinePos.offset(ventingSide);
    IBlockState blockOnPos = metaTileEntity.getWorld().getBlockState(ventingBlockPos);
    if (blockOnPos.getCollisionBoundingBox(metaTileEntity.getWorld(), ventingBlockPos) == Block.NULL_AABB) {
        metaTileEntity.getWorld()
            .getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ventingBlockPos), EntitySelectors.CAN_AI_TARGET)
            .forEach(entity -> entity.attackEntityFrom(DamageSources.getHeatDamage(), 6.0f));
        WorldServer world = (WorldServer) metaTileEntity.getWorld();
        double posX = machinePos.getX() + 0.5 + ventingSide.getFrontOffsetX() * 0.6;
        double posY = machinePos.getY() + 0.5 + ventingSide.getFrontOffsetY() * 0.6;
        double posZ = machinePos.getZ() + 0.5 + ventingSide.getFrontOffsetZ() * 0.6;

        world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, posX, posY, posZ,
            7 + world.rand.nextInt(3),
            ventingSide.getFrontOffsetX() / 2.0,
            ventingSide.getFrontOffsetY() / 2.0,
            ventingSide.getFrontOffsetZ() / 2.0, 0.1);
        world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f);
        setNeedsVenting(false);
    } else if (!ventingStuck) {
        setVentingStuck(true);
    }
}
 
Example 2
Source File: ItemSlab.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos, int subtype)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == this.singleSlab)
    {
        int subtype1 = singleSlabCS.getSubtype(iblockstate);

        if (subtype1 == subtype)
        {
            IBlockState stateDouble = this.makeState(subtype1);
            AxisAlignedBB axisalignedbb = stateDouble == null ? Block.NULL_AABB : stateDouble.getCollisionBoundingBox(worldIn, pos);

            if (stateDouble != null && axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, stateDouble, 11))
            {
                SoundType soundtype = stateDouble.getBlock().getSoundType(stateDouble, worldIn, pos, player);
                worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                stack.shrink(1);
            }

            return true;
        }
    }

    return false;
}
 
Example 3
Source File: SealableBlockHandler.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
/**
 * Checks if a block is full sized based off of block bounds. This
 * is not a perfect check as mods may have a full size. However,
 * have a 3D model that doesn't look a full block in size. There
 * is no way around this other than to make a black list check.
 *
 * @param block - block to compare
 * @return true if full block
 */
public static boolean isFullBlock(IBlockAccess world, BlockPos pos, IBlockState state)
{
	AxisAlignedBB bb = state.getCollisionBoundingBox((World) world, pos);
	
   	if(bb == null)
   		return false;
	
       int minX = (int) (bb.minX * 100);
       int minY = (int) (bb.minY * 100);
       int minZ = (int) (bb.minZ * 100);
       int maxX = (int) (bb.maxX * 100);
       int maxY = (int) (bb.maxY * 100);
       int maxZ = (int) (bb.maxZ * 100);

       return minX == 0 && minY == 0 && minZ == 0 && maxX == 100 && maxY == 100 && maxZ == 100;
}
 
Example 4
Source File: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
private static boolean canLandAtLocation(EntityLiving ent, int x, int y, int z) {

    World world = ent.getEntityWorld();
    ent.setPosition(x + 0.5, y, z + 0.5);
    if (!SpawnUtil.isSpaceAvailableForSpawn(world, ent, false, false)) {
      return false;
    }

    BlockPos below = new BlockPos(x, y, z).down();
    IBlockState bs = world.getBlockState(below);
    if (!bs.getMaterial().isSolid()) {
      return false;
    }    
    AxisAlignedBB collides = bs.getCollisionBoundingBox(world, below);
    return collides != null;
  }
 
Example 5
Source File: FlyNodeProcessor.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
private boolean entityFits(Entity entityIn, int x, int y, int z) {

    BlockPos.MutableBlockPos mutableblockpos = new BlockPos.MutableBlockPos();
    for (int i = x; i < x + entitySizeX; ++i) {
      for (int j = y; j < y + entitySizeY; ++j) {
        for (int k = z; k < z + entitySizeZ; ++k) {
          IBlockState bs = blockaccess.getBlockState(mutableblockpos.setPos(i, j, k));
          if (bs.getMaterial() != Material.AIR) {
            AxisAlignedBB bb = bs.getCollisionBoundingBox(entityIn.world, mutableblockpos);
            if(bb != null) {
              return false;
            }
          }
        }
      }
    }

    return true;
  }
 
Example 6
Source File: WorldHelper.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns true if block is replaceable and has no collider
 */
public static boolean isAirLikeBlock(World world, BlockPos pos)
{
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	boolean replaceable = block.isReplaceable(world, pos);
	boolean noCollider = (state.getCollisionBoundingBox(world, pos) == Block.NULL_AABB);
	return (replaceable || noCollider);
}
 
Example 7
Source File: ItemSlab.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos.offset(facing), facing, itemstack))
    {
        int subtype = getMetadata(itemstack);
        IBlockState currentState = worldIn.getBlockState(pos);

        if (currentState.getBlock() == singleSlab)
        {
            int subtype1 = this.singleSlabCS.getSubtype(currentState);
            net.minecraft.block.BlockSlab.EnumBlockHalf half = currentState.getValue(net.minecraft.block.BlockSlab.HALF);

            if ((facing == EnumFacing.UP && half == net.minecraft.block.BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && half == net.minecraft.block.BlockSlab.EnumBlockHalf.TOP)
                && subtype1 == subtype)
            {
                IBlockState stateDouble = this.makeState(subtype1);
                AxisAlignedBB axisalignedbb = stateDouble == null ? Block.NULL_AABB : stateDouble.getCollisionBoundingBox(worldIn, pos);

                if (stateDouble != null && axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, stateDouble, 11))
                {
                    SoundType soundtype = stateDouble.getBlock().getSoundType(stateDouble, worldIn, pos, player);
                    worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    itemstack.shrink(1);
                }

                return EnumActionResult.SUCCESS;
            }
        }

        return this.tryPlace(player, itemstack, worldIn, pos.offset(facing), subtype) ? EnumActionResult.SUCCESS : super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    } else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example 8
Source File: ItemSnow.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack))
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        BlockPos blockpos = pos;

        if ((facing != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
        {
            blockpos = pos.offset(facing);
            iblockstate = worldIn.getBlockState(blockpos);
            block = iblockstate.getBlock();
        }

        if (block == this.block)
        {
            int i = iblockstate.getValue(BlockSnow.LAYERS);

            if (i < 8)
            {
                IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, i + 1);
                AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);

                if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && worldIn.setBlockState(blockpos, iblockstate1, 10))
                {
                    SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, pos, player);
                    worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);

                    if (player instanceof EntityPlayerMP)
                    {
                        CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
                    }

                    itemstack.shrink(1);
                    return EnumActionResult.SUCCESS;
                }
            }
        }

        return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example 9
Source File: EntityEnderPearlReusable.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void onImpact(RayTraceResult rayTraceResult)
{
    Entity thrower = this.getThrower();

    // Thrower not found, drop the item if applicable and bail out
    if (thrower == null)
    {
        if (this.getEntityWorld().isRemote == false && this.canPickUp)
        {
            this.dropAsItem();
        }

        this.setDead();
        return;
    }

    // Don't collide with the thrower or the entities in the 'stack' with the thrower
    if (this.getEntityWorld().isRemote == false && rayTraceResult.typeOfHit == RayTraceResult.Type.ENTITY)
    {
        if (EntityUtils.doesEntityStackContainEntity(rayTraceResult.entityHit, thrower))
        {
            return;
        }

        if (rayTraceResult.entityHit instanceof EntityPlayerMP && ((EntityPlayerMP)rayTraceResult.entityHit).isSpectator())
        {
            return;
        }

        if (rayTraceResult.entityHit instanceof EntityLivingBase)
        {
            rayTraceResult.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, thrower), 0.0f);
        }
    }
    // Don't collide with blocks without a collision box
    else if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.getBlockPos() != null)
    {
        IBlockState state = this.getEntityWorld().getBlockState(rayTraceResult.getBlockPos());
        AxisAlignedBB aabb = state.getCollisionBoundingBox(this.getEntityWorld(), rayTraceResult.getBlockPos());
        if (aabb == Block.NULL_AABB)
        {
            return;
        }
    }

    // A regular pearl lands, teleport the thrower
    if (this.isElite == false)
    {
        // If the thrower is currently riding an elite pearl, unmount the pearl
        Entity bottom = thrower.getLowestRidingEntity();
        if (bottom instanceof EntityEnderPearlReusable && bottom.isBeingRidden())
        {
            bottom.removePassengers();
        }

        if (this.getEntityWorld().isRemote == false)
        {
            TeleportEntity.teleportEntityWithProjectile(thrower, this, rayTraceResult, this.teleportDamage, true, true);
        }
    }
    // An Elite pearl lands, which is still being ridden by something (see above)
    else if (this.isBeingRidden())
    {
        Entity entity = this.getPassengers().get(0);
        this.removePassengers();

        if (this.getEntityWorld().isRemote == false)
        {
            TeleportEntity.teleportEntityWithProjectile(entity, this, rayTraceResult, this.teleportDamage, true, true);
        }
    }

    // Try to add the pearl straight back to the player's inventory
    if (this.getEntityWorld().isRemote == false && this.returnToPlayersInventory() == false)
    {
        this.dropAsItem();
    }

    this.setDead();
}
 
Example 10
Source File: EntityOwl.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public void onLivingUpdate() {

  // setDead();
  super.onLivingUpdate();
  prevWingRotation = wingRotation;
  prevDestPos = destPos;
  destPos = (float) (destPos + (onGround ? -1 : 4) * 0.3D);
  destPos = MathHelper.clamp(destPos, 0.0F, 1.0F);
  if (!onGround && wingRotDelta < 1.0F) {
    wingRotDelta = 1.0F;
  }
  wingRotDelta = (float) (wingRotDelta * 0.9D);
  float flapSpeed = 2f;
  double yDelta = Math.abs(posY - prevPosY);
  if (yDelta != 0) {
    // normalise between 0 and 0.02
    yDelta = Math.min(1, yDelta / 0.02);
    yDelta = Math.max(yDelta, 0.75);
    flapSpeed *= yDelta;
  }
  wingRotation += wingRotDelta * flapSpeed;
   

  if (!world.isRemote && !isChild() && --timeUntilNextEgg <= 0) {
    if (isOnLeaves()) {
      playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
      dropItem(EnderZoo.itemOwlEgg, 1);        
    }
    timeUntilNextEgg = getNextLayingTime();
  }

  
  
  AxisAlignedBB movedBB = getEntityBoundingBox().offset(0, motionY, 0);
  BlockPos ep = getPosition();
  BlockPos pos = new BlockPos(ep.getX(), movedBB.maxY, ep.getZ());
  IBlockState bs = world.getBlockState(pos);
  if (bs.getMaterial() != Material.AIR) {
    AxisAlignedBB bb = bs.getCollisionBoundingBox(world, pos);
    if (bb != null) {
      double ouch = movedBB.maxY - bb.minY;
      if (ouch == 0) {
        motionY = -0.1;
      } else {
        motionY = 0;
      }
    }
  }
  

  if (onGround) {
    motionX *= groundSpeedRatio;
    motionZ *= groundSpeedRatio;
  }
}