terra-items 0.4.0

Crate with enum contatining terraria items and prefixes
Documentation
use super::Item;
use std::{mem, ops::RangeInclusive};

const ID_RANGE: RangeInclusive<i32> = 1..=6144;

impl super::Item {
	pub fn to_id(self, version: i32) -> i32 {
		let id = self as i32;
		if version > 146 {
			return id;
		}

		match id {
			3769 => -24,
			3768 => -23,
			3767 => -22,
			3766 => -21,
			3765 => -20,
			3764 => -19,
			3480 => -48,
			3481 => -47,
			3482 => -46,
			3483 => -45,
			3484 => -44,
			3485 => -43,
			3486 => -42,
			3487 => -41,
			3488 => -40,
			3489 => -39,
			3490 => -38,
			3491 => -37,
			3492 => -36,
			3493 => -35,
			3494 => -34,
			3495 => -33,
			3496 => -32,
			3497 => -31,
			3498 => -30,
			3499 => -29,
			3500 => -28,
			3501 => -27,
			3502 => -26,
			3503 => -25,
			3504 => -18,
			3505 => -17,
			3506 => -16,
			3507 => -15,
			3508 => -14,
			3509 => -13,
			3510 => -12,
			3511 => -11,
			3512 => -10,
			3513 => -9,
			3514 => -8,
			3515 => -7,
			3516 => -6,
			3517 => -5,
			3518 => -4,
			3519 => -3,
			3520 => -2,
			3521 => -1,
			_ => id,
		}
	}

	pub fn from_id(id: i32) -> Option<Self> {
		let id = match id {
			-24 => 3769,
			-23 => 3768,
			-22 => 3767,
			-21 => 3766,
			-20 => 3765,
			-19 => 3764,
			-48 => 3480,
			-47 => 3481,
			-46 => 3482,
			-45 => 3483,
			-44 => 3484,
			-43 => 3485,
			-42 => 3486,
			-41 => 3487,
			-40 => 3488,
			-39 => 3489,
			-38 => 3490,
			-37 => 3491,
			-36 => 3492,
			-35 => 3493,
			-34 => 3494,
			-33 => 3495,
			-32 => 3496,
			-31 => 3497,
			-30 => 3498,
			-29 => 3499,
			-28 => 3500,
			-27 => 3501,
			-26 => 3502,
			-25 => 3503,
			-18 => 3504,
			-17 => 3505,
			-16 => 3506,
			-15 => 3507,
			-14 => 3508,
			-13 => 3509,
			-12 => 3510,
			-11 => 3511,
			-10 => 3512,
			-9 => 3513,
			-8 => 3514,
			-7 => 3515,
			-6 => 3516,
			-5 => 3517,
			-4 => 3518,
			-3 => 3519,
			-2 => 3520,
			-1 => 3521,
			_ => id,
		};

		if !ID_RANGE.contains(&id) {
			return None;
		}

		Some(unsafe { mem::transmute::<i32, Item>(id) })
	}
}