Search in sources :

Example 1 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Bookshelf by Darkhax-Minecraft.

the class SerializerVec3d method read.

@Override
public Vector3d read(INBT nbt) {
    if (nbt instanceof CompoundNBT) {
        final CompoundNBT tag = (CompoundNBT) nbt;
        final double x = tag.getDouble("x");
        final double y = tag.getDouble("y");
        final double z = tag.getDouble("z");
        return new Vector3d(x, y, z);
    }
    throw new IllegalArgumentException("Expected NBT to be a compound tag. Class was " + nbt.getClass() + " with ID " + nbt.getId() + " instead.");
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Vector3d(net.minecraft.util.math.vector.Vector3d)

Example 2 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Bookshelf by Darkhax-Minecraft.

the class EntityUtils method pushTowards.

/**
 * Pushes an Entity towards a BlockPos.
 *
 * @param entityToMove The entity that you want to push.
 * @param pos The BlockPos to push the entity towards.
 * @param force The amount of force to push the entity with.
 */
public static void pushTowards(Entity entityToMove, BlockPos pos, double force) {
    final BlockPos entityPos = entityToMove.blockPosition();
    final double distanceX = (double) pos.getX() - entityPos.getX();
    final double distanceY = (double) pos.getY() - entityPos.getY();
    final double distanceZ = (double) pos.getZ() - entityPos.getZ();
    final double distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ);
    if (distance > 0) {
        entityToMove.setDeltaMovement(new Vector3d(distanceX / distance * force, distanceY / distance * force, distanceZ / distance * force));
    }
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Bookshelf by Darkhax-Minecraft.

the class EntityUtils method pushTowardsDirection.

/**
 * Creates a Vector3d that represents the additional motion that would be needed to push an
 * entity towards a destination.
 *
 * @param entityToMove The entity to push.
 * @param direction The direction to push the entity.
 * @param force The amount of force to use.
 */
public static void pushTowardsDirection(Entity entityToMove, Direction direction, double force) {
    final BlockPos entityPos = entityToMove.blockPosition();
    final BlockPos destination = entityToMove.blockPosition().relative(direction.getOpposite(), 1);
    final double distanceX = (double) destination.getX() - entityPos.getX();
    final double distanceY = (double) destination.getY() - entityPos.getY();
    final double distanceZ = (double) destination.getZ() - entityPos.getZ();
    final double distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ);
    if (distance > 0) {
        entityToMove.setDeltaMovement(new Vector3d(distanceX / distance * force, distanceY / distance * force, distanceZ / distance * force));
    }
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Bookshelf by Darkhax-Minecraft.

the class EntityUtils method rayTrace.

/**
 * Performs a ray trace for the look vector of an entity.
 *
 * @param entity The entity to perform a ray trace on.
 * @param length The distance to cast the rays.
 * @param blockMode The mode used when detecting blocks.
 * @param fluidMode The mode used when detecting fluids.
 * @return An object containing the results of the ray trace.
 */
public static RayTraceResult rayTrace(LivingEntity entity, double length, BlockMode blockMode, FluidMode fluidMode) {
    final Vector3d startingPosition = new Vector3d(entity.getX(), entity.getY() + entity.getEyeHeight(), entity.getZ());
    final Vector3d lookVector = entity.getLookAngle();
    final Vector3d endingPosition = startingPosition.add(lookVector.x * length, lookVector.y * length, lookVector.z * length);
    return entity.level.clip(new RayTraceContext(startingPosition, endingPosition, blockMode, fluidMode, entity));
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceContext(net.minecraft.util.math.RayTraceContext)

Example 5 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Bookshelf by Darkhax-Minecraft.

the class CheckEnergy method test.

@Override
public boolean test(LootContext ctx) {
    final Vector3d pos = ctx.getParamOrNull(LootParameters.ORIGIN);
    if (pos != null) {
        final TileEntity tile = ctx.getLevel().getBlockEntity(new BlockPos(pos));
        if (tile != null) {
            final LazyOptional<IEnergyStorage> energyCap = tile.getCapability(CapabilityEnergy.ENERGY);
            final IEnergyStorage energyStorage = energyCap.orElse(null);
            if (energyStorage != null) {
                return this.energy.matches(energyStorage.getEnergyStored());
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Vector3d (net.minecraft.util.math.vector.Vector3d)19 BlockPos (net.minecraft.util.math.BlockPos)7 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 ItemStack (net.minecraft.item.ItemStack)4 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)4 Nullable (javax.annotation.Nullable)3 BlockState (net.minecraft.block.BlockState)3 Entity (net.minecraft.entity.Entity)3 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)3 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)2 Nonnull (javax.annotation.Nonnull)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Direction (net.minecraft.util.Direction)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 RayTraceContext (net.minecraft.util.math.RayTraceContext)2 Matrix4f (net.minecraft.util.math.vector.Matrix4f)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 BlockBPMultipart (com.bluepowermod.block.BlockBPMultipart)1