net.minecraft.util.math.RayTraceResult Java Examples

The following examples show how to use net.minecraft.util.math.RayTraceResult. 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: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addBlockLandingEffects(World worldObj, Vector3 entityPos, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager, int numParticles) {
    Vector3 start = entityPos.copy();
    Vector3 end = start.copy().add(Vector3.down.copy().multiply(4));
    RayTraceResult traceResult = worldObj.rayTraceBlocks(start.vec3(), end.vec3(), true, false, true);
    double speed = 0.15;
    Random randy = new Random();

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    if (traceResult != null && traceResult.typeOfHit == Type.BLOCK && numParticles != 0) {
        for (int i = 0; i < numParticles; i++) {
            double mX = randy.nextGaussian() * speed;
            double mY = randy.nextGaussian() * speed;
            double mZ = randy.nextGaussian() * speed;
            DigIconParticle digIconParticle = DigIconParticle.newLandingParticle(worldObj, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, atlasSprite);
            digIconParticle.setRBGColorF(red, green, blue);
            manager.addEffect(digIconParticle);
        }
    }
}
 
Example #2
Source File: EntityFukumame.java    From TofuCraftReload with MIT License 6 votes vote down vote up
/**
 * Called when this EntityThrowable hits a block or entity.
 */
@Override
protected void onImpact(RayTraceResult par1MovingObjectPosition) {
    Entity entityHit = par1MovingObjectPosition.entityHit;
    if (entityHit == this.ignoreEntity && this.age < 5) {
        return;
    }
    if (par1MovingObjectPosition.entityHit != null) {
        double d = this.getDamage();
        d *= this.isCrit ? 2.5D : 1.0D;


        entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float) d);
        if (entityHit instanceof EntityLivingBase) {
            EntityLivingBase entityLivivng = (EntityLivingBase) entityHit;
            entityLivivng.hurtResistantTime = entityLivivng.maxHurtResistantTime / 2;
        }
        for (int i = 0; i < 3; ++i) {
            this.world.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
        }
    }

    if (!this.world.isRemote) {
        this.setDead();
    }
}
 
Example #3
Source File: EntityBeam.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
protected void onImpact(RayTraceResult result) {
    if (!this.world.isRemote) {
        if (result.entityHit != null) {
            if (this.shootingEntity != null) {
                if (result.entityHit.attackEntityFrom(DamageSource.causeMobDamage(this.shootingEntity), 6.0F)) {
                    this.applyEnchantments(this.shootingEntity, result.entityHit);
                }
            } else {
                result.entityHit.attackEntityFrom(DamageSource.MAGIC, 6.0F);
            }
        }

        this.world.newExplosion(this, this.posX, this.posY, this.posZ, 0.5F, false, net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity));
        this.setDead();
    }
}
 
Example #4
Source File: ToolJackHammer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<BlockPos> getAOEBlocks(ItemStack itemStack, EntityPlayer player, RayTraceResult rayTraceResult) {
    if(player.isCreative()) {
        return Collections.emptyList();
    }
    ArrayList<BlockPos> result = new ArrayList<>();
    BlockPos pos = rayTraceResult.getBlockPos();
    JackHammerMode jackHammerMode = MODE_SWITCH_BEHAVIOR.getModeFromItemStack(itemStack);
    EnumFacing horizontalFacing = player.getHorizontalFacing();
    int xSizeExtend = (jackHammerMode.getHorizontalSize() - 1) / 2;
    int ySizeExtend = (jackHammerMode.getVerticalSize() - 1) / 2;
    for (int x = -xSizeExtend; x <= xSizeExtend; x++) {
        for (int y = -ySizeExtend; y <= ySizeExtend; y++) {
            //do not check center block - it's handled now
            if (x == 0 && y == 0) continue;
            BlockPos offsetPos = rotate(pos, x, y, rayTraceResult.sideHit, horizontalFacing);
            IBlockState blockState = player.world.getBlockState(offsetPos);
            if(itemStack.canHarvestBlock(blockState)) {
                result.add(offsetPos);
            }
        }
    }
    return result;
}
 
