Search in sources :

Example 6 with IPart

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

the class GateIntegratedCircuit method writeUpdateData.

@Override
public void writeUpdateData(DataOutput buffer, int channel) throws IOException {
    super.writeUpdateData(buffer, channel);
    if (channel < 10)
        return;
    int c = channel - 10;
    int x = c % getSize();
    int z = (c - x) / getSize();
    IPart p = getPart(x, z);
    if (p == null) {
        buffer.writeBoolean(false);
        return;
    }
    buffer.writeBoolean(true);
    buffer.writeUTF(p.getType());
    buffer.writeInt(updateChannel);
    // ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // DataOutputStream buf = new DataOutputStream(baos);
    p.writeUpdateData(buffer, updateChannel);
//
// byte[] data = baos.toByteArray();
// buffer.write(data.length);
// buffer.write(data);
}
Also used : IPart(uk.co.qmunity.lib.part.IPart)

Example 7 with IPart

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

the class PartConverterGate method convert.

@Override
public IPart convert(NBTTagCompound old) {
    String id = old.getString("part_id");
    PartInfo info = PartManager.getPartInfo(id);
    if (info == null)
        return null;
    IPart p = info.create();
    if (!(p instanceof GateBase<?, ?, ?, ?, ?, ?>))
        return null;
    GateBase<?, ?, ?, ?, ?, ?> part = (GateBase<?, ?, ?, ?, ?, ?>) p;
    NBTTagCompound data = old.getCompoundTag("partData");
    part.readFromNBT(data);
    part.setRotation(data.getInteger("rotation") + 2);
    return part;
}
Also used : IPart(uk.co.qmunity.lib.part.IPart) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PartInfo(com.bluepowermod.part.PartInfo) GateBase(com.bluepowermod.part.gate.GateBase)

Example 8 with IPart

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

the class ItemSilkyScrewdriver method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    TileEntity te = world.getTileEntity(x, y, z);
    ITilePartHolder h = MultipartCompatibility.getPartHolder(world, x, y, z);
    if (h != null) {
        QMovingObjectPosition mop = h.rayTrace(RayTracer.instance().getStartVector(player), RayTracer.instance().getEndVector(player));
        if (mop != null) {
            IPart p = mop.getPart();
            if (p instanceof ISilkyRemovable && !world.isRemote) {
                if (p instanceof IAdvancedSilkyRemovable && !((IAdvancedSilkyRemovable) p).preSilkyRemoval(world, x, y, z))
                    return false;
                NBTTagCompound tag = new NBTTagCompound();
                boolean hideTooltip = false;
                if (p instanceof IAdvancedSilkyRemovable) {
                    hideTooltip = ((IAdvancedSilkyRemovable) p).writeSilkyData(world, x, y, z, tag);
                } else {
                    p.writeToNBT(tag);
                }
                ItemStack droppedStack = p.getItem();
                NBTTagCompound stackTag = droppedStack.getTagCompound();
                if (stackTag == null) {
                    stackTag = new NBTTagCompound();
                    droppedStack.setTagCompound(stackTag);
                }
                stackTag.setTag("tileData", tag);
                stackTag.setBoolean("hideSilkyTooltip", hideTooltip);
                world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, droppedStack));
                h.removePart(p);
                if (p instanceof IAdvancedSilkyRemovable)
                    ((IAdvancedSilkyRemovable) p).postSilkyRemoval(world, x, y, z);
                stack.damageItem(1, player);
                return true;
            }
        }
        return false;
    }
    if (block instanceof ISilkyRemovable && !world.isRemote) {
        if (block instanceof IAdvancedSilkyRemovable && !((IAdvancedSilkyRemovable) block).preSilkyRemoval(world, x, y, z))
            return false;
        if (te == null)
            throw new IllegalStateException("Block doesn't have a TileEntity?! Implementers of ISilkyRemovable should have one. Offender: " + block.getUnlocalizedName());
        NBTTagCompound tag = new NBTTagCompound();
        te.writeToNBT(tag);
        int metadata = world.getBlockMetadata(x, y, z);
        Item item = block.getItemDropped(metadata, itemRand, 0);
        if (item == null)
            throw new NullPointerException("Block returns null for getItemDropped(meta, rand, fortune)! Offender: " + block.getUnlocalizedName());
        ItemStack droppedStack = new ItemStack(item, 1, block.damageDropped(metadata));
        NBTTagCompound stackTag = droppedStack.getTagCompound();
        if (stackTag == null) {
            stackTag = new NBTTagCompound();
            droppedStack.setTagCompound(stackTag);
        }
        stackTag.setTag("tileData", tag);
        world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, droppedStack));
        world.setBlockToAir(x, y, z);
        if (block instanceof IAdvancedSilkyRemovable)
            ((IAdvancedSilkyRemovable) block).postSilkyRemoval(world, x, y, z);
        stack.damageItem(1, player);
        return true;
    }
    return false;
}
Also used : IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QMovingObjectPosition(uk.co.qmunity.lib.raytrace.QMovingObjectPosition) TileEntity(net.minecraft.tileentity.TileEntity) ITilePartHolder(uk.co.qmunity.lib.part.ITilePartHolder) EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) IPart(uk.co.qmunity.lib.part.IPart) ISilkyRemovable(com.bluepowermod.api.block.ISilkyRemovable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 9 with IPart

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

the class MessageWirelessNewFreq method handleServerSide.

@Override
public void handleServerSide(EntityPlayer player) {
    Frequency freq = (Frequency) WirelessManager.COMMON_INSTANCE.registerFrequency(player, name, acc, bundled);
    ITilePartHolder h = MultipartCompatibility.getPartHolder(player.worldObj, x, y, z);
    if (h == null)
        return;
    IWirelessGate p = null;
    for (IPart pa : h.getParts()) if (pa instanceof IWirelessGate && ((IWirelessGate) pa).getFace() == face)
        p = (IWirelessGate) pa;
    if (p == null)
        return;
    p.setFrequency(freq);
    BPNetworkHandler.INSTANCE.sendTo(new MessageWirelessFrequencySync(player), (EntityPlayerMP) player);
}
Also used : ITilePartHolder(uk.co.qmunity.lib.part.ITilePartHolder) IPart(uk.co.qmunity.lib.part.IPart) IWirelessGate(com.bluepowermod.part.gate.wireless.IWirelessGate) Frequency(com.bluepowermod.part.gate.wireless.Frequency)

Example 10 with IPart

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

the class GateIntegratedCircuit method getDeviceOnSide.

@Override
public IRedstoneDevice getDeviceOnSide(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 IRedstoneDevice)
        return (IRedstoneDevice) p;
    return null;
}
Also used : IPart(uk.co.qmunity.lib.part.IPart) IRedstoneDevice(com.bluepowermod.api.wire.redstone.IRedstoneDevice) Vec3d(uk.co.qmunity.lib.vec.Vec3d)

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