Search in sources :

Example 1 with IAgriFluidComponent

use of com.infinityraider.agricraft.api.v1.misc.IAgriFluidComponent in project AgriCraft by AgriCraft.

the class TileEntityChannelValve method classifyConnection.

@Override
protected byte classifyConnection(@Nonnull EnumFacing side) {
    final Block b = WorldHelper.getBlock(world, pos.offset(side), Block.class).orElse(null);
    final IAgriFluidComponent component = WorldHelper.getTile(world, pos.offset(side), IAgriFluidComponent.class).orElse(null);
    if (b instanceof BlockLever) {
        return -1;
    } else if (component == null) {
        return 0;
    } else if (side.getAxis().isHorizontal()) {
        return 1;
    } else if (component instanceof TileEntitySprinkler) {
        return 2;
    } else {
        return 0;
    }
}
Also used : BlockLever(net.minecraft.block.BlockLever) Block(net.minecraft.block.Block) IAgriFluidComponent(com.infinityraider.agricraft.api.v1.misc.IAgriFluidComponent)

Example 2 with IAgriFluidComponent

use of com.infinityraider.agricraft.api.v1.misc.IAgriFluidComponent in project AgriCraft by AgriCraft.

the class TileEntityChannel method update.

@Override
public void update() {
    // Push down.
    if (this.connections.get(EnumFacing.DOWN) > 0) {
        // Get the component.
        final IAgriFluidComponent component = WorldHelper.getTile(world, pos.offset(EnumFacing.DOWN), IAgriFluidComponent.class).orElse(null);
        // Push all fluid.
        if (component != null) {
            int newFluidAmount = component.acceptFluid(1000, fluidAmount, true, false);
            if (newFluidAmount < 0) {
                throw new AssertionError("A component acccepted too much fluid!");
            }
            this.fluidAmount = newFluidAmount;
        }
    }
    // Push Out.
    for (EnumFacing side : EnumFacing.HORIZONTALS) {
        // Check if connected.
        if (this.connections.get(side) > 0) {
            // Get the component and attempt to push.
            final IAgriFluidComponent component = WorldHelper.getTile(world, pos.offset(side), IAgriFluidComponent.class).orElse(null);
            // If present, do the thing.
            if (component != null) {
                this.pushToComponent(component);
            }
        }
    }
    // If the fluid amount changed then need to do an update?
    if (Math.abs(this.oldFluidAmount - this.fluidAmount) > this.fluidSyncThreshold) {
        // Check the time.
        long currentTime = System.currentTimeMillis();
        // If time is greater than delta, then do sync.
        if (currentTime - this.last_update > fluidSyncTimeout) {
            // Update the old amount.
            this.oldFluidAmount = this.fluidAmount;
            // If on server side, need to tell client.
            if (!this.world.isRemote) {
                new MessageSyncFluidAmount(world, pos, fluidAmount).sendToAll();
            }
        }
    }
    // If the component fluid amount changed, mark this as dirty.
    if (this.fluidAmount != this.oldFluidAmount) {
        this.world.markChunkDirty(pos, this);
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) MessageSyncFluidAmount(com.infinityraider.agricraft.network.MessageSyncFluidAmount) IAgriFluidComponent(com.infinityraider.agricraft.api.v1.misc.IAgriFluidComponent)

Aggregations

IAgriFluidComponent (com.infinityraider.agricraft.api.v1.misc.IAgriFluidComponent)2 MessageSyncFluidAmount (com.infinityraider.agricraft.network.MessageSyncFluidAmount)1 Block (net.minecraft.block.Block)1 BlockLever (net.minecraft.block.BlockLever)1 EnumFacing (net.minecraft.util.EnumFacing)1