Search in sources :

Example 1 with IIntegratedCircuitPart

use of com.bluepowermod.api.gate.IIntegratedCircuitPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method renderStatic.

// Rendering
@Override
@SideOnly(Side.CLIENT)
public boolean renderStatic(Vec3i translation, RenderHelper renderer, RenderBlocks renderBlocks, int pass) {
    switch(getFace()) {
        case DOWN:
            break;
        case UP:
            renderer.addTransformation(new Rotation(180, 180, 0, Vec3d.center));
            break;
        case NORTH:
            renderer.addTransformation(new Rotation(90, 0, 0, Vec3d.center));
            break;
        case SOUTH:
            renderer.addTransformation(new Rotation(-90, 0, 0, Vec3d.center));
            break;
        case WEST:
            renderer.addTransformation(new Rotation(0, 0, -90, Vec3d.center));
            break;
        case EAST:
            renderer.addTransformation(new Rotation(0, 0, 90, Vec3d.center));
            break;
        default:
            break;
    }
    int rotation = getRotation();
    if (rotation != -1)
        renderer.addTransformation(new Rotation(0, 90 * -rotation, 0));
    IIcon[] icons = new IIcon[] { getIcon(ForgeDirection.DOWN), getIcon(ForgeDirection.UP), getIcon(ForgeDirection.WEST), getIcon(ForgeDirection.EAST), getIcon(ForgeDirection.NORTH), getIcon(ForgeDirection.SOUTH) };
    renderer.renderBox(new Vec3dCube(0, 0, 0, 1, 1 / 16D, 1), icons);
    renderer.renderBox(new Vec3dCube(0, 1 / 16D, 0, 1, 2 / 16D, 1 / 16D), icons);
    renderer.renderBox(new Vec3dCube(0, 1 / 16D, 15 / 16D, 1, 2 / 16D, 1), icons);
    renderer.renderBox(new Vec3dCube(0, 1 / 16D, 0, 1 / 16D, 2 / 16D, 1), icons);
    renderer.renderBox(new Vec3dCube(15 / 16D, 1 / 16D, 0, 1, 2 / 16D, 1), icons);
    for (IGateComponent c : getComponents()) c.renderStatic(translation, renderer, pass);
    double scale = (1 - border * 2D) / getSize();
    renderer.addTransformation(new Scale(scale, scale, scale));
    for (int x = 0; x < getSize(); x++) {
        for (int z = 0; z < getSize(); z++) {
            IIntegratedCircuitPart part = getPart(x, z);
            if (part == null)
                continue;
            int s = getSize();
            if (s % 2 == 1)
                s -= 1;
            double a = (getSize() - 1) / 2D;
            renderer.addTransformation(new Translation(-(s - x - a), -a, -(s - z - a)));
            part.renderStatic(translation, renderer, renderBlocks, pass);
            renderer.addTransformation(new Translation(s - x - a, a, s - z - a));
        }
    }
    renderer.removeTransformation();
    return true;
}
Also used : Translation(uk.co.qmunity.lib.transform.Translation) IIcon(net.minecraft.util.IIcon) IGateComponent(com.bluepowermod.api.gate.IGateComponent) IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart) Scale(uk.co.qmunity.lib.transform.Scale) Rotation(uk.co.qmunity.lib.transform.Rotation) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 2 with IIntegratedCircuitPart

use of com.bluepowermod.api.gate.IIntegratedCircuitPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method readParts.

private void readParts(NBTTagList l) {
    for (int i = 0; i < l.tagCount(); i++) {
        NBTTagCompound tag = l.getCompoundTagAt(i);
        int x = tag.getInteger("x");
        int z = tag.getInteger("z");
        IPart p = getPart(x, z);
        if (p == null) {
            p = PartRegistry.createPart(tag.getString("type"), false);
            if (p == null || !(p instanceof IIntegratedCircuitPart))
                continue;
            setPart(x, z, (IIntegratedCircuitPart) p);
        }
        p.readFromNBT(tag.getCompoundTag("data"));
    }
}
Also used : IPart(uk.co.qmunity.lib.part.IPart) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart)

Example 3 with IIntegratedCircuitPart

use of com.bluepowermod.api.gate.IIntegratedCircuitPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method tick.

@Override
public void tick() {
    loadWorld();
    for (IIntegratedCircuitPart part : allParts()) if (part instanceof IPartTicking)
        ((IPartTicking) part).update();
    unloadWorld();
}
Also used : IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart) IPartTicking(uk.co.qmunity.lib.part.IPartTicking)

Example 4 with IIntegratedCircuitPart

use of com.bluepowermod.api.gate.IIntegratedCircuitPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method sendUpdatePacket.

public void sendUpdatePacket(IPart part, int channel) {
    int x = 0;
    int z = 0;
    for (int x_ = 0; x_ < getSize(); x_++) {
        boolean found = false;
        for (int z_ = 0; z_ < getSize(); z_++) {
            IIntegratedCircuitPart p = getPart(x_, z_);
            if (p == part) {
                found = true;
                x = x_;
                z = z_;
                break;
            }
        }
        if (found)
            break;
    }
    int c = (z * getSize()) + x + 10;
    updateChannel = channel;
    sendUpdatePacket(c);
}
Also used : IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart)

Example 5 with IIntegratedCircuitPart

use of com.bluepowermod.api.gate.IIntegratedCircuitPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method onActivated.

@Override
public boolean onActivated(final EntityPlayer player, QMovingObjectPosition hit, ItemStack item) {
    Vec2d v = new Vec2d(hit.hitVec.xCoord - hit.blockX, hit.hitVec.zCoord - hit.blockZ).sub(0.5, 0.5).rotate(90 * -getRotation()).add(0.5, 0.5);
    int x = (int) (v.getX() * getSize());
    int z = (int) (v.getY() * getSize());
    if (getPart(x, z) == null && item != null && item.getItem() instanceof ItemPart) {
        IPart part = ((ItemPart) item.getItem()).createPart(item, player, getWorld(), hit);
        if (part instanceof IIntegratedCircuitPart) {
            if (!getWorld().isRemote) {
                setPart(x, z, (IIntegratedCircuitPart) part);
                sendUpdatePacket(part, -1);
            }
            return true;
        }
    }
    return super.onActivated(player, hit, item);
}
Also used : ItemPart(com.bluepowermod.item.ItemPart) IPart(uk.co.qmunity.lib.part.IPart) IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart) Vec2d(uk.co.qmunity.lib.vec.Vec2d)

Aggregations

IIntegratedCircuitPart (com.bluepowermod.api.gate.IIntegratedCircuitPart)6 IPart (uk.co.qmunity.lib.part.IPart)3 IGateComponent (com.bluepowermod.api.gate.IGateComponent)1 ItemPart (com.bluepowermod.item.ItemPart)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 IIcon (net.minecraft.util.IIcon)1 IPartTicking (uk.co.qmunity.lib.part.IPartTicking)1 Rotation (uk.co.qmunity.lib.transform.Rotation)1 Scale (uk.co.qmunity.lib.transform.Scale)1 Translation (uk.co.qmunity.lib.transform.Translation)1 Vec2d (uk.co.qmunity.lib.vec.Vec2d)1 Vec3dCube (uk.co.qmunity.lib.vec.Vec3dCube)1