Example #5
Source File: RayTraceUtils.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
public static RayTraceResult traceToSchematicWorld(Entity entity, double range, boolean respectRenderRange)
{
    World world = SchematicWorldHandler.getSchematicWorld();
    boolean invert = Hotkeys.INVERT_GHOST_BLOCK_RENDER_STATE.getKeybind().isKeybindHeld();

    if (world == null ||
        (respectRenderRange &&
            (Configs.Visuals.ENABLE_RENDERING.getBooleanValue() == false ||
             Configs.Visuals.ENABLE_SCHEMATIC_RENDERING.getBooleanValue() == invert)))
    {
        return null;
    }

    Vec3d start = entity.getPositionEyes(1f);
    Vec3d look = entity.getLook(1f).scale(range);
    Vec3d end = start.add(look);

    LayerRange layerRange = respectRenderRange ? DataManager.getRenderLayerRange() : null;

    return fi.dy.masa.malilib.util.RayTraceUtils.rayTraceBlocks(world, start, end,
            fi.dy.masa.malilib.util.RayTraceUtils::checkRayCollision,
            fi.dy.masa.malilib.util.RayTraceUtils.RayTraceFluidHandling.SOURCE_ONLY,
            fi.dy.masa.malilib.util.RayTraceUtils.BLOCK_FILTER_NON_AIR,
            false, true, layerRange, 200);
}
 
Example #6
Source File: ItemSakuraDiamond.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
  public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
      ItemStack itemstack = playerIn.getHeldItem(handIn);
      RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, false);

      if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME) {
          return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
      }
if (worldIn.isRemote) {
    int j = worldIn.rand.nextInt(2) * 2 - 1;
    int k = worldIn.rand.nextInt(2) * 2 - 1;

    double d0 = playerIn.getPosition().getX() + 0.25D * j;
    double d1 = playerIn.getPosition().getY() + 1D;
    double d2 = playerIn.getPosition().getZ() + 0.25D * k;
    double d3 = worldIn.rand.nextFloat() * j * 0.1D;
    double d4 = (worldIn.rand.nextFloat() * 0.055D) + 0.015D;
    double d5 = worldIn.rand.nextFloat() * k * 0.1D;

    SakuraMain.proxy.spawnParticle(SakuraParticleType.LEAVESSAKURA, d0, d1, d2, d3, -d4, d5);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
  }
 
Example #7
Source File: RayTraceUtils.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static boolean traceToSelectionBoxBody(SelectionBox box, Vec3d start, Vec3d end)
{
    if (box.getPos1() != null && box.getPos2() != null)
    {
        AxisAlignedBB bb = PositionUtils.createEnclosingAABB(box.getPos1(), box.getPos2());
        RayTraceResult hit = bb.calculateIntercept(start, end);

        if (hit != null)
        {
            double dist = hit.hitVec.distanceTo(start);

            if (closestBoxDistance < 0 || dist < closestBoxDistance)
            {
                closestBoxDistance = dist;
                closestBox = new RayTraceWrapper(box, Corner.NONE, hit.hitVec);
            }

            return true;
        }
    }

    return false;
}
 
Example #8
Source File: RayTraceUtils.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static boolean traceToSelectionBoxCorner(SelectionBox box, Corner corner, Vec3d start, Vec3d end)
{
    BlockPos pos = (corner == Corner.CORNER_1) ? box.getPos1() : (corner == Corner.CORNER_2) ? box.getPos2() : null;

    if (pos != null)
    {
        AxisAlignedBB bb = PositionUtils.createAABBForPosition(pos);
        RayTraceResult hit = bb.calculateIntercept(start, end);

        if (hit != null)
        {
            double dist = hit.hitVec.distanceTo(start);

            if (closestCornerDistance < 0 || dist < closestCornerDistance)
            {
                closestCornerDistance = dist;
                closestCorner = new RayTraceWrapper(box, corner, hit.hitVec);
            }

            return true;
        }
    }

    return false;
}
 
