Search in sources :

Example 1 with CableColor

use of mcjty.xnet.blocks.generic.CableColor 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 2 with CableColor

use of mcjty.xnet.blocks.generic.CableColor 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 3 with CableColor

use of mcjty.xnet.blocks.generic.CableColor 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)

Example 4 with CableColor

use of mcjty.xnet.blocks.generic.CableColor in project XNet by McJty.

the class ConnectorBlock method createCableSegment.

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

Example 5 with CableColor

use of mcjty.xnet.blocks.generic.CableColor in project XNet by McJty.

the class FacadeBlock method removedByPlayer.

@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
    CableColor color = state.getValue(COLOR);
    this.onBlockHarvested(world, pos, state, player);
    return world.setBlockState(pos, NetCableSetup.netCableBlock.getDefaultState().withProperty(COLOR, color), world.isRemote ? 11 : 3);
}
Also used : CableColor(mcjty.xnet.blocks.generic.CableColor)

Aggregations

CableColor (mcjty.xnet.blocks.generic.CableColor)5 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)3 IBlockState (net.minecraft.block.state.IBlockState)3 GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)2 WorldBlob (mcjty.xnet.multiblock.WorldBlob)2 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)2 Block (net.minecraft.block.Block)2 BlockPos (net.minecraft.util.math.BlockPos)2 ConsumerId (mcjty.xnet.api.keys.ConsumerId)1 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)1 FacadeBlock (mcjty.xnet.blocks.facade.FacadeBlock)1 FacadeBlockId (mcjty.xnet.blocks.facade.FacadeBlockId)1 ColorId (mcjty.xnet.multiblock.ColorId)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 ItemBlock (net.minecraft.item.ItemBlock)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1