Search in sources :

Example 1 with IOutfittedTrackTile

use of mods.railcraft.api.tracks.IOutfittedTrackTile in project Railcraft by Railcraft.

the class EntityCartTrackRelayer method replace.

private void replace() {
    BlockPos pos = getPosition();
    if (TrackTools.isRailBlockAt(worldObj, pos.down()))
        pos = pos.down();
    Block block = WorldPlugin.getBlock(worldObj, pos);
    if (TrackTools.isRailBlock(block)) {
        ItemStack trackExist = patternInv.getStackInSlot(SLOT_EXIST);
        ItemStack trackStock = getStackInSlot(SLOT_STOCK);
        boolean nextToSuspended = false;
        for (EnumFacing side : EnumSet.of(EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH)) {
            TileEntity tile = WorldPlugin.getBlockTile(worldObj, pos.offset(side));
            if (tile instanceof IOutfittedTrackTile) {
                IOutfittedTrackTile track = (IOutfittedTrackTile) tile;
                if (track.getTrackKitInstance() instanceof TrackKitSuspended) {
                    nextToSuspended = true;
                    break;
                }
            }
        }
        if (nextToSuspended)
            return;
        if (trackExist != null && trackStock != null)
            if (trackExist.getItem() instanceof ITrackItem) {
                ITrackItem trackItem = (ITrackItem) trackExist.getItem();
                if (trackItem.getPlacedBlock() == block) {
                    TileEntity tile = worldObj.getTileEntity(pos);
                    if (trackItem.isPlacedTileEntity(trackExist, tile)) {
                        BlockRailBase.EnumRailDirection trackShape = removeOldTrack(pos, block);
                        placeNewTrack(pos, SLOT_STOCK, trackShape);
                    }
                }
            } else if (InvTools.isStackEqualToBlock(trackExist, block)) {
                BlockRailBase.EnumRailDirection trackShape = removeOldTrack(pos, block);
                placeNewTrack(pos, SLOT_STOCK, trackShape);
            }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TrackKitSuspended(mods.railcraft.common.blocks.tracks.outfitted.kits.TrackKitSuspended) IOutfittedTrackTile(mods.railcraft.api.tracks.IOutfittedTrackTile) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ITrackItem(mods.railcraft.api.core.items.ITrackItem) ItemStack(net.minecraft.item.ItemStack) BlockRailBase(net.minecraft.block.BlockRailBase)

Aggregations

ITrackItem (mods.railcraft.api.core.items.ITrackItem)1 IOutfittedTrackTile (mods.railcraft.api.tracks.IOutfittedTrackTile)1 TrackKitSuspended (mods.railcraft.common.blocks.tracks.outfitted.kits.TrackKitSuspended)1 Block (net.minecraft.block.Block)1 BlockRailBase (net.minecraft.block.BlockRailBase)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1