Search in sources :

Example 21 with Pos

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

the class TileMulti method updateConnections.

public void updateConnections() {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        Pos pos = new Pos(this).add(dir);
        Block b = pos.getBlock(getWorldObj());
        if (connectedBlocks.containsKey(dir)) {
            //TODO notify that a block has changed
            if (connectedBlocks.get(dir) != b) {
                connectedBlocks.remove(dir);
            }
        }
        if (b != null && !b.isAir(getWorldObj(), xCoord, yCoord, zCoord)) {
            connectedBlocks.put(dir, b);
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block)

Example 22 with Pos

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

the class TileMulti method read.

@Override
public boolean read(ByteBuf buf, int id, EntityPlayer player, PacketType type) {
    if (worldObj.isRemote) {
        if (id == 1) {
            //Update host data for client use
            Pos pos = new Pos(buf);
            if (pos.isZero()) {
                this.setHost(null);
            } else {
                TileEntity tile = pos.getTileEntity(worldObj);
                if (tile instanceof IMultiTileHost) {
                    this.setHost((IMultiTileHost) tile);
                }
            }
            //Update should render
            boolean prev = shouldRenderBlock;
            shouldRenderBlock = buf.readBoolean();
            //Update render bounds
            if (buf.readBoolean()) {
                overrideRenderBounds = new Cube(buf);
            } else {
                overrideRenderBounds = new Cube(0, 0, 0, 1, 1, 1);
            }
            if (prev != shouldRenderBlock) {
                worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) IMultiTileHost(com.builtbroken.mc.api.tile.multiblock.IMultiTileHost)

Example 23 with Pos

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

the class BlockRenderHandler method renderWorldBlock.

@Override
public boolean renderWorldBlock(IBlockAccess access, int x, int y, int z, Block block, int modelId, RenderBlocks renderBlocks) {
    /**
         * Try TileEntity rendering
         */
    TileEntity tile = access.getTileEntity(x, y, z);
    if (tile instanceof Tile) {
        if (((Tile) tile).renderStatic(renderBlocks, new Pos(x, y, z), 0)) {
            return true;
        }
    }
    /**
         * Try Block rendering
         */
    if (block instanceof BlockTile) {
        BlockTile dummy = (BlockTile) block;
        tile = dummy.inject(access, x, y, z);
        boolean b = ((Tile) tile).renderStatic(renderBlocks, new Pos(x, y, z), 0);
        dummy.eject();
        return b;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile)

Example 24 with Pos

use of com.builtbroken.mc.imp.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.imp.transform.vector.Pos)

Example 25 with Pos

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

the class FXElectricBolt2 method split.

/**
	 * Slits a large segment into multiple smaller ones.
	 *
	 * @param splitAmount - The amount of splits
	 * @param offset      - The multiplier scale for the offset.
	 * @param splitChance - The chance of creating a split.
	 * @param splitLength - The length of each split.
	 * @param splitAngle  - The angle of the split.
	 */
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle) {
    /** Temporarily store old segments in a new array */
    List<BoltSegment> oldSegments = this.segments;
    this.segments = new ArrayList();
    /** Previous segment */
    BoltSegment prev = null;
    for (BoltSegment segment : oldSegments) {
        prev = segment.prev;
        /** Length of each subsegment */
        Pos subSegment = segment.difference.clone().multiply(1.0F / splitAmount);
        /**
			 * Creates an array of new bolt points. The first and last points of the bolts are the
			 * respected start and end points of the current segment.
			 */
        BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
        Pos startPoint = segment.start;
        newPoints[0] = segment.start;
        newPoints[splitAmount] = segment.end;
        /**
			 * Create bolt points.
			 */
        for (int i = 1; i < splitAmount; i++) {
            Pos newOffset = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
            Pos basePoint = startPoint.clone().add(subSegment.clone().multiply(i));
            newPoints[i] = new BoltPoint(basePoint, newOffset);
        }
        for (int i = 0; i < splitAmount; i++) {
            BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.alpha, segment.id * splitAmount + i, segment.splitID);
            next.prev = prev;
            if (prev != null) {
                prev.next = next;
            }
            if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
                IPos3D splitrot = next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360, next.difference));
                Pos diff = new Pos(next.difference.clone().transform(new Quaternion((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot))).multiply(splitLength);
                this.maxSplitID += 1;
                this.parentIDMap.put(this.maxSplitID, next.splitID);
                BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].base, newPoints[(i + 1)].offset.clone().add(diff)), segment.alpha / 2f, next.id, this.maxSplitID);
                split.prev = prev;
                this.segments.add(split);
            }
            prev = next;
            this.segments.add(next);
        }
        if (segment.next != null) {
            segment.next.prev = prev;
        }
    }
    this.segmentCount *= splitAmount;
}
Also used : IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Quaternion(com.builtbroken.mc.imp.transform.rotation.Quaternion)

Aggregations

Pos (com.builtbroken.mc.imp.transform.vector.Pos)105 Block (net.minecraft.block.Block)25 TileEntity (net.minecraft.tileentity.TileEntity)13 Location (com.builtbroken.mc.imp.transform.vector.Location)11 Entity (net.minecraft.entity.Entity)11 Cube (com.builtbroken.mc.imp.transform.region.Cube)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Test (org.junit.Test)7 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)6 EntityMissile (icbm.classic.content.entity.EntityMissile)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)5 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)5 ItemStack (net.minecraft.item.ItemStack)5 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4