Search in sources :

Example 1 with BlockTrackFlex

use of mods.railcraft.common.blocks.tracks.flex.BlockTrackFlex in project Railcraft by Railcraft.

the class ItemTrackKit method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    playerIn.swingArm(hand);
    if (Game.isClient(worldIn))
        return EnumActionResult.PASS;
    IBlockState oldState = WorldPlugin.getBlockState(worldIn, pos);
    if (!TrackTools.isRailBlock(oldState)) {
        return EnumActionResult.PASS;
    }
    TrackType trackType = null;
    if (oldState.getBlock() instanceof BlockTrackFlex) {
        BlockTrackFlex track = (BlockTrackFlex) oldState.getBlock();
        trackType = track.getTrackType(worldIn, pos);
    } else if (oldState.getBlock() == Blocks.RAIL) {
        trackType = TrackTypes.IRON.getTrackType();
    }
    if (trackType != null) {
        BlockRailBase.EnumRailDirection shape = TrackTools.getTrackDirectionRaw(worldIn, pos);
        if (TrackShapeHelper.isStraight(shape)) {
            TrackKit trackKit = TrackRegistry.TRACK_KIT.get(stack);
            if (!shape.isAscending() || trackKit.isAllowedOnSlopes()) {
                if (!trackKit.isAllowedTrackType(trackType)) {
                    ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.track_type");
                    return EnumActionResult.PASS;
                }
                if (BlockTrackOutfitted.placeTrack(worldIn, pos, playerIn, shape, trackType, trackKit)) {
                    SoundHelper.playPlaceSoundForBlock(worldIn, pos);
                    stack.stackSize--;
                    return EnumActionResult.SUCCESS;
                }
            } else {
                ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.slope");
            }
        } else {
            ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.curve");
        }
    } else {
        ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.track_kit.item.invalid.track");
    }
    return EnumActionResult.PASS;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TrackType(mods.railcraft.api.tracks.TrackType) BlockTrackFlex(mods.railcraft.common.blocks.tracks.flex.BlockTrackFlex) BlockRailBase(net.minecraft.block.BlockRailBase) TrackKit(mods.railcraft.api.tracks.TrackKit)

Aggregations

TrackKit (mods.railcraft.api.tracks.TrackKit)1 TrackType (mods.railcraft.api.tracks.TrackType)1 BlockTrackFlex (mods.railcraft.common.blocks.tracks.flex.BlockTrackFlex)1 BlockRailBase (net.minecraft.block.BlockRailBase)1 IBlockState (net.minecraft.block.state.IBlockState)1