Search in sources :

Example 6 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob 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 7 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob 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)

Example 8 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class GenericCableBlock method createCableSegment.

public void createCableSegment(World world, BlockPos pos, ItemStack stack) {
    XNetBlobData blobData = XNetBlobData.getBlobData(world);
    WorldBlob worldBlob = blobData.getWorldBlob(world);
    CableColor color = world.getBlockState(pos).getValue(COLOR);
    worldBlob.createCableSegment(pos, new ColorId(color.ordinal() + 1));
    blobData.save(world);
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) ColorId(mcjty.xnet.multiblock.ColorId)

Example 9 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class RouterBlock method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    if (!world.isRemote) {
        XNetBlobData blobData = XNetBlobData.getBlobData(world);
        WorldBlob worldBlob = blobData.getWorldBlob(world);
        worldBlob.removeCableSegment(pos);
        blobData.save(world);
    }
    super.breakBlock(world, pos, state);
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Example 10 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class GenericCableBlock method unlinkBlock.

public void unlinkBlock(World world, BlockPos pos) {
    if (!world.isRemote) {
        XNetBlobData blobData = XNetBlobData.getBlobData(world);
        WorldBlob worldBlob = blobData.getWorldBlob(world);
        worldBlob.removeCableSegment(pos);
        blobData.save(world);
    }
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Aggregations

WorldBlob (mcjty.xnet.multiblock.WorldBlob)25 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)11 ConsumerId (mcjty.xnet.api.keys.ConsumerId)8 NetworkId (mcjty.xnet.api.keys.NetworkId)8 ColorId (mcjty.xnet.multiblock.ColorId)7 TileEntity (net.minecraft.tileentity.TileEntity)7 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)6 EnumFacing (net.minecraft.util.EnumFacing)6 BlockPos (net.minecraft.util.math.BlockPos)6 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)5 Nonnull (javax.annotation.Nonnull)4 SidedPos (mcjty.xnet.api.keys.SidedPos)4 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)4 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)3 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)3 ConnectedBlockClientInfo (mcjty.xnet.clientinfo.ConnectedBlockClientInfo)3 BlobId (mcjty.xnet.multiblock.BlobId)3 IBlockState (net.minecraft.block.state.IBlockState)3 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)3 Nullable (javax.annotation.Nullable)2