Example #9
Source File: SchematicEditUtils.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static boolean breakAllIdenticalSchematicBlocks(Minecraft mc)
{
    Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
    RayTraceWrapper wrapper = RayTraceUtils.getSchematicWorldTraceWrapperIfClosest(mc.world, entity, 20);

    // The state can be null in 1.13+
    if (wrapper != null)
    {
        RayTraceResult trace = wrapper.getRayTraceResult();
        BlockPos pos = trace.getBlockPos();
        IBlockState stateOriginal = SchematicWorldHandler.getSchematicWorld().getBlockState(pos);

        return setAllIdenticalSchematicBlockStates(pos, stateOriginal, Blocks.AIR.getDefaultState());
    }

    return false;
}
 
Example #10
Source File: GTItemFluidTube.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ActionResult<ItemStack> tryPickUpFluid(@Nonnull World world, @Nonnull EntityPlayer player,
		@Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) {
	RayTraceResult mop = this.rayTrace(world, player, true);
	ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop);
	if (ret != null)
		return ret;
	if (mop == null) {
		return ActionResult.newResult(EnumActionResult.PASS, itemstack);
	}
	BlockPos clickPos = mop.getBlockPos();
	if (world.isBlockModifiable(player, clickPos)) {
		FluidActionResult result = FluidUtil.tryPickUpFluid(itemstack, player, world, clickPos, mop.sideHit);
		if (result.isSuccess()) {
			ItemHandlerHelper.giveItemToPlayer(player, result.getResult());
			itemstack.shrink(1);
			return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
		}
	}
	return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
 
Example #11
Source File: NoVoidModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Minecraft mc = Minecraft.getMinecraft();
        if(!mc.player.noClip) {
            if (mc.player.posY <= this.height.getValue()) {

                final RayTraceResult trace = mc.world.rayTraceBlocks(mc.player.getPositionVector(), new Vec3d(mc.player.posX, 0, mc.player.posZ), false, false, false);

                if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) {
                    return;
                }

                mc.player.setVelocity(0, 0, 0);

                if (mc.player.getRidingEntity() != null) {
                    mc.player.getRidingEntity().setVelocity(0, 0, 0);
                }
            }
        }
    }
}
 
Example #12
Source File: PullDownModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
private boolean hullCollidesWithBlock(final Entity entity,
        final Vec3d nextPosition) {
    final AxisAlignedBB boundingBox = entity.getEntityBoundingBox();
    final Vec3d[] boundingBoxCorners = {
            new Vec3d(boundingBox.minX, boundingBox.minY, boundingBox.minZ),
            new Vec3d(boundingBox.minX, boundingBox.minY, boundingBox.maxZ),
            new Vec3d(boundingBox.maxX, boundingBox.minY, boundingBox.minZ),
            new Vec3d(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ)
    };

    final Vec3d entityPosition = entity.getPositionVector();
    for (final Vec3d entityBoxCorner : boundingBoxCorners) {
        final Vec3d nextBoxCorner = entityBoxCorner.subtract(entityPosition).add(nextPosition);
        final RayTraceResult rayTraceResult = entity.world.rayTraceBlocks(entityBoxCorner,
                nextBoxCorner, true, false, true);
        if (rayTraceResult == null)
            continue;

        if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
            return true;
    }

    return false;
}
 
Example #13
Source File: BlockPipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return ItemStack.EMPTY;
    }
    if (target instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult result = (CuboidRayTraceResult) target;
        if (result.cuboid6.data instanceof CoverSideData) {
            EnumFacing coverSide = ((CoverSideData) result.cuboid6.data).side;
            CoverBehavior coverBehavior = pipeTile.getCoverableImplementation().getCoverAtSide(coverSide);
            return coverBehavior == null ? ItemStack.EMPTY : coverBehavior.getPickItem();
        }
    }
    return getDropItem(pipeTile);
}
 
