Search in sources :

Example 1 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.

the class TileEntityController method removeConnector.

private void removeConnector(int channel, SidedPos pos) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
    SidedConsumer toremove = null;
    for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
        SidedConsumer key = entry.getKey();
        if (key.getSide().getOpposite().equals(pos.getSide())) {
            if (key.getConsumerId().equals(consumerId)) {
                toremove = key;
                break;
            }
        }
    }
    if (toremove != null) {
        channels[channel].getConnectors().remove(toremove);
        networkDirty();
        markDirtyQuick();
    }
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Example 2 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.

the class ItemChannelSettings method tick.

@Override
public void tick(int channel, IControllerContext context) {
    delay--;
    if (delay <= 0) {
        // Multiply of the different speeds we have
        delay = 200 * 6;
    }
    if (delay % 5 != 0) {
        return;
    }
    int d = delay / 5;
    updateCache(channel, context);
    World world = context.getControllerWorld();
    for (Map.Entry<SidedConsumer, ItemConnectorSettings> entry : itemExtractors.entrySet()) {
        ItemConnectorSettings settings = entry.getValue();
        if (d % settings.getSpeed() != 0) {
            continue;
        }
        ConsumerId consumerId = entry.getKey().getConsumerId();
        BlockPos extractorPos = context.findConsumerPosition(consumerId);
        if (extractorPos != null) {
            EnumFacing side = entry.getKey().getSide();
            BlockPos pos = extractorPos.offset(side);
            if (!WorldTools.chunkLoaded(world, pos)) {
                continue;
            }
            if (checkRedstone(world, settings, extractorPos)) {
                return;
            }
            if (!context.matchColor(settings.getColorsMask())) {
                return;
            }
            TileEntity te = world.getTileEntity(pos);
            if (XNet.rftools && RFToolsSupport.isStorageScanner(te)) {
                RFToolsSupport.tickStorageScanner(context, settings, te, this);
            } else {
                IItemHandler handler = getItemHandlerAt(te, settings.getFacing());
                if (handler != null) {
                    int idx = getStartExtractIndex(settings, consumerId, handler);
                    idx = tickItemHandler(context, settings, handler, idx);
                    if (handler.getSlots() > 0) {
                        rememberExtractIndex(consumerId, (idx + 1) % handler.getSlots());
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) EnumFacing(net.minecraft.util.EnumFacing) ConsumerId(mcjty.xnet.api.keys.ConsumerId) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 3 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.

the class ItemChannelSettings method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound tag) {
    channelMode = ChannelMode.values()[tag.getByte("mode")];
    delay = tag.getInteger("delay");
    roundRobinOffset = tag.getInteger("offset");
    int[] cons = tag.getIntArray("extidx");
    for (int idx = 0; idx < cons.length; idx += 2) {
        extractIndeces.put(new ConsumerId(cons[idx]), cons[idx + 1]);
    }
}
Also used : ConsumerId(mcjty.xnet.api.keys.ConsumerId)

Example 4 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.

the class ConnectorBlock method getDrops.

@Override
public List<ItemStack> getDrops(IBlockAccess blockAccess, BlockPos pos, IBlockState state, int fortune) {
    List<ItemStack> drops = super.getDrops(blockAccess, pos, state, fortune);
    if (blockAccess instanceof World) {
        World world = (World) blockAccess;
        for (ItemStack drop : drops) {
            if (!drop.hasTagCompound()) {
                drop.setTagCompound(new NBTTagCompound());
            }
            WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
            ConsumerId consumer = worldBlob.getConsumerAt(pos);
            if (consumer != null) {
                drop.getTagCompound().setInteger("consumerId", consumer.getId());
            }
        }
    }
    return drops;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World)

Example 5 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.

the class ConnectorUpgradeItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block == NetCableSetup.connectorBlock) {
        if (!world.isRemote) {
            TileEntity te = world.getTileEntity(pos);
            if (te instanceof ConnectorTileEntity) {
                NBTTagCompound tag = new NBTTagCompound();
                te.writeToNBT(tag);
                CableColor color = world.getBlockState(pos).getValue(GenericCableBlock.COLOR);
                XNetBlobData blobData = XNetBlobData.getBlobData(world);
                WorldBlob worldBlob = blobData.getWorldBlob(world);
                ConsumerId consumer = worldBlob.getConsumerAt(pos);
                ((ConnectorBlock) block).unlinkBlock(world, pos);
                world.setBlockState(pos, NetCableSetup.advancedConnectorBlock.getDefaultState().withProperty(GenericCableBlock.COLOR, color));
                IBlockState blockState = world.getBlockState(pos);
                ((ConnectorBlock) blockState.getBlock()).createCableSegment(world, pos, consumer);
                te = TileEntity.create(world, tag);
                if (te != null) {
                    world.getChunkFromBlockCoords(pos).addTileEntity(te);
                    te.markDirty();
                    world.notifyBlockUpdate(pos, blockState, blockState, 3);
                    player.inventory.decrStackSize(player.inventory.currentItem, 1);
                    player.openContainer.detectAndSendChanges();
                    player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Connector was upgraded"), false);
                } else {
                    player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Something went wrong during upgrade!"), false);
                    return EnumActionResult.FAIL;
                }
            }
        }
        return EnumActionResult.SUCCESS;
    } else if (block == NetCableSetup.advancedConnectorBlock) {
        if (!world.isRemote) {
            player.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "This connector is already advanced!"), false);
        }
        return EnumActionResult.SUCCESS;
    } else {
        if (!world.isRemote) {
            player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Use this item on a connector to upgrade it!"), false);
        }
        return EnumActionResult.SUCCESS;
    }
}
Also used : ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ConsumerId(mcjty.xnet.api.keys.ConsumerId) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) Block(net.minecraft.block.Block) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) WorldBlob(mcjty.xnet.multiblock.WorldBlob) CableColor(mcjty.xnet.blocks.generic.CableColor) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ConsumerId (mcjty.xnet.api.keys.ConsumerId)15 WorldBlob (mcjty.xnet.multiblock.WorldBlob)7 NetworkId (mcjty.xnet.api.keys.NetworkId)6 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)5 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 Nonnull (javax.annotation.Nonnull)1 Argument (mcjty.lib.network.Argument)1 IChannelType (mcjty.xnet.api.channels.IChannelType)1 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)1 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)1 CableColor (mcjty.xnet.blocks.generic.CableColor)1 GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)1 BlobId (mcjty.xnet.multiblock.BlobId)1 ColorId (mcjty.xnet.multiblock.ColorId)1