Java Code Examples for net.minecraft.util.EnumFacing#getFacingFromVector()
The following examples show how to use
net.minecraft.util.EnumFacing#getFacingFromVector() .
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: TileEntitySignalBase.java From Signals with GNU General Public License v3.0 | 6 votes |
public void setLampStatus(EnumLampStatus lampStatus){ IBlockState state = getBlockState(); if(state.getPropertyKeys().contains(BlockSignalBase.LAMP_STATUS) && state.getValue(BlockSignalBase.LAMP_STATUS) != lampStatus) { getWorld().setBlockState(getPos(), state.withProperty(BlockSignalBase.LAMP_STATUS, lampStatus)); if(lampStatus == EnumLampStatus.GREEN) { //Push carts when they're standing still or going backwards. List<EntityMinecart> neighborMinecarts = getNeighborMinecarts(); for(EntityMinecart cart : neighborMinecarts) { if(new Vec3d(cart.motionX, cart.motionY, cart.motionZ).lengthVector() < 0.01 || EnumFacing.getFacingFromVector((float)cart.motionX, 0, (float)cart.motionZ) == getFacing()) { cart.motionX += getFacing().getFrontOffsetX() * 0.1; cart.motionZ += getFacing().getFrontOffsetZ() * 0.1; } else if(EnumFacing.getFacingFromVector((float)cart.motionX, 0, (float)cart.motionZ) == getFacing().getOpposite()) { //Reverse the cart if going backwards into a signal. cart.motionX *= -1; cart.motionY *= -1; cart.motionZ *= -1; } } } } }
Example 2
Source File: WrapperEnumFacing.java From ClientBase with MIT License | 4 votes |
public static WrapperEnumFacing getFacingFromVector(float var0, float var1, float var2) { return new WrapperEnumFacing(EnumFacing.getFacingFromVector(var0, var1, var2)); }
Example 3
Source File: RayTrace.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
/** * Credits to Masa on discord for providing the base of the code. I heavily modified it. * This raytracer will precisely trace entities and blocks (including misses) without snapping to any grid. * * @return The RaytraceResult. */ @Nonnull public RayTraceResult trace() { Vec3d lookVec = origin.add(slope.normalize().scale(range)); RayTraceResult entityResult = null; RayTraceResult blockResult = null;// world.rayTraceBlocks(origin, lookVec, false, ignoreBlocksWithoutBoundingBoxes, returnLastUncollidableBlock); if (!skipEntities) { Entity targetEntity = null; RayTraceResult entityTrace = null; AxisAlignedBB bb = new AxisAlignedBB(origin.x, origin.y, origin.z, lookVec.x, lookVec.y, lookVec.z); List<Entity> list = world.getEntitiesWithinAABB(Entity.class, bb.grow(range, range, range), input -> { if (predicateEntity == null) return true; else return predicateEntity.test(input); }); double closest = 0.0D; for (Entity entity : list) { if (entity == null) continue; bb = entity.getEntityBoundingBox(); RayTraceResult traceTmp = bb.calculateIntercept(lookVec, origin); if (traceTmp != null) { double tmp = origin.distanceTo(traceTmp.hitVec); if (tmp < closest || closest == 0.0D) { targetEntity = entity; entityTrace = traceTmp; closest = tmp; } } } if (targetEntity != null) entityResult = new RayTraceResult(targetEntity, entityTrace.hitVec); } if (!skipBlocks) blockResult = traceBlock(origin, lookVec); if (blockResult == null) blockResult = new RayTraceResult( RayTraceResult.Type.BLOCK, lookVec, EnumFacing.getFacingFromVector((float) lookVec.x, (float) lookVec.y, (float) lookVec.z), new BlockPos(lookVec)); return (entityResult != null && origin.distanceTo(entityResult.hitVec) < origin.distanceTo(blockResult.hitVec)) ? entityResult : blockResult; }
Example 4
Source File: ModuleEffectPhase.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@Override @SideOnly(Side.CLIENT) public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) { EnumFacing faceHit = spell.getFaceHit(); Set<BlockPos> blockSet = spell.getDataWithFallback(SpellData.DefaultKeys.BLOCK_SET, new BlockSet(new HashSet<>())).getBlockSet(); Map<BlockPos, IBlockState> blockStateCache = spell.getDataWithFallback(SpellData.DefaultKeys.BLOCKSTATE_CACHE, new BlockStateCache(new HashMap<>())).getBlockStateCache(); HashMap<BlockPos, IBlockState> tmpCache = new HashMap<>(blockStateCache); double duration = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 20; PhasedBlockRenderer.addPhase(world, blockSet, (int) duration); if (faceHit != null) { for (Map.Entry<BlockPos, IBlockState> entry : tmpCache.entrySet()) { IBlockState thisState = entry.getValue(); if (thisState.getBlock() != ModBlocks.FAKE_AIR) continue; ParticleBuilder glitter2 = new ParticleBuilder(10); glitter2.setRenderNormalLayer(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED)); glitter2.disableRandom(); ParticleSpawner.spawn(glitter2, world, new StaticInterp<>(new Vec3d(entry.getKey()).add(0.5, 0.5, 0.5)), 5, (int) duration, (aFloat, build) -> { build.setColor(Color.CYAN); //build.setAlphaFunction(new InterpFloatInOut(1f, 0.1f)); build.setAlpha(RandUtil.nextFloat(0.05f, 0.2f)); build.setPositionOffset(new Vec3d( RandUtil.nextDouble(-0.5, 0.5), RandUtil.nextDouble(-0.5, 0.5), RandUtil.nextDouble(-0.5, 0.5) )); build.setMotion(new Vec3d( RandUtil.nextDouble(-0.001, 0.001), RandUtil.nextDouble(-0.001, 0.001), RandUtil.nextDouble(-0.001, 0.001) )); build.setLifetime(RandUtil.nextInt(20, 40)); build.setScaleFunction(new InterpFloatInOut(0.9f, 0.9f)); build.setScale(RandUtil.nextFloat(0.1f, 0.3f)); }); BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos(entry.getKey()); for (EnumFacing facing : EnumFacing.VALUES) { mutable.move(facing); IBlockState adjState; if (!blockStateCache.containsKey(mutable)) { adjState = world.getBlockState(mutable); blockStateCache.put(mutable.toImmutable(), adjState); } else adjState = blockStateCache.get(mutable); if (adjState.getBlock() != Blocks.AIR && adjState.getBlock() != ModBlocks.FAKE_AIR) { Vec3d directionOffsetVec = new Vec3d(facing.getOpposite().getDirectionVec()).scale(0.5); Vec3d adjPos = new Vec3d(mutable).add(0.5, 0.5, 0.5).add(directionOffsetVec); for (EnumFacing subFacing : getPerpendicularFacings(facing)) { mutable.move(subFacing); IBlockState subState; if (!blockStateCache.containsKey(mutable)) { subState = world.getBlockState(mutable); blockStateCache.put(mutable.toImmutable(), subState); } else subState = blockStateCache.get(mutable); if (BlockUtils.isAnyAir(subState)) { Vec3d subPos = new Vec3d(mutable).add(0.5, 0.5, 0.5).add(directionOffsetVec); Vec3d midPointVec = new Vec3d( (adjPos.x + subPos.x) / 2.0, (adjPos.y + subPos.y) / 2.0, (adjPos.z + subPos.z) / 2.0); Vec3d sub = subPos.subtract(adjPos); EnumFacing adjSubFacing = EnumFacing.getFacingFromVector((float) sub.x, (float) sub.y, (float) sub.z); Vec3d cross = new Vec3d(adjSubFacing.getDirectionVec()).crossProduct(new Vec3d(facing.getDirectionVec())).normalize().scale(0.5); ParticleBuilder glitter = new ParticleBuilder(10); glitter.setRenderNormalLayer(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED)); glitter.disableRandom(); ParticleSpawner.spawn(glitter, world, new StaticInterp<>(midPointVec), 50, (int) duration, (aFloat, build) -> { build.setColor(Color.CYAN); //build.setAlphaFunction(new InterpFloatInOut(1f, 0.1f)); build.setAlpha(RandUtil.nextFloat(0.3f, 0.7f)); build.setPositionOffset(cross.scale(RandUtil.nextFloat(-1, 1))); build.setLifetime(RandUtil.nextInt(20, 40)); build.setScaleFunction(new InterpFloatInOut(0.9f, 0.9f)); build.setScale(RandUtil.nextFloat(0.2f, 0.5f)); }); } mutable.move(subFacing.getOpposite()); } } mutable.move(facing.getOpposite()); } } } }