Search in sources :

Example 11 with IPart

use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method doLogic.

// Logic and interaction
@Override
public void doLogic() {
    loadWorld();
    IPart part = getPart(0, (getSize() - 1) / 2);
    if (part instanceof IPartUpdateListener)
        ((IPartUpdateListener) part).onNeighborBlockChange();
    part = getPart(getSize() - 1, (getSize() - 1) / 2);
    if (part instanceof IPartUpdateListener)
        ((IPartUpdateListener) part).onNeighborBlockChange();
    part = getPart((getSize() - 1) / 2, 0);
    if (part instanceof IPartUpdateListener)
        ((IPartUpdateListener) part).onNeighborBlockChange();
    part = getPart((getSize() - 1) / 2, getSize() - 1);
    if (part instanceof IPartUpdateListener)
        ((IPartUpdateListener) part).onNeighborBlockChange();
    unloadWorld();
}
Also used : IPartUpdateListener(uk.co.qmunity.lib.part.IPartUpdateListener) IPart(uk.co.qmunity.lib.part.IPart)

Example 12 with IPart

use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method getBundledDeviceOnSide.

@Override
public IBundledDevice getBundledDeviceOnSide(ForgeDirection side) {
    side = new Vec3d(0, 0, 0).add(side).rotate(0, 90 * -getRotation(), 0).toForgeDirection();
    IPart p = getCircuitPartOnSide(side);
    if (p == null)
        return null;
    if (p instanceof IBundledDevice)
        return (IBundledDevice) p;
    return null;
}
Also used : IPart(uk.co.qmunity.lib.part.IPart) Vec3d(uk.co.qmunity.lib.vec.Vec3d) IBundledDevice(com.bluepowermod.api.wire.redstone.IBundledDevice)

Example 13 with IPart

use of uk.co.qmunity.lib.part.IPart 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)

Example 14 with IPart

use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method readUpdateData.

@Override
public void readUpdateData(DataInput buffer, int channel) throws IOException {
    super.readUpdateData(buffer, channel);
    getWorld().markBlockRangeForRenderUpdate(getX(), getY(), getZ(), getX(), getY(), getZ());
    if (channel < 10)
        return;
    int c = channel - 10;
    int x = c % getSize();
    int z = (c - x) / getSize();
    if (!buffer.readBoolean())
        return;
    String type = buffer.readUTF();
    IPart p = getPart(x, z);
    if (p == null)
        setPart(x, z, (IIntegratedCircuitPart) (p = PartRegistry.createPart(type, true)));
    if (p == null) {
        // buffer.skipBytes(buffer.readInt());
        return;
    }
    updateChannel = buffer.readInt();
    // byte[] data = new byte[buffer.readInt()];
    // buffer.readFully(data, 0, data.length);
    // ByteArrayInputStream bais = new ByteArrayInputStream(data, 0, data.length);
    // DataInputStream buf = new DataInputStream(bais);
    p.readUpdateData(buffer, updateChannel);
}
Also used : IPart(uk.co.qmunity.lib.part.IPart) IIntegratedCircuitPart(com.bluepowermod.api.gate.IIntegratedCircuitPart)

Example 15 with IPart

use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.

the class GateIntegratedCircuit method writeParts.

private void writeParts(NBTTagList l) {
    for (int x = 0; x < getSize(); x++) {
        for (int z = 0; z < getSize(); z++) {
            IPart p = getPart(x, z);
            if (p == null)
                continue;
            NBTTagCompound tag = new NBTTagCompound();
            tag.setInteger("x", x);
            tag.setInteger("z", z);
            tag.setString("type", p.getType());
            NBTTagCompound data = new NBTTagCompound();
            p.writeToNBT(data);
            tag.setTag("data", data);
            l.appendTag(tag);
        }
    }
}
Also used : IPart(uk.co.qmunity.lib.part.IPart) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

IPart (uk.co.qmunity.lib.part.IPart)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ItemPart (com.bluepowermod.item.ItemPart)4 Vec3d (uk.co.qmunity.lib.vec.Vec3d)4 IIntegratedCircuitPart (com.bluepowermod.api.gate.IIntegratedCircuitPart)3 IScrewdriver (com.bluepowermod.api.misc.IScrewdriver)3 PartRedwireFace (com.bluepowermod.part.wire.redstone.PartRedwireFace)3 PartRedwireFaceUninsulated (com.bluepowermod.part.wire.redstone.PartRedwireFace.PartRedwireFaceUninsulated)3 ItemStack (net.minecraft.item.ItemStack)3 IRedstoneDevice (com.bluepowermod.api.wire.redstone.IRedstoneDevice)2 IPartUpdateListener (uk.co.qmunity.lib.part.IPartUpdateListener)2 ITilePartHolder (uk.co.qmunity.lib.part.ITilePartHolder)2 IAdvancedSilkyRemovable (com.bluepowermod.api.block.IAdvancedSilkyRemovable)1 ISilkyRemovable (com.bluepowermod.api.block.ISilkyRemovable)1 MinecraftColor (com.bluepowermod.api.misc.MinecraftColor)1 IBundledDevice (com.bluepowermod.api.wire.redstone.IBundledDevice)1 IInsulatedRedwire (com.bluepowermod.api.wire.redstone.IRedwire.IInsulatedRedwire)1 RedwireType (com.bluepowermod.api.wire.redstone.RedwireType)1 ItemScrewdriver (com.bluepowermod.item.ItemScrewdriver)1 PartInfo (com.bluepowermod.part.PartInfo)1