Search in sources :

Example 1 with TileMultiBlock

use of mods.railcraft.common.blocks.machine.TileMultiBlock in project Railcraft by Railcraft.

the class TileTankIronValve method update.

@Override
public void update() {
    super.update();
    if (Game.isClient(worldObj))
        return;
    decrementFilling();
    if (isMaster) {
        TileEntity tileBelow = tileCache.getTileOnSide(EnumFacing.DOWN);
        TileTankIronValve valveBelow = null;
        if (tileBelow instanceof TileTankIronValve) {
            valveBelow = (TileTankIronValve) tileBelow;
            if (valveBelow.isStructureValid() && valveBelow.getPatternMarker() == 'T') {
                //noinspection ConstantConditions
                StandardTank tankBelow = valveBelow.getTankManager().get(0);
                assert tankBelow != null;
                FluidStack liquid = tankBelow.getFluid();
                if (liquid != null && liquid.amount >= tankBelow.getCapacity() - FluidTools.BUCKET_VOLUME) {
                    valveBelow = null;
                    FluidStack fillStack = liquid.copy();
                    fillStack.amount = FluidTools.BUCKET_VOLUME - (tankBelow.getCapacity() - liquid.amount);
                    if (fillStack.amount > 0) {
                        int used = tank.fill(fillStack, false);
                        if (used > 0) {
                            fillStack = tankBelow.drain(used, true);
                            tank.fill(fillStack, true);
                        }
                    }
                }
            } else
                valveBelow = null;
        }
        if (valveBelow != null) {
            FluidStack available = tankManager.drain(0, FluidTools.BUCKET_VOLUME, false);
            if (available != null && available.amount > 0) {
                int used = valveBelow.fill(available, true);
                tankManager.drain(0, used, true);
            }
        }
    }
    if (getPatternPosition().getY() - getPattern().getMasterOffset().getY() == 0) {
        TankManager tMan = getTankManager();
        if (tMan != null)
            tMan.push(tileCache, Predicates.notInstanceOf(TileTankBase.class), FLUID_OUTPUTS, 0, FLOW_RATE);
    }
    TileMultiBlock masterBlock = getMasterBlock();
    if (masterBlock instanceof TileTankBase) {
        TileTankBase masterTileTankBase = (TileTankBase) masterBlock;
        int compValue = masterTileTankBase.getComparatorValue();
        if (previousComparatorValue != compValue) {
            previousComparatorValue = compValue;
            getWorld().notifyNeighborsOfStateChange(getPos(), null);
        }
    }
    if (previousStructureValidity != isStructureValid())
        getWorld().notifyNeighborsOfStateChange(getPos(), null);
    previousStructureValidity = isStructureValid();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileMultiBlock(mods.railcraft.common.blocks.machine.TileMultiBlock) FluidStack(net.minecraftforge.fluids.FluidStack) TankManager(mods.railcraft.common.fluids.TankManager) StandardTank(mods.railcraft.common.fluids.tanks.StandardTank)

Example 2 with TileMultiBlock

use of mods.railcraft.common.blocks.machine.TileMultiBlock in project Railcraft by Railcraft.

the class TileTankBase method isMapPositionValid.

@Override
protected boolean isMapPositionValid(BlockPos pos, char mapPos) {
    IBlockState state = WorldPlugin.getBlockState(worldObj, getPos());
    Block block = state.getBlock();
    int meta = block.getMetaFromState(state);
    switch(mapPos) {
        case // Other
        'O':
            {
                if (block == getBlockType()) {
                    if (getTankType().isTankBlock(meta))
                        return false;
                }
                return true;
            }
        case // Gauge or Valve
        'W':
            {
                return block == getBlockType() && getTankType().isTankBlock(meta);
            }
        case // Block
        'B':
            {
                return block == getBlockType() && getTankType().isWallBlock(meta);
            }
        // Master
        case 'M':
        case // Top Block
        'T':
            {
                if (block != getBlockType())
                    return false;
                if (!getTankType().isTankBlock(meta))
                    return false;
                TileEntity tile = worldObj.getTileEntity(getPos());
                if (!(tile instanceof TileMultiBlock)) {
                    worldObj.removeTileEntity(getPos());
                    return true;
                }
                return !((TileMultiBlock) tile).isStructureValid();
            }
        case // Air
        'A':
            {
                return worldObj.isAirBlock(getPos());
            }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) TileMultiBlock(mods.railcraft.common.blocks.machine.TileMultiBlock) Block(net.minecraft.block.Block) TileMultiBlock(mods.railcraft.common.blocks.machine.TileMultiBlock)

Example 3 with TileMultiBlock

use of mods.railcraft.common.blocks.machine.TileMultiBlock in project Railcraft by Railcraft.

the class ItemMagnifyingGlass method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (Game.isClient(world))
        return EnumActionResult.PASS;
    TileEntity t = world.getTileEntity(pos);
    EnumActionResult returnValue = EnumActionResult.PASS;
    if (t instanceof IOwnable) {
        IOwnable ownable = (IOwnable) t;
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.placedby", ownable.getDisplayName(), ownable.getOwner());
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof TileMultiBlock) {
        TileMultiBlock tile = (TileMultiBlock) t;
        if (tile.isStructureValid())
            ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
        else
            for (MultiBlockStateReturn returnState : EnumSet.complementOf(EnumSet.of(MultiBlockStateReturn.VALID))) {
                List<Integer> pats = tile.patternStates.get(returnState);
                if (!pats.isEmpty())
                    ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, pats.toString());
            }
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof IDualHeadSignal) {
        IDualHeadSignal signal = (IDualHeadSignal) t;
        SignalAspect top = signal.getSignalAspect(DualLamp.TOP);
        SignalAspect bottom = signal.getSignalAspect(DualLamp.BOTTOM);
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect.dual", top.getLocalizationTag(), bottom.getLocalizationTag());
        returnValue = EnumActionResult.SUCCESS;
    } else if (t instanceof TileSignalBase) {
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect", ((TileSignalBase) t).getSignalAspect().getLocalizationTag());
        returnValue = EnumActionResult.SUCCESS;
    }
    return returnValue;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SignalAspect(mods.railcraft.api.signals.SignalAspect) EnumActionResult(net.minecraft.util.EnumActionResult) TileMultiBlock(mods.railcraft.common.blocks.machine.TileMultiBlock) MultiBlockStateReturn(mods.railcraft.common.blocks.machine.TileMultiBlock.MultiBlockStateReturn) IDualHeadSignal(mods.railcraft.common.blocks.wayobjects.IDualHeadSignal) TileSignalBase(mods.railcraft.common.blocks.wayobjects.TileSignalBase) IOwnable(mods.railcraft.api.core.IOwnable) List(java.util.List)

Aggregations

TileMultiBlock (mods.railcraft.common.blocks.machine.TileMultiBlock)3 TileEntity (net.minecraft.tileentity.TileEntity)3 List (java.util.List)1 IOwnable (mods.railcraft.api.core.IOwnable)1 SignalAspect (mods.railcraft.api.signals.SignalAspect)1 MultiBlockStateReturn (mods.railcraft.common.blocks.machine.TileMultiBlock.MultiBlockStateReturn)1 IDualHeadSignal (mods.railcraft.common.blocks.wayobjects.IDualHeadSignal)1 TileSignalBase (mods.railcraft.common.blocks.wayobjects.TileSignalBase)1 TankManager (mods.railcraft.common.fluids.TankManager)1 StandardTank (mods.railcraft.common.fluids.tanks.StandardTank)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 FluidStack (net.minecraftforge.fluids.FluidStack)1