Example #14
Source File: ICoverable.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
static EnumFacing traceCoverSide(RayTraceResult result) {
    if (result instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) result;
        if (rayTraceResult.cuboid6.data == null) {
            return determineGridSideHit(result);
        } else if (rayTraceResult.cuboid6.data instanceof CoverSideData) {
            return ((CoverSideData) rayTraceResult.cuboid6.data).side;
        } else if (rayTraceResult.cuboid6.data instanceof BlockPipe.PipeConnectionData) {
            return ((PipeConnectionData) rayTraceResult.cuboid6.data).side;
        } else if(rayTraceResult.cuboid6.data instanceof PrimaryBoxData) {
            PrimaryBoxData primaryBoxData = (PrimaryBoxData) rayTraceResult.cuboid6.data;
            return primaryBoxData.usePlacementGrid ? determineGridSideHit(result) : result.sideHit;
        } else return null; //unknown hit type, return null
    }
    //normal collision ray trace, return side hit
    return determineGridSideHit(result);
}
 
Example #15
Source File: RayTraceUtils.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
public static BlockPos getTargetedPosition(World world, Entity entity, double maxDistance, boolean sneakToOffset)
{
    RayTraceResult trace = fi.dy.masa.malilib.util.RayTraceUtils
            .getRayTraceFromEntity(world, entity, RayTraceFluidHandling.NONE, false, maxDistance);

    if (trace.typeOfHit != RayTraceResult.Type.BLOCK)
    {
        return null;
    }

    BlockPos pos = trace.getBlockPos();

    // Sneaking puts the position adjacent the targeted block face, not sneaking puts it inside the targeted block
    if (sneakToOffset == entity.isSneaking())
    {
        pos = pos.offset(trace.sideHit);
    }

    return pos;
}
 
Example #16
Source File: SchematicPlacementManager.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setPositionOfCurrentSelectionToRayTrace(Minecraft mc, double maxDistance)
{
    SchematicPlacement schematicPlacement = this.getSelectedSchematicPlacement();

    if (schematicPlacement != null)
    {
        Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
        RayTraceResult trace = fi.dy.masa.malilib.util.RayTraceUtils.getRayTraceFromEntity(mc.world, entity, RayTraceFluidHandling.NONE, false, maxDistance);

        if (trace.typeOfHit != RayTraceResult.Type.BLOCK)
        {
            return;
        }

        BlockPos pos = trace.getBlockPos();

        // Sneaking puts the position inside the targeted block, not sneaking puts it against the targeted face
        if (mc.player.isSneaking() == false)
        {
            pos = pos.offset(trace.sideHit);
        }

        this.setPositionOfCurrentSelectionTo(pos, mc);
    }
}
 
Example #17
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Cuboid6 getBoundingBox(IBlockState blockState, World world, RayTraceResult target) {
    BlockPos blockPos = target.getBlockPos();
    if (target instanceof CuboidRayTraceResult) {
        return ((CuboidRayTraceResult) target).cuboid6.copy().add(blockPos);
    }
    return new Cuboid6(blockState.getBoundingBox(world, blockPos)).add(blockPos);
}
 
Example #18
Source File: WrenchOverlayRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
    EntityPlayer player = event.getPlayer();
    World world = player.world;
    RayTraceResult target = event.getTarget();

    if (target.typeOfHit != RayTraceResult.Type.BLOCK) {
        return; //magically, draw block highlight is called not only for blocks (see forge issues)
    }

    BlockPos pos = target.getBlockPos();
    IBlockState blockState = world.getBlockState(pos);
    TileEntity tileEntity = world.getTileEntity(pos);
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);

    if (tileEntity != null && shouldDrawOverlayForItem(heldItem, tileEntity) && useGridForRayTraceResult(target)) {
        EnumFacing facing = target.sideHit;
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        GlStateManager.glLineWidth(2.0F);
        GlStateManager.disableTexture2D();
        GlStateManager.depthMask(false);

        if (world.getWorldBorder().contains(pos)) {
            double d3 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) event.getPartialTicks();
            double d4 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) event.getPartialTicks();
            double d5 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) event.getPartialTicks();
            AxisAlignedBB box = blockState.getSelectedBoundingBox(world, pos).grow(0.002D).offset(-d3, -d4, -d5);
            RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 0.0F, 0.0F, 0.4F);
            drawOverlayLines(facing, box);
        }

        GlStateManager.depthMask(true);
        GlStateManager.enableTexture2D();
        GlStateManager.disableBlend();

        event.setCanceled(true);
    }
}
 
