Search in sources :

Example 1 with EntityBOPBoat

use of biomesoplenty.common.entities.item.EntityBOPBoat in project BiomesOPlenty by Glitchfiend.

the class ItemBOPBoat method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    float f = 1.0F;
    float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * 1.0F;
    float f2 = playerIn.prevRotationYaw + (playerIn.rotationYaw - playerIn.prevRotationYaw) * 1.0F;
    double d0 = playerIn.prevPosX + (playerIn.posX - playerIn.prevPosX) * 1.0D;
    double d1 = playerIn.prevPosY + (playerIn.posY - playerIn.prevPosY) * 1.0D + (double) playerIn.getEyeHeight();
    double d2 = playerIn.prevPosZ + (playerIn.posZ - playerIn.prevPosZ) * 1.0D;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
    float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
    float f5 = -MathHelper.cos(-f1 * 0.017453292F);
    float f6 = MathHelper.sin(-f1 * 0.017453292F);
    float f7 = f4 * f5;
    float f8 = f3 * f5;
    double d3 = 5.0D;
    Vec3d vec3d1 = vec3d.addVector((double) f7 * 5.0D, (double) f6 * 5.0D, (double) f8 * 5.0D);
    RayTraceResult raytraceresult = worldIn.rayTraceBlocks(vec3d, vec3d1, true);
    if (raytraceresult == null) {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
    } else {
        Vec3d vec3d2 = playerIn.getLook(1.0F);
        boolean flag = false;
        List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().expand(vec3d2.x * 5.0D, vec3d2.y * 5.0D, vec3d2.z * 5.0D).grow(1.0D));
        for (int i = 0; i < list.size(); ++i) {
            Entity entity = list.get(i);
            if (entity.canBeCollidedWith()) {
                AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().grow((double) entity.getCollisionBorderSize());
                if (axisalignedbb.contains(vec3d)) {
                    flag = true;
                }
            }
        }
        if (flag) {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
        } else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
        } else {
            Block block = worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock();
            boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
            EntityBOPBoat entitybopboat = new EntityBOPBoat(worldIn, raytraceresult.hitVec.x, flag1 ? raytraceresult.hitVec.y - 0.12D : raytraceresult.hitVec.y, raytraceresult.hitVec.z);
            entitybopboat.setBoatType(this.type);
            entitybopboat.rotationYaw = playerIn.rotationYaw;
            if (!worldIn.getCollisionBoxes(entitybopboat, entitybopboat.getEntityBoundingBox().grow(-0.1D)).isEmpty()) {
                return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
            } else {
                if (!worldIn.isRemote) {
                    worldIn.spawnEntity(entitybopboat);
                }
                if (!playerIn.capabilities.isCreativeMode) {
                    itemstack.shrink(1);
                }
                playerIn.addStat(StatList.getObjectUseStats(this));
                return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityBOPBoat(biomesoplenty.common.entities.item.EntityBOPBoat) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EntityBOPBoat

use of biomesoplenty.common.entities.item.EntityBOPBoat in project BiomesOPlenty by Glitchfiend.

the class DispenserBehaviorBOPBoat method dispenseStack.

public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
    EnumFacing enumfacing = (EnumFacing) source.getBlockState().getValue(BlockDispenser.FACING);
    World world = source.getWorld();
    double d0 = source.getX() + (double) ((float) enumfacing.getFrontOffsetX() * 1.125F);
    double d1 = source.getY() + (double) ((float) enumfacing.getFrontOffsetY() * 1.125F);
    double d2 = source.getZ() + (double) ((float) enumfacing.getFrontOffsetZ() * 1.125F);
    BlockPos blockpos = source.getBlockPos().offset(enumfacing);
    Material material = world.getBlockState(blockpos).getMaterial();
    double d3;
    if (Material.WATER.equals(material)) {
        d3 = 1.0D;
    } else {
        if (!Material.AIR.equals(material) || !Material.WATER.equals(world.getBlockState(blockpos.down()).getMaterial())) {
            return this.dispenseBehavior.dispense(source, stack);
        }
        d3 = 0.0D;
    }
    EntityBOPBoat entitybopboat = new EntityBOPBoat(world, d0, d1 + d3, d2);
    entitybopboat.setBoatType(this.boatType);
    entitybopboat.rotationYaw = enumfacing.getHorizontalAngle();
    world.spawnEntity(entitybopboat);
    stack.shrink(1);
    return stack;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) EntityBOPBoat(biomesoplenty.common.entities.item.EntityBOPBoat) BlockPos(net.minecraft.util.math.BlockPos) Material(net.minecraft.block.material.Material) World(net.minecraft.world.World)

Aggregations

EntityBOPBoat (biomesoplenty.common.entities.item.EntityBOPBoat)2 Block (net.minecraft.block.Block)1 Material (net.minecraft.block.material.Material)1 Entity (net.minecraft.entity.Entity)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1