Search in sources :

Example 1 with ConnectorBlock

use of mcjty.xnet.blocks.cables.ConnectorBlock 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 ConnectorBlock

use of mcjty.xnet.blocks.cables.ConnectorBlock in project XNet by McJty.

the class GuiProxy method getServerGuiElement.

@Override
public Object getServerGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) {
    if (guiid == GUI_MANUAL_XNET) {
        return null;
    }
    BlockPos pos = new BlockPos(x, y, z);
    Block block = world.getBlockState(pos).getBlock();
    if (block instanceof GenericBlock) {
        GenericBlock<?, ?> genericBlock = (GenericBlock<?, ?>) block;
        TileEntity te = world.getTileEntity(pos);
        return genericBlock.createServerContainer(entityPlayer, te);
    } else if (block instanceof ConnectorBlock) {
        return new EmptyContainer(entityPlayer, null);
    }
    return null;
}
Also used : GenericBlock(mcjty.lib.container.GenericBlock) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) EmptyContainer(mcjty.lib.container.EmptyContainer) GenericBlock(mcjty.lib.container.GenericBlock) Block(net.minecraft.block.Block) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) BlockPos(net.minecraft.util.math.BlockPos) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Example 3 with ConnectorBlock

use of mcjty.xnet.blocks.cables.ConnectorBlock 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 4 with ConnectorBlock

use of mcjty.xnet.blocks.cables.ConnectorBlock in project XNet by McJty.

the class ConnectorIterator method findNext.

private void findNext() {
    foundPos = null;
    while (facingIdx != -1) {
        BlockPos connectorPos = pos.offset(EnumFacing.VALUES[facingIdx]);
        facingIdx++;
        if (facingIdx >= EnumFacing.VALUES.length) {
            facingIdx = -1;
        }
        IBlockState state = world.getBlockState(connectorPos);
        if (state.getBlock() instanceof ConnectorBlock) {
            CableColor color = state.getValue(GenericCableBlock.COLOR);
            if ((color == CableColor.ROUTING) == routing) {
                foundPos = connectorPos;
                return;
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) CableColor(mcjty.xnet.blocks.generic.CableColor) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Example 5 with ConnectorBlock

use of mcjty.xnet.blocks.cables.ConnectorBlock in project XNet by McJty.

the class RenderWorldLastEventHandler method renderCablesInt.

private static void renderCablesInt(RenderWorldLastEvent evt, Minecraft mc) {
    EntityPlayerSP p = mc.player;
    WorldClient world = mc.world;
    double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * evt.getPartialTicks();
    double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * evt.getPartialTicks();
    double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * evt.getPartialTicks();
    GlStateManager.pushMatrix();
    GlStateManager.color(1.0f, 0, 0);
    GlStateManager.glLineWidth(2);
    GlStateManager.translate(-doubleX, -doubleY, -doubleZ);
    GlStateManager.disableDepth();
    GlStateManager.disableTexture2D();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();
    buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
    for (int dx = -20; dx <= 20; dx++) {
        for (int dy = -20; dy <= 20; dy++) {
            for (int dz = -20; dz <= 20; dz++) {
                BlockPos c = p.getPosition().add(dx, dy, dz);
                IBlockState state = world.getBlockState(c);
                Block block = state.getBlock();
                if (block instanceof FacadeBlock || block instanceof ConnectorBlock || block instanceof GenericCableBlock) {
                    IExtendedBlockState extendedBlockState;
                    if (state.getBlock() instanceof FacadeBlock) {
                        extendedBlockState = (IExtendedBlockState) ((FacadeBlock) state.getBlock()).getStateInternal(state, world, c);
                    } else {
                        extendedBlockState = (IExtendedBlockState) state.getBlock().getExtendedState(state, world, c);
                    }
                    FacadeBlockId facadeId = extendedBlockState.getValue(GenericCableBlock.FACADEID);
                    if (((!GeneralConfiguration.showNonFacadedCablesWhileSneaking) || (!p.isSneaking())) && facadeId == null && !(block instanceof FacadeBlock)) {
                        continue;
                    }
                    CableColor color = extendedBlockState.getValue(GenericCableBlock.COLOR);
                    float r = 0;
                    float g = 0;
                    float b = 0;
                    switch(color) {
                        case BLUE:
                            r = .4f;
                            g = .4f;
                            b = 1f;
                            break;
                        case RED:
                            r = 1f;
                            g = .4f;
                            b = .4f;
                            break;
                        case YELLOW:
                            r = 1f;
                            g = 1f;
                            b = .4f;
                            break;
                        case GREEN:
                            r = .4f;
                            g = 1f;
                            b = .4f;
                            break;
                        case ROUTING:
                            r = .7f;
                            g = .7f;
                            b = .7f;
                            break;
                    }
                    List<Rect> quads = getQuads(extendedBlockState);
                    for (Rect quad : quads) {
                        renderRect(buffer, quad, c, r, g, b, 0.5f);
                    }
                }
            }
        }
    }
    tessellator.draw();
    GlStateManager.enableTexture2D();
    GlStateManager.popMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) IBlockState(net.minecraft.block.state.IBlockState) FacadeBlockId(mcjty.xnet.blocks.facade.FacadeBlockId) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) WorldClient(net.minecraft.client.multiplayer.WorldClient) FacadeBlock(mcjty.xnet.blocks.facade.FacadeBlock) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) FacadeBlock(mcjty.xnet.blocks.facade.FacadeBlock) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) Block(net.minecraft.block.Block) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CableColor(mcjty.xnet.blocks.generic.CableColor) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Aggregations

ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)7 Block (net.minecraft.block.Block)5 IBlockState (net.minecraft.block.state.IBlockState)4 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)3 CableColor (mcjty.xnet.blocks.generic.CableColor)3 EmptyContainer (mcjty.lib.container.EmptyContainer)2 GenericBlock (mcjty.lib.container.GenericBlock)2 FacadeBlockId (mcjty.xnet.blocks.facade.FacadeBlockId)2 GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)2 WorldBlob (mcjty.xnet.multiblock.WorldBlob)2 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)2 EnumFacing (net.minecraft.util.EnumFacing)2 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)2 Function (com.google.common.base.Function)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 XNet (mcjty.xnet.XNet)1