Example #19
Source File: ToolUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void setToolModeBlockState(ToolMode mode, boolean primary, Minecraft mc)
{
    IBlockState state = Blocks.AIR.getDefaultState();
    double reach = mc.playerController.getBlockReachDistance();
    Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
    RayTraceWrapper wrapper = RayTraceUtils.getGenericTrace(mc.world, entity, reach, true);

    if (wrapper != null)
    {
        RayTraceResult trace = wrapper.getRayTraceResult();

        if (trace != null)
        {
            BlockPos pos = trace.getBlockPos();

            if (wrapper.getHitType() == HitType.SCHEMATIC_BLOCK)
            {
                state = SchematicWorldHandler.getSchematicWorld().getBlockState(pos);
            }
            else if (wrapper.getHitType() == HitType.VANILLA)
            {
                state = mc.world.getBlockState(pos).getActualState(mc.world, pos);
            }
        }
    }

    if (primary)
    {
        mode.setPrimaryBlock(state);
    }
    else
    {
        mode.setSecondaryBlock(state);
    }
}
 
Example #20
Source File: ScannerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Pair<BlockPos, IBlockState> getHitBlock(EntityPlayer entityPlayer) {
    RayTraceResult result = RayTracer.retrace(entityPlayer);
    if (result.typeOfHit == Type.BLOCK) {
        BlockPos blockPos = result.getBlockPos();
        IBlockState blockState = entityPlayer.world.getBlockState(blockPos);
        if (blockState.getBlock() instanceof IScannableBlock) {
            return Pair.of(blockPos, blockState);
        }
    }
    return null;
}
 
Example #21
Source File: ToolMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<BlockPos> getAOEBlocks(ItemStack itemStack, EntityPlayer player, RayTraceResult rayTraceResult) {
    T metaToolValueItem = getItem(itemStack);
    if (metaToolValueItem != null) {
        IToolStats toolStats = metaToolValueItem.getToolStats();
        return toolStats.getAOEBlocks(itemStack, player, rayTraceResult);
    }
    return Collections.emptyList();
}
 
Example #22
Source File: DynamiteEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onImpact(RayTraceResult result) {
    if (result.sideHit == EnumFacing.UP) {
        inGround = true;
        blockPosCollidedAt = result.getBlockPos();
    } else {
        if (result.sideHit.getAxis() == EnumFacing.Axis.Z) {
            this.motionZ = 0;
        } else if (result.sideHit.getAxis() == EnumFacing.Axis.X) {
            this.motionX = 0;
        } else if (result.sideHit.getAxis() == EnumFacing.Axis.Y) {
            this.motionY = 0;
        }
    }
}
 
Example #23
Source File: EntitySphere.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
@Override
public void onUpdate() {
    if (this.world.isRemote || this.world.isBlockLoaded(new BlockPos(this))) {
        super.onUpdate();

        ++this.ticksInAir;
        RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, this.ticksInAir >= 25, this.shootingEntity);

        if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
            this.onImpact(raytraceresult);
        }

        this.posX += this.motionX;
        this.posY += this.motionY;
        this.posZ += this.motionZ;
        ProjectileHelper.rotateTowardsMovement(this, 0.2F);
        float f = this.getMotionFactor();

        if (this.isInWater()) {
            for (int i = 0; i < 4; ++i) {
                this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
            }

            f = 0.8F;
        }

        this.motionX += this.accelerationX;
        this.motionY += this.accelerationY;
        this.motionZ += this.accelerationZ;
        this.motionX *= f;
        this.motionY *= f;
        this.motionZ *= f;
        this.setPosition(this.posX, this.posY, this.posZ);
    } else {
        this.setDead();
    }
}
 
Example #24
Source File: BlockMachine.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
    if (metaTileEntity == null)
        return ItemStack.EMPTY;
    if (target instanceof CuboidRayTraceResult) {
        return metaTileEntity.getPickItem((CuboidRayTraceResult) target, player);
    }
    return ItemStack.EMPTY;
}
 
