Java Code Examples for net.minecraft.util.Vec3#rotateAroundY()

The following examples show how to use net.minecraft.util.Vec3#rotateAroundY() . 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: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SubscribeEvent
public void entityHurtEvent(LivingHurtEvent event) {
	if (!EtFuturum.enableDmgIndicator)
		return;
	int amount = MathHelper.floor_float(Math.min(event.entityLiving.getHealth(), event.ammount) / 2F);
	if (amount <= 0)
		return;

	// If the attacker is a player spawn the hearts aligned and facing it
	if (event.source instanceof EntityDamageSource) {
		EntityDamageSource src = (EntityDamageSource) event.source;
		Entity attacker = src.getSourceOfDamage();
		if (attacker instanceof EntityPlayer && !(attacker instanceof FakePlayer)) {
			EntityPlayer player = (EntityPlayer) attacker;
			Vec3 look = player.getLookVec();
			look.rotateAroundY((float) Math.PI / 2);
			for (int i = 0; i < amount; i++) {
				double x = event.entityLiving.posX - amount * 0.35 * look.xCoord / 2 + i * 0.35 * look.xCoord;
				double y = event.entityLiving.posY + 1.5 + event.entityLiving.worldObj.rand.nextGaussian() * 0.05;
				double z = event.entityLiving.posZ - amount * 0.35 * look.zCoord / 2 + i * 0.35 * look.zCoord;
				EtFuturum.networkWrapper.sendToAllAround(new BlackHeartParticlesMessage(x, y, z), new TargetPoint(player.worldObj.provider.dimensionId, x, y, z, 64));
			}
		}
	}
}
 
Example 2
Source File: EntityShip.java    From archimedes-ships with MIT License 6 votes vote down vote up
public void alignToGrid()
{
	rotationYaw = Math.round(rotationYaw / 90F) * 90F;
	rotationPitch = 0F;
	
	Vec3 vec = Vec3.createVectorHelper(-shipChunk.getCenterX(), -shipChunk.minY(), -shipChunk.getCenterZ());
	vec.rotateAroundY((float) Math.toRadians(rotationYaw));
	
	int ix = MathHelperMod.round_double(vec.xCoord + posX);
	int iy = MathHelperMod.round_double(vec.yCoord + posY);
	int iz = MathHelperMod.round_double(vec.zCoord + posZ);

	posX = ix - vec.xCoord;
	posY = iy - vec.yCoord;
	posZ = iz - vec.zCoord;
	
	motionX = motionY = motionZ = 0D;
}
 
Example 3
Source File: ClientProxy.java    From SimplyJetpacks with MIT License 5 votes vote down vote up
@Override
public void showJetpackParticles(World world, EntityLivingBase wearer, ParticleType particle) {
    if (mc.gameSettings.particleSetting == 0 || mc.gameSettings.particleSetting == 1 && mc.theWorld.getTotalWorldTime() % 4L == 0) {
        Vec3 userPos = Vec3.createVectorHelper(wearer.posX, wearer.posY, wearer.posZ);
        
        if (!wearer.equals(mc.thePlayer)) {
            userPos = userPos.addVector(0, 1.6D, 0);
        }
        
        Random rand = MathHelper.RANDOM;
        
        Vec3 vLeft = Vec3.createVectorHelper(-0.28D, -0.95D, -0.38D);
        vLeft.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
        
        Vec3 vRight = Vec3.createVectorHelper(0.28D, -0.95D, -0.38D);
        vRight.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
        
        Vec3 vCenter = Vec3.createVectorHelper((rand.nextFloat() - 0.5F) * 0.25F, -0.95D, -0.38D);
        vCenter.rotateAroundY((float) Math.toRadians(-wearer.renderYawOffset));
        
        vLeft = vLeft.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
        vRight = vRight.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
        vCenter = vCenter.addVector(-wearer.motionX * 0.2D, -wearer.motionY * 0.2D, -wearer.motionZ * 0.2D);
        
        Vec3 v = userPos.addVector(vLeft.xCoord, vLeft.yCoord, vLeft.zCoord);
        ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
        
        v = userPos.addVector(vRight.xCoord, vRight.yCoord, vRight.zCoord);
        ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
        
        v = userPos.addVector(vCenter.xCoord, vCenter.yCoord, vCenter.zCoord);
        ParticleUtils.spawnParticle(particle, world, v.xCoord, v.yCoord, v.zCoord, rand.nextDouble() * 0.05D - 0.025D, -0.2D, rand.nextDouble() * 0.05D - 0.025D);
    }
}
 
