net.minecraft.util.math.RayTraceResult.Type Java Examples
The following examples show how to use
net.minecraft.util.math.RayTraceResult.Type.
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 |
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: RayTraceUtils.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
@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 #3
Source File: ItemBasicLaserGun.java From AdvancedRocketry with MIT License | 6 votes |
@Nullable @Override public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entityLiving) { RayTraceResult rayTrace = rayTrace(world, (EntityPlayer) entityLiving, false); if(rayTrace != null && rayTrace.typeOfHit == Type.BLOCK) { IBlockState state = world.getBlockState(rayTrace.getBlockPos()); if(state.getBlockHardness(world, rayTrace.getBlockPos()) != -1) { // if(!world.isRemote) { ((EntityPlayerMP)entityLiving).interactionManager.tryHarvestBlock(rayTrace.getBlockPos()); //world.destroyBlock(rayTrace.getBlockPos(), true); } //state.getPlayerRelativeBlockHardness((EntityPlayer)player, world, rayTrace.getBlockPos()); } } posMap.remove(entityLiving); return stack; }
Example #4
Source File: BucketHandler.java From AdvancedRocketry with MIT License | 6 votes |
@SubscribeEvent public void onBucketFill(FillBucketEvent event) { if(event.getTarget() == null || Type.BLOCK != event.getTarget().typeOfHit) return; IBlockState state = event.getWorld().getBlockState(new BlockPos(event.getTarget().getBlockPos())); Block block = state.getBlock(); Item bucket = bucketMap.get(block); if(bucket != null && state.equals(block.getDefaultState())) { event.getWorld().setBlockToAir(new BlockPos(event.getTarget().getBlockPos())); event.setFilledBucket(new ItemStack(bucket)); bucket.hasContainerItem(event.getFilledBucket()); event.setResult(Result.ALLOW); } }
Example #5
Source File: ICoverable.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
static EnumFacing rayTraceCoverableSide(ICoverable coverable, EntityPlayer player) { RayTraceResult result = RayTracer.retraceBlock(coverable.getWorld(), player, coverable.getPos()); if (result == null || result.typeOfHit != Type.BLOCK) { return null; } return traceCoverSide(result); }
Example #6
Source File: ScannerBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
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 #7
Source File: LocalPlayerUtils.java From ForgeHax with MIT License | 5 votes |
public static RayTraceResult getMouseOverBlockTrace() { return Optional.ofNullable(MC.objectMouseOver) .filter(tr -> tr.getBlockPos() != null) // no its not intelliJ .filter( tr -> Type.BLOCK.equals(tr.typeOfHit) || !Material.AIR.equals( getWorld().getBlockState(tr.getBlockPos()).getMaterial())) .orElse(null); }
Example #8
Source File: RayTraceUtils.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
@Nonnull public static RayTraceWrapper getWrappedRayTraceFromEntity(World world, Entity entity, double range) { Vec3d eyesPos = entity.getPositionEyes(1f); Vec3d rangedLookRot = entity.getLook(1f).scale(range); Vec3d lookEndPos = eyesPos.add(rangedLookRot); RayTraceResult result = fi.dy.masa.malilib.util.RayTraceUtils .getRayTraceFromEntity(world, entity, RayTraceFluidHandling.NONE, false, range); double closestVanilla = result.typeOfHit != RayTraceResult.Type.MISS ? result.hitVec.distanceTo(eyesPos) : -1D; AreaSelection area = DataManager.getSelectionManager().getCurrentSelection(); RayTraceWrapper wrapper = null; clearTraceVars(); if (DataManager.getToolMode().getUsesSchematic() == false && area != null) { for (SelectionBox box : area.getAllSubRegionBoxes()) { boolean hitCorner = false; hitCorner |= traceToSelectionBoxCorner(box, Corner.CORNER_1, eyesPos, lookEndPos); hitCorner |= traceToSelectionBoxCorner(box, Corner.CORNER_2, eyesPos, lookEndPos); if (hitCorner == false) { traceToSelectionBoxBody(box, eyesPos, lookEndPos); } } BlockPos origin = area.getExplicitOrigin(); if (origin != null) { traceToOrigin(origin, eyesPos, lookEndPos, HitType.SELECTION_ORIGIN, null); } } if (DataManager.getToolMode().getUsesSchematic()) { for (SchematicPlacement placement : DataManager.getSchematicPlacementManager().getVisibleSchematicPlacements()) { if (placement.isEnabled()) { traceToPlacementBox(placement, eyesPos, lookEndPos); traceToOrigin(placement.getOrigin(), eyesPos, lookEndPos, HitType.PLACEMENT_ORIGIN, placement); } } } double closestDistance = closestVanilla; if (closestBoxDistance >= 0 && (closestVanilla < 0 || closestBoxDistance <= closestVanilla)) { closestDistance = closestBoxDistance; wrapper = closestBox; } // Corners are preferred over box body hits, thus this being after the box check if (closestCornerDistance >= 0 && (closestVanilla < 0 || closestCornerDistance <= closestVanilla)) { closestDistance = closestCornerDistance; wrapper = closestCorner; } // Origins are preferred over everything else if (closestOriginDistance >= 0 && (closestVanilla < 0 || closestOriginDistance <= closestVanilla)) { closestDistance = closestOriginDistance; if (originType == HitType.PLACEMENT_ORIGIN) { wrapper = closestOrigin; } else { wrapper = new RayTraceWrapper(RayTraceWrapper.HitType.SELECTION_ORIGIN); } } clearTraceVars(); if (wrapper == null || closestDistance < 0) { wrapper = new RayTraceWrapper(); } return wrapper; }
Example #9
Source File: LocalPlayerUtils.java From ForgeHax with MIT License | 4 votes |
public static RayTraceResult getViewTrace( Entity entity, Vec3d direction, float partialTicks, double reach, double reachAttack) { if (entity == null) { return null; } Vec3d eyes = entity.getPositionEyes(partialTicks); RayTraceResult trace = entity.rayTrace(reach, partialTicks); Vec3d dir = direction.scale(reach); Vec3d lookDir = eyes.add(dir); double hitDistance = trace == null ? reachAttack : trace.hitVec.distanceTo(eyes); Entity hitEntity = null; Vec3d hitEntityVec = null; for (Entity ent : getWorld() .getEntitiesInAABBexcluding( entity, entity.getEntityBoundingBox().expand(dir.x, dir.y, dir.y).grow(1.D), Predicates.and( EntitySelectors.NOT_SPECTATING, ent -> ent != null && ent.canBeCollidedWith()))) { AxisAlignedBB bb = ent.getEntityBoundingBox().grow(ent.getCollisionBorderSize()); RayTraceResult tr = bb.calculateIntercept(eyes, lookDir); if (bb.contains(eyes)) { if (hitDistance > 0.D) { hitEntity = ent; hitEntityVec = tr == null ? eyes : tr.hitVec; hitDistance = 0.D; } } else if (tr != null) { double dist = eyes.distanceTo(tr.hitVec); if (dist < hitDistance || hitDistance == 0.D) { if (entity.getLowestRidingEntity() == ent.getLowestRidingEntity() && !ent.canRiderInteract()) { if (hitDistance == 0.D) { hitEntity = ent; hitEntityVec = tr.hitVec; } } else { hitEntity = ent; hitEntityVec = tr.hitVec; hitDistance = dist; } } } } if (hitEntity != null && reach > 3.D && eyes.distanceTo(hitEntityVec) > 3.D) { return new RayTraceResult(Type.MISS, hitEntityVec, EnumFacing.UP, new BlockPos(hitEntityVec)); } else if (hitEntity != null && trace == null && hitDistance < reachAttack) { return new RayTraceResult(hitEntity, hitEntityVec); } else { return trace; } }
Example #10
Source File: ItemBasicLaserGun.java From AdvancedRocketry with MIT License | 4 votes |
@Override public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) { World world = player.getEntityWorld(); RayTraceResult rayTrace = rayTraceEntity(world,player); if(rayTrace != null) { rayTrace.entityHit.attackEntityFrom(DamageSource.GENERIC, 1f); if(world.isRemote) LibVulpes.proxy.playSound(world, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, 1, 1f); AdvancedRocketry.proxy.spawnLaser(player, rayTrace.hitVec); player.resetActiveHand(); return; } rayTrace = rayTrace(world, (EntityPlayer) player, false); if(rayTrace == null) return; if(posMap.get(player) != null && !posMap.get(player).equals(rayTrace.getBlockPos())) { player.resetActiveHand(); return; } else if(posMap.get(player) == null && rayTrace.getBlockPos() != null) { posMap.put(player, rayTrace.getBlockPos()); } if(rayTrace.typeOfHit == Type.BLOCK) { IBlockState state = world.getBlockState(rayTrace.getBlockPos()); if(count % 5 == 0 && world.isRemote) LibVulpes.proxy.playSound(world, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, 1, 1f); // AdvancedRocketry.proxy.spawnLaser(player, rayTrace.hitVec); super.onUsingTick(stack, player, count); } }
Example #11
Source File: ItemBasicLaserGun.java From AdvancedRocketry with MIT License | 3 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) { player.setActiveHand(hand); posMap.remove(player); ItemStack stack = player.getHeldItem(hand); //if(true) // return super.onItemRightClick(stack, worldIn, player, hand); World world = player.getEntityWorld(); RayTraceResult rayTrace = rayTraceEntity(world,player); if(rayTrace != null) { rayTrace.entityHit.attackEntityFrom(DamageSource.GENERIC, .5f); if(world.isRemote) LibVulpes.proxy.playSound(worldIn, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.PLAYERS), 1f); return new ActionResult(EnumActionResult.PASS, stack); } rayTrace = rayTrace(world, (EntityPlayer) player, false); if(rayTrace != null && rayTrace.typeOfHit == Type.BLOCK) { IBlockState state = world.getBlockState(rayTrace.getBlockPos()); if(world.isRemote) LibVulpes.proxy.playSound(worldIn, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.PLAYERS), 1f); return new ActionResult(EnumActionResult.PASS, stack); } return new ActionResult(EnumActionResult.PASS, stack); }