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;
}
Aggregations