use of com.builtbroken.mc.imp.transform.rotation.EulerAngle in project Engine by VoltzEngine-Project.
the class ModelStateJsonProcessor method process.
@Override
public IRenderState process(JsonObject renderStateObject, String stateID, String globalRenderType, String subRenderType) {
ModelState renderState;
//Data
String modelID = null;
Pos offset = null;
Pos scale = null;
EulerAngle rotation = null;
//Load model ID, child objects may or may not contain this
if (renderStateObject.has("modelID")) {
modelID = renderStateObject.get("modelID").getAsString();
}
//Loads position offset
if (renderStateObject.has("offset")) {
offset = JsonConverterPos.fromJson(renderStateObject.get("offset"));
if (offset == null) {
throw new IllegalArgumentException("Unknown value type for offset " + renderStateObject.get("offset"));
}
}
//Loads scale value
if (renderStateObject.has("scale")) {
scale = JsonConverterPos.fromJson(renderStateObject.get("scale"));
if (scale == null) {
throw new IllegalArgumentException("Unknown value type for scale " + renderStateObject.get("scale"));
}
}
//Loads rotations
if (renderStateObject.has("rotation")) {
JsonObject rotationObject = renderStateObject.get("rotation").getAsJsonObject();
double yaw = 0;
double pitch = 0;
double roll = 0;
if (rotationObject.has("yaw")) {
yaw = rotationObject.getAsJsonPrimitive("yaw").getAsDouble();
}
if (rotationObject.has("pitch")) {
pitch = rotationObject.getAsJsonPrimitive("pitch").getAsDouble();
}
if (rotationObject.has("roll")) {
roll = rotationObject.getAsJsonPrimitive("roll").getAsDouble();
}
rotation = new EulerAngle(yaw, pitch, roll);
}
//Creates state object
if (globalRenderType.equalsIgnoreCase("tile")) {
renderState = new TileState(stateID, modelID, offset, scale, rotation);
} else {
renderState = new ModelState(stateID, modelID, offset, scale, rotation);
}
if (renderStateObject.has("renderOnlyParts")) {
renderState.renderOnlyParts = renderStateObject.get("renderOnlyParts").getAsBoolean();
}
if (renderStateObject.has("renderParent")) {
renderState.renderParent = renderStateObject.get("renderParent").getAsBoolean();
}
//Loads parts to render if all is not selected
if (renderStateObject.has("parts")) {
String parts = renderStateObject.get("parts").getAsString();
if (!parts.equals("all")) {
renderState.parts = parts.split(",");
}
}
return renderState;
}
use of com.builtbroken.mc.imp.transform.rotation.EulerAngle in project ICBM-Classic by BuiltBrokenModding.
the class BlastRedmatter method affectEntity.
/**
* Makes an entity get affected by Red Matter.
*
* @Return True if explosion happened
*/
public boolean affectEntity(float radius, Entity entity, boolean doExplosion) {
//Ignore players that are in creative mode or can't be harmed
if (entity instanceof EntityPlayer && (((EntityPlayer) entity).capabilities.isCreativeMode || ((EntityPlayer) entity).capabilities.disableDamage)) {
return false;
}
//Ignore self
if (entity == this.controller) {
return false;
}
//Ignore entities that mark themselves are ignorable
if (entity instanceof IExplosiveIgnore) {
if (((IExplosiveIgnore) entity).canIgnore(this)) {
return false;
}
}
//Calculate different from center
double xDifference = entity.posX - position.xi() + 0.5;
double yDifference = entity.posY - position.yi() + 0.5;
double zDifference = entity.posZ - position.zi() + 0.5;
/** The percentage of the closeness of the entity. */
double xPercentage = 1 - (xDifference / radius);
double yPercentage = 1 - (yDifference / radius);
double zPercentage = 1 - (zDifference / radius);
double distancePercentage = this.position.distance(entity) / radius;
Pos entityPosition = new Pos(entity);
Pos centeredPosition = entityPosition.subtract(this.position);
centeredPosition = (Pos) centeredPosition.transform(new EulerAngle(1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random()));
Location newPosition = this.position.add(centeredPosition);
// Orbit Velocity
entity.addVelocity(newPosition.x() - entityPosition.x(), 0, newPosition.z() - entityPosition.z());
// Gravity Velocity (0.015 is barely enough to overcome y gravity so do not lower)
entity.addVelocity(-xDifference * 0.015 * xPercentage, -yDifference * 0.015 * yPercentage, -zDifference * 0.015 * zPercentage);
boolean explosionCreated = false;
if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < (ENTITY_DESTROY_RADIUS * (getRadius() / NORMAL_RADIUS))) {
if (entity instanceof EntityExplosion) {
if (((EntityExplosion) entity).getBlast() instanceof BlastAntimatter) {
if (doAudio) {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}
if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
entity.setDead();
return explosionCreated;
}
} else if (((EntityExplosion) entity).getBlast() instanceof BlastRedmatter) {
//https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
//We are going to merge both blasts together
double sizeA = this.getRadius();
sizeA = sizeA * sizeA * sizeA;
double sizeB = ((EntityExplosion) entity).getBlast().getRadius();
sizeB = sizeB * sizeB * sizeB;
float radiusNew = (float) Math.cbrt(sizeA + sizeB);
//Average out timer
this.callCount = (callCount + ((EntityExplosion) entity).getBlast().callCount) / 2;
//Destroy current instance
this.isAlive = false;
this.controller.setDead();
//Create new to avoid doing packet syncing
new BlastRedmatter(world(), entity, position.x(), position.y(), position.z(), radiusNew).explode();
}
//Kill explosion entity
((EntityExplosion) entity).getBlast().isAlive = false;
//Kill entity in the center of the ball
entity.setDead();
} else if (entity instanceof EntityExplosive) {
((EntityExplosive) entity).explode();
} else if (entity instanceof EntityLiving) {
((EntityLiving) entity).attackEntityFrom(DamageSource.outOfWorld, 99999999);
} else {
//Kill entity in the center of the ball
entity.setDead();
}
}
return explosionCreated;
}
use of com.builtbroken.mc.imp.transform.rotation.EulerAngle in project ICBM-Classic by BuiltBrokenModding.
the class RenderEntityBlock method doRenderGravityBlock.
/** The actual render method that is used in doRender */
public void doRenderGravityBlock(EntityFlyingBlock entity, double x, double y, double z, float par8, float par9) {
Block block = entity.block;
if (block == null || block.getMaterial() == Material.air) {
block = Blocks.stone;
}
GL11.glPushMatrix();
try {
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
RenderUtility.setTerrainTexture();
EulerAngle rotation = new EulerAngle(entity.rotationYaw, entity.rotationPitch);
Pos translation = rotation.toPos();
GL11.glTranslated(translation.x(), translation.y(), translation.z());
//GL11.glDisable(GL11.GL_LIGHTING);
GL11.glRotatef(entity.rotationPitch, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(entity.rotationYaw, 0.0F, 1.0F, 0.0F);
if (block.getRenderType() != 0) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
try {
tessellator.setTranslation((-MathHelper.floor_double(entity.posX)) - 0.5F, (-MathHelper.floor_double(entity.posY)) - 0.5F, (-MathHelper.floor_double(entity.posZ)) - 0.5F);
RenderUtility.getBlockRenderer().renderBlockByRenderType(block, MathHelper.floor_double(entity.posX), MathHelper.floor_double(entity.posY), MathHelper.floor_double(entity.posZ));
tessellator.setTranslation(0.0D, 0.0D, 0.0D);
tessellator.draw();
} catch (Exception e) {
ICBMClassic.INSTANCE.logger().error("Unexpected error while rendering EntityBlock[" + entity + "] with data [" + block + ":" + entity.metadata + "] forcing to render as stone to prevent additional errors.", e);
entity.block = Blocks.stone;
//Hacky way of clearing current draw state
tessellator.isDrawing = false;
tessellator.startDrawingQuads();
tessellator.isDrawing = false;
}
} else {
RenderUtility.renderCube(0, 0, 0, 1, 1, 1, block, null, entity.metadata);
}
//GL11.glEnable(GL11.GL_LIGHTING);
} catch (Exception e) {
ICBMClassic.INSTANCE.logger().error("Unexpected error while rendering EntityBlock[" + entity + "] with data [" + block + ":" + entity.metadata + "]", e);
}
GL11.glPopMatrix();
}
use of com.builtbroken.mc.imp.transform.rotation.EulerAngle in project Engine by VoltzEngine-Project.
the class PacketSpawnParticleCircle method handleClientSide.
@Override
public void handleClientSide(EntityPlayer player) {
if (//TODO add error logging as neither condition should happen
player.worldObj.provider.dimensionId == dim && name != null && !name.isEmpty()) {
if (Engine.runningAsDev && distance <= 1) {
Engine.logger().error("PacketSpawnParticleCircle: Size of " + distance + " is to small to render effectively. " + new Pos(x, y, z).toString());
return;
}
double c = 2 * Math.PI * distance;
int particles = (int) Math.ceil(c) / 2;
if (particles % 2 == 1) {
particles += 1;
}
particles *= 5;
double angleSeg = 360.0 / (double) particles;
for (int i = 0; i < particles; i++) {
EulerAngle angle = new EulerAngle(angleSeg * i, 0);
Pos pos = angle.toPos().multiply(distance).add(x, y, z);
player.worldObj.spawnParticle(name, pos.x(), pos.y(), pos.z(), vx, vy, vz);
}
}
}
Aggregations