Example 4
Source File: EntityShip.java    From archimedes-ships with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
protected void spawnParticles(double horvel)
{
	/*if (isInWater() && horvel > 0.1625D)
	{
		/*double yaw = Math.toRadians(rotationYaw);
		double cosyaw = Math.cos(yaw);
		double sinyaw = Math.sin(yaw);*//*
										
										for (int j = 0; j < 1D + horvel * 60D; j++)
										{
										worldObj.spawnParticle("splash", posX + (rand.nextFloat() - 0.5F) * width, posY, posZ + (rand.nextFloat() - 0.5F) * width, motionX, motionY + 1F, motionZ);
										}
										for (int j = 0; j < 1D + horvel * 20D; j++)
										{
										worldObj.spawnParticle("bubble", posX + rand.nextFloat() - 0.5F, posY - 0.2D, posZ + rand.nextFloat() - 0.5F, 0D, 0D, 0D);
										}
										}*/
	if (capabilities.getEngines() != null)
	{
		Vec3 vec = Vec3.createVectorHelper(0d, 0d, 0d);
		float yaw = (float) Math.toRadians(rotationYaw);
		for (TileEntityEngine engine : capabilities.getEngines())
		{
			if (engine.isRunning())
			{
				vec.xCoord = engine.xCoord - shipChunk.getCenterX() + 0.5f;
				vec.yCoord = engine.yCoord;
				vec.zCoord = engine.zCoord - shipChunk.getCenterZ() + 0.5f;
				vec.rotateAroundY(yaw);
				worldObj.spawnParticle("smoke", posX + vec.xCoord, posY + vec.yCoord + 1d, posZ + vec.zCoord, 0d, 0d, 0d);
			}
		}
	}
}
 
Example 5
Source File: EntityShip.java    From archimedes-ships with MIT License 5 votes vote down vote up
public void driftToGrid()
{
	if( Math.abs( motionYaw ) < BASE_TURN_SPEED  * 0.25f )
	{
		float targetYaw = Math.round(rotationYaw / 90F) * 90F - rotationYaw;
		float targetDir = Math.min( Math.abs( targetYaw ), BASE_TURN_SPEED * 0.25f ) * Math.signum( targetYaw );
		motionYaw = targetDir;
	}
	
	if( Math.abs( motionX ) < BASE_FORWARD_SPEED * 0.25f && Math.abs( motionZ ) < BASE_FORWARD_SPEED * 0.25f )
	{
		Vec3 size = Vec3.createVectorHelper(shipChunk.getSizeX(), shipChunk.getSizeY(), shipChunk.getSizeZ());
		size.rotateAroundY((float) Math.toRadians(rotationYaw));
		
		Vec3 target = Vec3.createVectorHelper(getBlockAt(posX, size.xCoord), getBlockAt(posY, size.yCoord), getBlockAt(posZ, size.zCoord));
		double ix = target.xCoord - posX;
		double iy = target.yCoord - posY;
		double iz = target.zCoord - posZ;

		double targetX = Math.min( Math.abs( ix ), BASE_FORWARD_SPEED * 0.25f ) * Math.signum( ix );
		double targetY = Math.min( Math.abs( iy ), BASE_FORWARD_SPEED * 0.25f ) * Math.signum( iy );
		double targetZ = Math.min( Math.abs( iz ), BASE_FORWARD_SPEED * 0.25f ) * Math.signum( iz );

		motionX = targetX;
		motionZ = targetZ;
	}
}
 
Example 6
Source File: EntityParachute.java    From archimedes-ships with MIT License 5 votes vote down vote up
public EntityParachute(World world, EntityShip ship, int x, int y, int z)
{
	this(world);
	Vec3 vec = Vec3.createVectorHelper(x - ship.getShipChunk().getCenterX(), y - ship.getShipChunk().minY(), z - ship.getShipChunk().getCenterZ());
	vec.rotateAroundY((float) Math.toRadians(ship.rotationYaw));
	
	setLocationAndAngles(ship.posX + vec.xCoord, ship.posY + vec.yCoord - 2D, ship.posZ + vec.zCoord, 0F, 0F);
	motionX = ship.motionX;
	motionY = ship.motionY;
	motionZ = ship.motionZ;
}
 
Example 7
Source File: EntityShip.java    From archimedes-ships with MIT License 4 votes vote down vote up
private boolean handlePlayerControl()
{
	boolean underControl = false;

	if (riddenByEntity instanceof EntityLivingBase)
	{
		double throttle = ((EntityLivingBase) riddenByEntity).moveForward;
		if (isFlying())
		{
			throttle *= 0.5D;
		}
		if( throttle > 0.0D ) underControl = true;
		
		if (ArchimedesShipMod.instance.modConfig.shipControlType == ArchimedesConfig.CONTROL_TYPE_ARCHIMEDES)
		{
			Vec3 vec = Vec3.createVectorHelper(riddenByEntity.motionX, 0D, riddenByEntity.motionZ);
			vec.rotateAroundY((float) Math.toRadians(riddenByEntity.rotationYaw));
			
			double steer = ((EntityLivingBase) riddenByEntity).moveStrafing;
			if( steer != 0.0D ) underControl = true;
			
			motionYaw += steer * BASE_TURN_SPEED * capabilities.getPoweredRotationMult() * ArchimedesShipMod.instance.modConfig.turnSpeed;
			
			float yaw = (float) Math.toRadians(180F - rotationYaw + frontDirection * 90F);
			vec.xCoord = motionX;
			vec.zCoord = motionZ;
			vec.rotateAroundY(yaw);
			vec.xCoord *= 0.9D;
			vec.zCoord -= throttle * BASE_FORWARD_SPEED * capabilities.getPoweredSpeedMult();
			vec.rotateAroundY(-yaw);
			
			motionX = vec.xCoord;
			motionZ = vec.zCoord;
		} else if (ArchimedesShipMod.instance.modConfig.shipControlType == ArchimedesConfig.CONTROL_TYPE_VANILLA)
		{
			if (throttle > 0.0D)
			{
				double dsin = -Math.sin(Math.toRadians(riddenByEntity.rotationYaw));
				double dcos = Math.cos(Math.toRadians(riddenByEntity.rotationYaw));
				motionX += dsin * BASE_FORWARD_SPEED * capabilities.speedMultiplier;
				motionZ += dcos * BASE_FORWARD_SPEED * capabilities.speedMultiplier;
			}
		}
	}
	
	if (controller.getShipControl() != 0)
	{
		if (controller.getShipControl() == 4)
		{
			alignToGrid();
		} else if (isBraking())
		{
			motionX *= capabilities.brakeMult;
			motionZ *= capabilities.brakeMult;
			if (isFlying())
			{
				motionY *= capabilities.brakeMult;
			}
		} else if (controller.getShipControl() < 3 && capabilities.canFly())
		{
			int i;
			if (controller.getShipControl() == 2)
			{
				isFlying = true;
				i = 1;
			} else
			{
				i = -1;
			}
			motionY += i * BASE_LIFT_SPEED * capabilities.getPoweredLiftMult();
		}
		underControl = true;
	}
	return underControl;
}
 