Example #25
Source File: BlockCustomParticle.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    Pair<TextureAtlasSprite, Integer> atlasSprite = getParticleTexture(worldObj, target.getBlockPos());
    ParticleHandlerUtil.addHitEffects(state, worldObj, target, atlasSprite.getLeft(), atlasSprite.getRight(), manager);
    return true;
}
 
Example #26
Source File: EntitySphere.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
protected void onImpact(RayTraceResult result) {
    if (!this.world.isRemote) {
        if (result.entityHit != null) {
            result.entityHit.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this, this.shootingEntity), 10.0F);
        }
        this.setDead();
    }
}
 
Example #27
Source File: RayTraceTools.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
public static void rayTrace(Beam beam, Function<Entity, Boolean> consumer) {
    // Based on EntityRender.getMouseOver(float partialTicks) which we can't use because that's client only
    Vec3d start = beam.getStart();
    Vec3d lookVec = beam.getLookVec();
    Vec3d end = beam.getEnd();
    double dist = beam.getDist();
    World world = beam.getWorld();
    EntityPlayer player = beam.getPlayer();
    List<Entity> targets = world.getEntitiesInAABBexcluding(player, player.getEntityBoundingBox().expand(lookVec.x * dist, lookVec.y * dist, lookVec.z * dist).grow(1.0D, 1.0D, 1.0D),
            Predicates.and(EntitySelectors.NOT_SPECTATING, ent -> ent != null && ent.canBeCollidedWith()));
    List<Pair<Entity, Double>> hitTargets = new ArrayList<>();
    for (Entity target : targets) {
        AxisAlignedBB targetBB = target.getEntityBoundingBox().grow(target.getCollisionBorderSize());
        if (targetBB.contains(start)) {
            hitTargets.add(Pair.of(target, 0.0));
        } else {
            RayTraceResult targetResult = targetBB.calculateIntercept(start, end);
            if (targetResult != null) {
                double d3 = start.distanceTo(targetResult.hitVec);
                if (d3 < dist) {
                    hitTargets.add(Pair.of(target, d3));
                }
            }
        }
    }
    hitTargets.sort(Comparator.comparing(Pair::getRight));
    hitTargets.stream().filter(pair -> consumer.apply(pair.getLeft())).findFirst();
}
 
Example #28
Source File: SchematicEditUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean setTargetedSchematicBlockState(Minecraft mc, IBlockState state)
{
    WorldSchematic world = SchematicWorldHandler.getSchematicWorld();
    Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
    RayTraceWrapper traceWrapper = RayTraceUtils.getGenericTrace(mc.world, entity, 20, true);

    if (world != null && traceWrapper != null && traceWrapper.getHitType() == RayTraceWrapper.HitType.SCHEMATIC_BLOCK)
    {
        RayTraceResult trace = traceWrapper.getRayTraceResult();
        BlockPos pos = trace.getBlockPos();
        return setTargetedSchematicBlockState(pos, state);
    }

    return false;
}
 
Example #29
Source File: WrenchOverlayRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean useGridForRayTraceResult(RayTraceResult result) {
    if(result instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult traceResult = (CuboidRayTraceResult) result;
        //use grid only for center hit or for primary box with placement grid enabled
        if(traceResult.cuboid6.data == null) {
            return true; //default is true
        } else if(traceResult.cuboid6.data instanceof PrimaryBoxData) {
            PrimaryBoxData primaryBoxData = (PrimaryBoxData) traceResult.cuboid6.data;
            return primaryBoxData.usePlacementGrid;
        } else return false; //otherwise, do not use grid
    }
    //also use it for default collision blocks
    return true;
}
 
Example #30
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static ProjectileHitEvent callProjectileHitEvent(Entity entity, RayTraceResult position) {
    Block hitBlock = null;
    if (position.typeOfHit == RayTraceResult.Type.BLOCK) {
        BlockPos blockposition = position.getBlockPos();
        hitBlock = entity.getBukkitEntity().getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
    }

    ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), position.entityHit == null ? null : position.entityHit.getBukkitEntity(), hitBlock);
    entity.world.getServer().getPluginManager().callEvent(event);
    return event;
}