Search in sources :

Example 1 with XNetBlobData

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

the class ControllerBlock method findNeighbourConnector.

// Check neighbour blocks for a connector and inherit the color from that
private void findNeighbourConnector(World world, BlockPos pos) {
    XNetBlobData blobData = XNetBlobData.getBlobData(world);
    WorldBlob worldBlob = blobData.getWorldBlob(world);
    ColorId oldColor = worldBlob.getColorAt(pos);
    ColorId newColor = null;
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (world.getBlockState(pos.offset(facing)).getBlock() instanceof ConnectorBlock) {
            ColorId color = worldBlob.getColorAt(pos.offset(facing));
            if (color != null) {
                if (color == oldColor) {
                    // Nothing to do
                    return;
                }
                newColor = color;
            }
        }
    }
    if (newColor != null) {
        if (worldBlob.getBlobAt(pos) != null) {
            worldBlob.removeCableSegment(pos);
        }
        NetworkId networkId = worldBlob.newNetwork();
        worldBlob.createNetworkProvider(pos, newColor, networkId);
        blobData.save(world);
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TileEntityController) {
            ((TileEntityController) te).setNetworkId(networkId);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) EnumFacing(net.minecraft.util.EnumFacing) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) ColorId(mcjty.xnet.multiblock.ColorId) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Example 2 with XNetBlobData

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

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

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

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

the class CommandGen method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    XNetBlobData data = XNetBlobData.getBlobData(server.getEntityWorld());
    EntityPlayer player = (EntityPlayer) sender;
    EnumFacing facing = player.getHorizontalFacing();
    BlockPos pos = player.getPosition();
    System.out.println("facing = " + facing);
    System.out.println("pos = " + pos);
    World world = player.getEntityWorld();
    for (int i = 0; i < 1000; i++) {
        System.out.println("i = " + i);
        world.setBlockState(pos, NetCableSetup.netCableBlock.getDefaultState());
        world.markBlockRangeForRenderUpdate(pos.add(-1, -1, -1), pos.add(1, 1, 1));
        NetCableSetup.netCableBlock.createCableSegment(world, pos, ItemStack.EMPTY);
        pos = pos.offset(facing);
    }
    // TeleportationTools.performTeleport(player, new TeleportDestination(pos, 0), 0, 0, true);
    System.out.println("done");
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)14 WorldBlob (mcjty.xnet.multiblock.WorldBlob)10 ColorId (mcjty.xnet.multiblock.ColorId)5 NetworkId (mcjty.xnet.api.keys.NetworkId)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ConsumerId (mcjty.xnet.api.keys.ConsumerId)2 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)2 CableColor (mcjty.xnet.blocks.generic.CableColor)2 EnumFacing (net.minecraft.util.EnumFacing)2 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)1 GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)1 BlobId (mcjty.xnet.multiblock.BlobId)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 World (net.minecraft.world.World)1