Search in sources :

Example 1 with EulerAngle

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;
}
Also used : TileState(com.builtbroken.mc.client.json.render.tile.TileState) JsonConverterPos(com.builtbroken.mc.lib.json.conversion.JsonConverterPos) Pos(com.builtbroken.mc.imp.transform.vector.Pos) ModelState(com.builtbroken.mc.client.json.render.state.ModelState) JsonObject(com.google.gson.JsonObject) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle)

Example 2 with EulerAngle

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;
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityExplosive(icbm.classic.content.entity.EntityExplosive) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle) IExplosiveIgnore(resonant.api.explosion.IExplosiveIgnore) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 3 with EulerAngle

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();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) Block(net.minecraft.block.Block) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle)

Example 4 with EulerAngle

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);
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle)

Aggregations

EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)4 Pos (com.builtbroken.mc.imp.transform.vector.Pos)4 ModelState (com.builtbroken.mc.client.json.render.state.ModelState)1 TileState (com.builtbroken.mc.client.json.render.tile.TileState)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 JsonConverterPos (com.builtbroken.mc.lib.json.conversion.JsonConverterPos)1 JsonObject (com.google.gson.JsonObject)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 EntityExplosive (icbm.classic.content.entity.EntityExplosive)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 Block (net.minecraft.block.Block)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IExplosiveIgnore (resonant.api.explosion.IExplosiveIgnore)1