Search in sources :

Example 1 with IBufferTransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.

the class FluidNetwork method refreshAcceptors.

public void refreshAcceptors() {
    if (this.acceptors == null) {
        this.acceptors = Maps.newHashMap();
    } else {
        this.acceptors.clear();
    }
    try {
        Iterator<IBufferTransmitter<FluidStack>> it = this.pipes.iterator();
        while (it.hasNext()) {
            IBufferTransmitter<FluidStack> transmitter = it.next();
            TileEntity tile = (TileEntity) transmitter;
            if (transmitter == null || tile.isInvalid() || tile.getWorld() == null) {
                it.remove();
                continue;
            }
            if (!transmitter.canTransmit()) {
                continue;
            }
            int i = 0;
            for (TileEntity acceptor : transmitter.getAdjacentConnections()) {
                if (!(acceptor instanceof IBufferTransmitter) && acceptor instanceof IFluidHandler) {
                    EnumFacing facing = EnumFacing.getFront(i).getOpposite();
                    BlockPos acceptorPos = tile.getPos().offset(facing.getOpposite());
                    EnumSet<EnumFacing> facingSet = this.acceptorDirections.get(acceptorPos);
                    if (facingSet != null) {
                        facingSet.add(facing);
                    } else {
                        facingSet = EnumSet.of(facing);
                    }
                    this.acceptors.put(acceptorPos, (IFluidHandler) acceptor);
                    this.acceptorDirections.put(acceptorPos, facingSet);
                }
                i++;
            }
        }
    } catch (Exception e) {
        FMLLog.severe("Failed to refresh liquid acceptors");
        e.printStackTrace();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) BlockPos(net.minecraft.util.BlockPos) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 2 with IBufferTransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.

the class FluidNetwork method refresh.

@Override
public void refresh() {
    if (this.acceptors != null) {
        this.acceptors.clear();
    }
    try {
        Iterator<IBufferTransmitter<FluidStack>> it = this.pipes.iterator();
        while (it.hasNext()) {
            ITransmitter transmitter = it.next();
            TileEntity tileTransmitter = (TileEntity) transmitter;
            if (transmitter == null) {
                it.remove();
                continue;
            }
            transmitter.onNetworkChanged();
            if (tileTransmitter.isInvalid() || tileTransmitter.getWorld() == null) {
                it.remove();
                continue;
            } else {
                if (this.worldObj == null) {
                    this.worldObj = tileTransmitter.getWorld();
                }
                transmitter.setNetwork(this);
            }
        }
        updateCapacity();
        clamp();
    } catch (Exception e) {
        FMLLog.severe("Failed to refresh liquid pipe network.");
        e.printStackTrace();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter)

Example 3 with IBufferTransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.

the class TileEntityFluidPipeRenderer method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityFluidPipe pipe, double x, double y, double z, float partialTicks, int destroyStage) {
    updateModels();
    if (pipe.getBlockType() == GCBlocks.oxygenPipePull) {
        GL11.glPushMatrix();
        GL11.glTranslatef((float) x, (float) y, (float) z);
        RenderHelper.disableStandardItemLighting();
        this.bindTexture(TextureMap.locationBlocksTexture);
        if (Minecraft.isAmbientOcclusionEnabled()) {
            GlStateManager.shadeModel(GL11.GL_SMOOTH);
        } else {
            GlStateManager.shadeModel(GL11.GL_FLAT);
        }
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        TileEntity[] adj = OxygenUtil.getAdjacentFluidConnections(pipe);
        for (EnumFacing facing : EnumFacing.VALUES) {
            TileEntity sideTile = adj[facing.ordinal()];
            if (sideTile != null && !(sideTile instanceof IBufferTransmitter)) {
                GL11.glPushMatrix();
                if (sideTile instanceof TileEntityFluidTank)
                    switch(facing) {
                        case SOUTH:
                            GL11.glTranslatef(0F, 0F, 1 / 16F);
                            break;
                        case NORTH:
                            GL11.glTranslatef(0F, 0F, -1 / 16F);
                            break;
                        case EAST:
                            GL11.glTranslatef(1 / 16F, 0F, 0F);
                            break;
                        case WEST:
                            GL11.glTranslatef(-1 / 16F, 0F, 0F);
                            break;
                    }
                ClientUtil.drawBakedModel(pullConnectorModel[facing.ordinal()]);
                GL11.glPopMatrix();
            }
        }
        GL11.glPopMatrix();
    }
    float scale;
    if (pipe.hasNetwork()) {
        FluidNetwork network = (FluidNetwork) pipe.getNetwork();
        scale = network.fluidScale;
    } else {
        scale = pipe.buffer.getFluidAmount() / (float) pipe.buffer.getCapacity();
    }
    Fluid fluid;
    if (pipe.hasNetwork()) {
        FluidNetwork network = (FluidNetwork) pipe.getNetwork();
        fluid = network.refFluid;
    } else {
        fluid = pipe.getBuffer() == null ? null : pipe.getBuffer().getFluid();
    }
    if (fluid == null) {
        return;
    }
    if (scale > 0.01) {
        this.bindTexture(TextureMap.locationBlocksTexture);
        GL11.glPushMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        GlStateManager.disableLighting();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        float opacity = 1.0F;
        boolean gas = fluid.isGaseous();
        if (gas) {
            opacity = scale;
        }
        GL11.glColor4f(1.0F, 1.0F, 1.0F, opacity);
        TileEntity[] connections = OxygenUtil.getAdjacentFluidConnections(pipe);
        for (EnumFacing side : EnumFacing.VALUES) {
            TileEntity sideTile = connections[side.ordinal()];
            if (sideTile != null) {
                Integer[] displayLists = getListAndRender(side, fluid);
                if (displayLists != null) {
                    if (!gas) {
                        Integer list = displayLists[Math.max(3, (int) (scale * (stages - 1)))];
                        GL11.glCallList(list);
                    } else {
                        Integer list = displayLists[stages - 1];
                        GL11.glCallList(list);
                    }
                }
            }
        }
        Integer[] displayLists = getListAndRender(null, fluid);
        if (displayLists != null) {
            if (!gas) {
                Integer list = displayLists[Math.max(3, (int) (scale * (stages - 1)))];
                GL11.glCallList(list);
            } else {
                Integer list = displayLists[stages - 1];
                GL11.glCallList(list);
            }
        }
        GlStateManager.enableLighting();
        GlStateManager.disableBlend();
        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) EnumFacing(net.minecraft.util.EnumFacing) Fluid(net.minecraftforge.fluids.Fluid) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)

Example 4 with IBufferTransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.

the class PacketFluidNetworkUpdate method encodeInto.

@Override
public void encodeInto(ByteBuf buffer) {
    super.encodeInto(buffer);
    buffer.writeInt(this.pos.getX());
    buffer.writeInt(this.pos.getY());
    buffer.writeInt(this.pos.getZ());
    buffer.writeInt(this.type.ordinal());
    switch(this.type) {
        case ADD_TRANSMITTER:
            buffer.writeBoolean(this.newNetwork);
            buffer.writeInt(this.transmittersAdded.size());
            for (IBufferTransmitter transmitter : this.transmittersAdded) {
                TileEntity tile = (TileEntity) transmitter;
                buffer.writeInt(tile.getPos().getX());
                buffer.writeInt(tile.getPos().getY());
                buffer.writeInt(tile.getPos().getZ());
            }
            break;
        case FLUID:
            if (this.stack != null) {
                buffer.writeBoolean(true);
                ByteBufUtils.writeUTF8String(buffer, FluidRegistry.getFluidName(this.stack));
                buffer.writeInt(this.stack.amount);
            } else {
                buffer.writeBoolean(false);
            }
            buffer.writeBoolean(this.didTransfer);
            break;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)

Example 5 with IBufferTransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.

the class PacketFluidNetworkUpdate method handleClientSide.

@Override
public void handleClientSide(EntityPlayer player) {
    TileEntity tile = player.worldObj.getTileEntity(this.pos);
    if (tile instanceof IBufferTransmitter) {
        IBufferTransmitter<FluidStack> transmitter = (IBufferTransmitter<FluidStack>) tile;
        switch(this.type) {
            case ADD_TRANSMITTER:
                {
                    FluidNetwork network = transmitter.hasNetwork() && !this.newNetwork ? (FluidNetwork) transmitter.getNetwork() : new FluidNetwork();
                    network.register();
                    transmitter.setNetwork(network);
                    for (BlockPos pos : this.transmittersCoords) {
                        TileEntity transmitterTile = player.worldObj.getTileEntity(pos);
                        if (transmitterTile instanceof IBufferTransmitter) {
                            ((IBufferTransmitter) transmitterTile).setNetwork(network);
                        }
                    }
                    network.updateCapacity();
                }
                break;
            case FLUID:
                if (transmitter.getNetwork() != null) {
                    FluidNetwork network = (FluidNetwork) transmitter.getNetwork();
                    if (this.fluidType != null) {
                        network.refFluid = this.fluidType;
                    }
                    network.buffer = this.stack;
                    network.didTransfer = this.didTransfer;
                }
                break;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) FluidStack(net.minecraftforge.fluids.FluidStack) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) BlockPos(net.minecraft.util.BlockPos)

Aggregations

IBufferTransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)7 TileEntity (net.minecraft.tileentity.TileEntity)7 FluidStack (net.minecraftforge.fluids.FluidStack)4 EnumFacing (net.minecraft.util.EnumFacing)3 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)2 BlockPos (net.minecraft.util.BlockPos)2 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)2 Pathfinder (micdoodle8.mods.galacticraft.api.transmission.grid.Pathfinder)1 PathfinderChecker (micdoodle8.mods.galacticraft.api.transmission.grid.PathfinderChecker)1 INetworkConnection (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection)1 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)1 ITransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 BlockFluidPipe (micdoodle8.mods.galacticraft.core.blocks.BlockFluidPipe)1 TileEntityFluidTank (micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)1 Block (net.minecraft.block.Block)1 Fluid (net.minecraftforge.fluids.Fluid)1