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.");
}
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));
}
}
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));
}
}
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));
}
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;
}
Aggregations