Example 8
Source File: EntityShip.java    From archimedes-ships with MIT License 4 votes vote down vote up
public void updateRiderPosition(Entity entity, int seatx, int seaty, int seatz, int flags)
{
	if (entity != null)
	{
		float yaw = (float) Math.toRadians(rotationYaw);
		float pitch = (float) Math.toRadians(rotationPitch);
		
		int x1 = seatx, y1 = seaty, z1 = seatz;
		if ((flags & 1) == 1)
		{
			if (frontDirection == 0)
			{
				z1 -= 1;
			} else if (frontDirection == 1)
			{
				x1 += 1;
			} else if (frontDirection == 2)
			{
				z1 += 1;
			} else if (frontDirection == 3)
			{
				x1 -= 1;
			}
			
			Block block = shipChunk.getBlock(x1, MathHelper.floor_double(y1 + getMountedYOffset() + entity.getYOffset()), z1);
			if (block.isOpaqueCube())
			{
				x1 = seatx;
				y1 = seaty;
				z1 = seatz;
			}
		}
		
		double yoff = (flags & 2) == 2 ? 0d : getMountedYOffset();
		Vec3 vec = Vec3.createVectorHelper(x1 - shipChunk.getCenterX() + 0.5d, y1 - shipChunk.minY() + yoff, z1 - shipChunk.getCenterZ() + 0.5d);
		switch (frontDirection)
		{
		case 0:
			vec.rotateAroundZ(-pitch);
			break;
		case 1:
			vec.rotateAroundX(pitch);
			break;
		case 2:
			vec.rotateAroundZ(pitch);
			break;
		case 3:
			vec.rotateAroundX(-pitch);
			break;
		}
		vec.rotateAroundY(yaw);
		
		entity.setPosition(posX + vec.xCoord, posY + vec.yCoord + entity.getYOffset(), posZ + vec.zCoord);
	}
}
 
Example 9
Source File: ChunkDisassembler.java    From archimedes-ships with MIT License 4 votes vote down vote up
public boolean canDisassemble()
{
	if (overwrite)
	{
		return true;
	}
	World world = ship.worldObj;
	MobileChunk chunk = ship.getShipChunk();
	float yaw = Math.round(ship.rotationYaw / 90F) * 90F;
	yaw = (float) Math.toRadians(yaw);
	
	float ox = -chunk.getCenterX();
	float oy = -chunk.minY(); //Created the normal way, through a VehicleFiller, this value will always be 0.
	float oz = -chunk.getCenterZ();
	
	Vec3 vec = Vec3.createVectorHelper(0D, 0D, 0D);
	Block block;
	int ix, iy, iz;
	for (int i = chunk.minX(); i < chunk.maxX(); i++)
	{
		for (int j = chunk.minY(); j < chunk.maxY(); j++)
		{
			for (int k = chunk.minZ(); k < chunk.maxZ(); k++)
			{
				if (chunk.isAirBlock(i, j, k)) continue;
				vec.xCoord = i + ox;
				vec.yCoord = j + oy;
				vec.zCoord = k + oz;
				vec.rotateAroundY(yaw);
				
				ix = MathHelperMod.round_double(vec.xCoord + ship.posX);
				iy = MathHelperMod.round_double(vec.yCoord + ship.posY);
				iz = MathHelperMod.round_double(vec.zCoord + ship.posZ);
				
				block = world.getBlock(ix, iy, iz);
				if (block != null && !block.isAir(world, ix, iy, iz) && !block.getMaterial().isLiquid() && !ArchimedesShipMod.instance.modConfig.overwritableBlocks.contains(block))
				{
					return false;
				}
			}
		}
	}
	return true;
}