use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class EntityThrownTomahawk method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
// Check for proper collision.
Vec3d vec1 = new Vec3d(posX, posY, posZ);
Vec3d vec2 = new Vec3d(posX + motionX, posY + motionY, posZ + motionZ);
RayTraceResult raytraceresult = world.rayTraceBlocks(vec1, vec2, false, true, false);
if (raytraceresult != null && raytraceresult.typeOfHit == Type.BLOCK)
onImpact(raytraceresult);
// Delete if the tomahawk item somehow goes missing, or exists for 10 minutes.
if (thrownStack == null || thrownStack.getItem() == null || ticksExisted > 12000) {
setDead();
if (ticksExisted > 10)
for (int i = 0; i < 15; ++i) world.spawnParticle(EnumParticleTypes.FLAME, posX, posY + 0.5, posZ, 0.01 * SilentGems.random.nextGaussian(), 0.05 * SilentGems.random.nextGaussian(), 0.01 * SilentGems.random.nextGaussian());
}
// Check for player pickup
if (!inAir && ticksExisted > 10) {
for (EntityPlayer player : world.getPlayers(EntityPlayer.class, p -> p.getDistanceSq(posX, posY, posZ) < 2)) {
// SilentGems.logHelper.debug(player.getName() + " is near a tomahawk.");
for (ItemStack stack : PlayerHelper.getNonEmptyStacks(player)) {
if (ToolHelper.areToolsEqual(stack, thrownStack)) {
// SilentGems.logHelper.debug(player.getName() + " picked up the tomahawk.");
ModItems.tomahawk.addAmmo(thrownStack, 1);
world.playSound(null, getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.AMBIENT, 0.5f, 1.5f);
setDead();
}
}
}
}
// Spawn particles to indicate landing spot?
if (!world.isRemote && hasHit && !inAir && ticksExisted % 4 == 0) {
SilentGems.proxy.spawnParticles(EnumModParticles.CHAOS, Color.WHITE, world, posX, posY, posZ, 0.01 * SilentGems.random.nextGaussian(), 0.125, 0.01 * SilentGems.random.nextGaussian());
}
// Spin!
float spinRate = (float) (inAir ? SPIN_RATE : 30 * Math.abs(motionY));
spin += spinRate;
if (spin >= 360)
spin -= 360;
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class SkillAreaMiner method raytraceFromEntity.
private RayTraceResult raytraceFromEntity(World world, Entity player, boolean par3, double range) {
float f = 1.0F;
float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;
double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double) f;
double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double) f;
if (!world.isRemote && player instanceof EntityPlayer)
d1 += 1.62D;
double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) f;
Vec3d vec3 = new Vec3d(d0, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = range;
if (player instanceof EntityPlayerMP) {
d3 = ((EntityPlayerMP) player).interactionManager.getBlockReachDistance();
}
Vec3d vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
return world.rayTraceBlocks(vec3, vec31, par3, !par3, par3);
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class TileChaosFlowerPot method tryPlacePhantomLight.
private boolean tryPlacePhantomLight() {
if (world.isRemote || StackHelper.isEmpty(getFlowerItemStack())) {
return false;
}
Random rand = SilentGems.random;
// final int step = ticksExisted / TRY_LIGHT_DELAY - 1;
// step > 7
final boolean longRange = rand.nextFloat() < 0.5f;
// SilentGems.instance.logHelper.debug(ticksExisted, step, longRange);
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
int dist = 8 + (longRange ? 6 : 0);
// Select a random angle to rotate target position around center.
final int k = longRange ? 8 : 4;
final int angleFactor = rand.nextInt(2 * k);
Vec3d vec = new Vec3d(dist, 0, 0);
// vec = vec.rotateYaw(rand.nextInt(2 * k) / (float) k * (float) Math.PI);
// final int angleFactor = step - (longRange ? 8 : 0);
vec = vec.rotateYaw(angleFactor / (float) k * (float) Math.PI);
x += Math.round(vec.x);
// rand.nextInt(5) - 2;
y += 2;
z += Math.round(vec.z);
MutableBlockPos tryPos = new MutableBlockPos(x, y, z);
// Debug particles
if (SilentGems.proxy.isClientPlayerHoldingDebugItem()) {
// Debug particles: try position
Color debugColor = new Color(0.4f, 0f, 1f);
for (int i = 0; i < 100; ++i) {
SilentGems.proxy.spawnParticles(EnumModParticles.CHAOS, debugColor, world, x + 0.5, y, z + 0.5, 0.005f * rand.nextGaussian(), 0.25f * rand.nextGaussian(), 0.005f * rand.nextGaussian());
}
// Debug particles: ring
for (float f = 0; f < 2 * Math.PI; f += Math.PI / 32) {
Vec3d v = new Vec3d(dist, 0, 0).rotateYaw(f);
SilentGems.proxy.spawnParticles(EnumModParticles.CHAOS, debugColor, world, pos.getX() + 0.5 + v.x, pos.getY() + 0.5, pos.getZ() + 0.5 + v.z, 0, 0, 0);
}
}
if (canPlacePhantomLightAt(tryPos)) {
placePhantomLightAt(tryPos);
return true;
}
for (int ty = y + 1; ty > y - 2; --ty) {
for (int tx = x - 1; tx < x + 2; ++tx) {
for (int tz = z - 1; tz < z + 2; ++tz) {
tryPos.setPos(tx, ty, tz);
if (canPlacePhantomLightAt(tryPos)) {
placePhantomLightAt(tryPos);
return true;
}
}
}
}
return false;
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class ChaosUtil method canSee.
/**
* Determines if the target entity can be "seen" from the source position. Ignores liquids and blocks with no
* collision.
*
* @return True if there is a clear line of sight, false otherwise.
*/
public static boolean canSee(World world, BlockPos source, Entity target) {
Vec3d startPos = new Vec3d(source.getX() + 0.5, source.getY() + 0.5, source.getZ() + 0.5);
Vec3d targetPos = target.getPositionVector().addVector(0, target.height / 2, 0);
RayTraceResult result = world.rayTraceBlocks(startPos, targetPos, false, true, false);
return result == null || result.getBlockPos().equals(target.getPosition().up((int) (target.height / 2)));
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class ChaosUtil method canSee.
/**
* Determine if the target position can be "seen" from the source position. Ignores liquids and blocks with no
* collision.
*
* @return True if there is a clear line of sight, false otherwise.
*/
public static boolean canSee(World world, BlockPos source, BlockPos target) {
Vec3d startPos = new Vec3d(source.getX() + 0.5, source.getY() + 0.5, source.getZ() + 0.5);
Vec3d targetPos = new Vec3d(target.getX() + 0.5, target.getY() + 0.5, target.getZ() + 0.5);
// Move start position ahead a bit so it doesn't collide with the source block!
Vec3d direction = targetPos.subtract(startPos).normalize();
startPos = startPos.add(direction);
RayTraceResult result = world.rayTraceBlocks(startPos, targetPos, false, true, false);
return result == null || result.getBlockPos().equals(target);
}
Aggregations