Search in sources :

Example 1 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class InventoryUtility method placeItemBlock.

/**
 * Tries to place the item stack into the world as a block.
 *
 * @param world     - world
 * @param x         - the x-Coordinate of desired placement
 * @param y         - the y-Coordinate of desired placement
 * @param z         - the z-Coordinate of desired placement
 * @param itemStack - itemStack, should be an ItemBlock or something that can be placed
 * @param side      - the side we are trying to place on within this block space.
 * @return true if the block was created from the item, or other words placed into the world. If
 * the stack is null, if its not valid, or there is no room it returns false.
 */
public static boolean placeItemBlock(World world, int x, int y, int z, ItemStack itemStack, int side) {
    // TODO implement support for micro blocks
    if (itemStack != null) {
        try {
            Pos rightClickPos = new Pos(x, y, z);
            if (world.isAirBlock(x, y, z)) {
                rightClickPos.add(ForgeDirection.getOrientation(side));
            }
            side ^= 1;
            return DummyPlayer.useItemAt(itemStack, world, x, y - 1, z, side);
        } catch (Exception e) {
            e.printStackTrace();
            if (world.getBlock(x, y, z) == ((ItemBlock) itemStack.getItem()).field_150939_a) {
                return true;
            }
        }
    }
    return false;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 2 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class Blast method displayEffectForEdit.

/**
 * See {@link RenderGlobal#doSpawnParticle(String, double, double, double, double, double, double)} for a list of vanilla particles
 */
@Override
public void displayEffectForEdit(IWorldEdit blocks) {
    // TODO add config syncing to ensure server doesn't send render packets when not used by client
    if (!world.isRemote) {
        // Generate random position near block
        double posX = (double) ((float) blocks.x() + world.rand.nextFloat());
        double posY = (double) ((float) blocks.y() + world.rand.nextFloat());
        double posZ = (double) ((float) blocks.z() + world.rand.nextFloat());
        Pos pos = randomMotion(posX, posY, posZ);
        // Spawn particles
        Engine.proxy.spawnParticle("explode", world, (posX + x * 1.0D) / 2.0D, (posY + y * 1.0D) / 2.0D, (posZ + z * 1.0D) / 2.0D, pos.x(), pos.y(), pos.z());
        Engine.proxy.spawnParticle("smoke", world, posX, posY, posZ, pos.x(), pos.y(), pos.z());
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 3 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class BlastBasic method doEffectOther.

@Override
public void doEffectOther(boolean beforeBlocksPlaced) {
    if (!beforeBlocksPlaced) {
        // TODO wright own version of getEntitiesWithinAABB that takes a filter and cuboid(or Vector3 to Vector3)
        // TODO ensure that the entity is in line of sight
        // TODO ensure that the entity can be pathed by the explosive
        AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(x - size - 1, y - size - 1, z - size - 1, x + size + 1, y + size + 1, z + size + 1);
        List list = world.selectEntitiesWithinAABB(Entity.class, bounds, new EntityDistanceSelector(new Pos(x, y, z), size + 1, true));
        if (list != null && !list.isEmpty()) {
            damageEntities(list, source);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ArrayList(java.util.ArrayList) List(java.util.List) EntityDistanceSelector(com.builtbroken.mc.prefab.entity.selector.EntityDistanceSelector)

Example 4 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class FXElectricBolt method renderBolt.

/**
 * Renders the bolts.
 */
private void renderBolt(Tessellator tessellator, float partialframe, float cosyaw, float cospitch, float sinyaw, float cossinpitch, int pass) {
    Pos playerVector = new Pos(sinyaw * -cospitch, -cossinpitch / cosyaw, cosyaw * cospitch);
    float voltage = this.particleAge >= 0 ? ((float) this.particleAge / (float) this.particleMaxAge) : 0.0F;
    float mainAlpha = 1.0F;
    if (pass == 0) {
        mainAlpha = (1.0F - voltage) * 0.4F;
    } else {
        mainAlpha = 1.0F - voltage * 0.5F;
    }
    int renderlength = (int) ((this.particleAge + partialframe + (int) (this.length * 3.0F)) / (int) (this.length * 3.0F) * this.segmentCount);
    for (BoltSegment renderSegment : this.segments) {
        if (renderSegment != null && renderSegment.segmentID <= renderlength) {
            float width = (float) (this.boltWidth * (getRelativeViewVector(renderSegment.startBolt.point).magnitude() / 5.0F + 1.0F) * (1.0F + renderSegment.weight) * 0.5F);
            Pos diff1 = playerVector.cross(renderSegment.prevDiff).multiply(width / renderSegment.sinPrev);
            Pos diff2 = playerVector.cross(renderSegment.nextDiff).multiply(width / renderSegment.sinNext);
            Pos startvec = renderSegment.startBolt.point;
            Pos endvec = renderSegment.endBolt.point;
            float rx1 = (float) (startvec.x() - interpPosX);
            float ry1 = (float) (startvec.y() - interpPosY);
            float rz1 = (float) (startvec.z() - interpPosZ);
            float rx2 = (float) (endvec.x() - interpPosX);
            float ry2 = (float) (endvec.y() - interpPosY);
            float rz2 = (float) (endvec.z() - interpPosZ);
            tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, mainAlpha * renderSegment.weight);
            tessellator.addVertexWithUV(rx2 - diff2.x(), ry2 - diff2.y(), rz2 - diff2.z(), 0.5D, 0.0D);
            tessellator.addVertexWithUV(rx1 - diff1.x(), ry1 - diff1.y(), rz1 - diff1.z(), 0.5D, 0.0D);
            tessellator.addVertexWithUV(rx1 + diff1.x(), ry1 + diff1.y(), rz1 + diff1.z(), 0.5D, 1.0D);
            tessellator.addVertexWithUV(rx2 + diff2.x(), ry2 + diff2.y(), rz2 + diff2.z(), 0.5D, 1.0D);
            if (renderSegment.nextSegment == null) {
                Pos roundend = renderSegment.endBolt.point.clone().add(renderSegment.difference.clone().normalize().multiply(width));
                float rx3 = (float) (roundend.x() - interpPosX);
                float ry3 = (float) (roundend.y() - interpPosY);
                float rz3 = (float) (roundend.z() - interpPosZ);
                tessellator.addVertexWithUV(rx3 - diff2.x(), ry3 - diff2.y(), rz3 - diff2.z(), 0.0D, 0.0D);
                tessellator.addVertexWithUV(rx2 - diff2.x(), ry2 - diff2.y(), rz2 - diff2.z(), 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx2 + diff2.x(), ry2 + diff2.y(), rz2 + diff2.z(), 0.5D, 1.0D);
                tessellator.addVertexWithUV(rx3 + diff2.x(), ry3 + diff2.y(), rz3 + diff2.z(), 0.0D, 1.0D);
            }
            if (renderSegment.prevSegment == null) {
                Pos roundend = renderSegment.startBolt.point.clone().subtract(renderSegment.difference.clone().normalize().multiply(width));
                float rx3 = (float) (roundend.x() - interpPosX);
                float ry3 = (float) (roundend.y() - interpPosY);
                float rz3 = (float) (roundend.z() - interpPosZ);
                tessellator.addVertexWithUV(rx1 - diff1.x(), ry1 - diff1.y(), rz1 - diff1.z(), 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx3 - diff1.x(), ry3 - diff1.y(), rz3 - diff1.z(), 0.0D, 0.0D);
                tessellator.addVertexWithUV(rx3 + diff1.x(), ry3 + diff1.y(), rz3 + diff1.z(), 0.0D, 1.0D);
                tessellator.addVertexWithUV(rx1 + diff1.x(), ry1 + diff1.y(), rz1 + diff1.z(), 0.5D, 1.0D);
            }
        }
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 5 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class FXElectricBolt2 method renderParticle.

@Override
public void renderParticle(Tessellator tessellator, float partialframe, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch) {
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    tessellator.draw();
    GL11.glPushMatrix();
    GL11.glDepthMask(false);
    GL11.glEnable(3042);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
    /**
     * Render the actual bolts.
     */
    tessellator.startDrawingQuads();
    tessellator.setBrightness(15728880);
    Pos playerVector = new Pos(sinYaw * -cosPitch, -cosSinPitch / cosYaw, cosYaw * cosPitch);
    int renderlength = (int) ((this.particleAge + partialframe + (int) (this.boltLength * 3.0F)) / (int) (this.boltLength * 3.0F) * this.segmentCount);
    for (BoltSegment segment : this.segments) {
        if (segment != null && segment.id <= renderlength) {
            double renderWidth = this.boltWidth * ((new Pos(player).distance(segment.start) / 5f + 1f) * (1 + segment.alpha) * 0.5f);
            renderWidth = Math.min(this.boltWidth, Math.max(renderWidth, 0));
            if (segment.difference.magnitude() > 0 && segment.difference.magnitude() != Double.NaN && segment.difference.magnitude() != Double.POSITIVE_INFINITY && renderWidth > 0 && renderWidth != Double.NaN && renderWidth != Double.POSITIVE_INFINITY) {
                Pos diffPrev = playerVector.cross(segment.prevDiff).multiply(renderWidth / segment.sinPrev);
                Pos diffNext = playerVector.cross(segment.nextDiff).multiply(renderWidth / segment.sinNext);
                Pos startVec = segment.start;
                Pos endVec = segment.end;
                float rx1 = (float) (startVec.x() - interpPosX);
                float ry1 = (float) (startVec.y() - interpPosY);
                float rz1 = (float) (startVec.z() - interpPosZ);
                float rx2 = (float) (endVec.x() - interpPosX);
                float ry2 = (float) (endVec.y() - interpPosY);
                float rz2 = (float) (endVec.z() - interpPosZ);
                tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, (1.0F - (this.particleAge >= 0 ? ((float) this.particleAge / (float) this.particleMaxAge) : 0.0F) * 0.6f) * segment.alpha);
                tessellator.addVertexWithUV(rx2 - diffNext.x(), ry2 - diffNext.y(), rz2 - diffNext.z(), 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx1 - diffPrev.x(), ry1 - diffPrev.y(), rz1 - diffPrev.z(), 0.5D, 0.0D);
                tessellator.addVertexWithUV(rx1 + diffPrev.x(), ry1 + diffPrev.y(), rz1 + diffPrev.z(), 0.5D, 1.0D);
                tessellator.addVertexWithUV(rx2 + diffNext.x(), ry2 + diffNext.y(), rz2 + diffNext.z(), 0.5D, 1.0D);
                if (segment.next == null) {
                    Pos roundEnd = segment.end.clone().add(segment.difference.clone().normalize().multiply(renderWidth));
                    float rx3 = (float) (roundEnd.x() - interpPosX);
                    float ry3 = (float) (roundEnd.y() - interpPosY);
                    float rz3 = (float) (roundEnd.z() - interpPosZ);
                    tessellator.addVertexWithUV(rx3 - diffNext.x(), ry3 - diffNext.y(), rz3 - diffNext.z(), 0.0D, 0.0D);
                    tessellator.addVertexWithUV(rx2 - diffNext.x(), ry2 - diffNext.y(), rz2 - diffNext.z(), 0.5D, 0.0D);
                    tessellator.addVertexWithUV(rx2 + diffNext.x(), ry2 + diffNext.y(), rz2 + diffNext.z(), 0.5D, 1.0D);
                    tessellator.addVertexWithUV(rx3 + diffNext.x(), ry3 + diffNext.y(), rz3 + diffNext.z(), 0.0D, 1.0D);
                }
                if (segment.prev == null) {
                    Pos roundEnd = segment.start.clone().subtract(segment.difference.clone().normalize().multiply(renderWidth));
                    float rx3 = (float) (roundEnd.x() - interpPosX);
                    float ry3 = (float) (roundEnd.y() - interpPosY);
                    float rz3 = (float) (roundEnd.z() - interpPosZ);
                    tessellator.addVertexWithUV(rx1 - diffPrev.x(), ry1 - diffPrev.y(), rz1 - diffPrev.z(), 0.5D, 0.0D);
                    tessellator.addVertexWithUV(rx3 - diffPrev.x(), ry3 - diffPrev.y(), rz3 - diffPrev.z(), 0.0D, 0.0D);
                    tessellator.addVertexWithUV(rx3 + diffPrev.x(), ry3 + diffPrev.y(), rz3 + diffPrev.z(), 0.0D, 1.0D);
                    tessellator.addVertexWithUV(rx1 + diffPrev.x(), ry1 + diffPrev.y(), rz1 + diffPrev.z(), 0.5D, 1.0D);
                }
            }
        }
    }
    tessellator.draw();
    GL11.glDisable(3042);
    GL11.glDepthMask(true);
    GL11.glPopMatrix();
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(PARTICLE_RESOURCE);
    tessellator.startDrawingQuads();
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

Pos (com.builtbroken.mc.lib.transform.vector.Pos)68 Block (net.minecraft.block.Block)11 TileEntity (net.minecraft.tileentity.TileEntity)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)7 Cube (com.builtbroken.mc.lib.transform.region.Cube)6 Test (org.junit.Test)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 BlockEdit (com.builtbroken.mc.lib.world.edit.BlockEdit)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Vector3DistanceComparator (com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Pair (com.builtbroken.jlib.type.Pair)3 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 Quaternion (com.builtbroken.mc.lib.transform.rotation.Quaternion)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)3