| 26 | import java.util.Set; |
| 27 | |
| 28 | public final class TimelessAPI { |
| 29 | @OnlyIn(Dist.CLIENT) |
| 30 | public static Optional<GunDisplayInstance> getGunDisplay(ItemStack stack) { |
| 31 | if (stack.getItem() instanceof IGun iGun) { |
| 32 | ResourceLocation gunId = iGun.getGunId(stack); |
| 33 | if (getCommonGunIndex(gunId).isEmpty()) { |
| 34 | return Optional.empty(); |
| 35 | } |
| 36 | ResourceLocation displayId = iGun.getGunDisplayId(stack); |
| 37 | if (displayId.equals(DefaultAssets.DEFAULT_GUN_DISPLAY_ID)) { |
| 38 | return getClientGunIndex(gunId).map(ClientGunIndex::getDefaultDisplay); |
| 39 | } else { |
| 40 | return getGunDisplay(displayId, gunId); |
| 41 | } |
| 42 | } |
| 43 | return Optional.empty(); |
| 44 | } |
| 45 | |
| 46 | @OnlyIn(Dist.CLIENT) |
| 47 | public static Optional<ClientGunIndex> getClientGunIndex(ResourceLocation gunId) { |
| 48 | return Optional.ofNullable(ClientIndexManager.GUN_INDEX.get(gunId)); |
| 49 | } |
| 50 | |
| 51 | @OnlyIn(Dist.CLIENT) |
| 52 | public static Optional<GunDisplayInstance> getGunDisplay(ResourceLocation displayId, ResourceLocation fallbackGunId) { |
| 53 | if (displayId == null || displayId.equals(DefaultAssets.DEFAULT_GUN_DISPLAY_ID)) { |
| 54 | return getClientGunIndex(fallbackGunId).map(ClientGunIndex::getDefaultDisplay); |
| 55 | } |
| 56 | |
| 57 | GunDisplayInstance instance = ClientIndexManager.getOrCreateGunDisplay(displayId); |
| 58 | if (instance == null) { |
| 59 | return getClientGunIndex(fallbackGunId).map(ClientGunIndex::getDefaultDisplay); |
| 60 | } |
| 61 | return Optional.of(instance); |
| 62 | } |
| 63 | |
| 64 | @OnlyIn(Dist.CLIENT) |
| 65 | public static Optional<ClientAttachmentIndex> getClientAttachmentIndex(ResourceLocation attachmentId) { |
| 66 | return Optional.ofNullable(ClientIndexManager.ATTACHMENT_INDEX.get(attachmentId)); |
| 67 | } |
| 68 | |
| 69 | @OnlyIn(Dist.CLIENT) |
| 70 | public static Optional<ClientAmmoIndex> getClientAmmoIndex(ResourceLocation ammoId) { |
| 71 | return Optional.ofNullable(ClientIndexManager.AMMO_INDEX.get(ammoId)); |
| 72 | } |
| 73 | |
| 74 | @OnlyIn(Dist.CLIENT) |
| 75 | public static Optional<ClientBlockIndex> getClientBlockIndex(ResourceLocation blockId) { |
| 76 | return Optional.ofNullable(ClientIndexManager.BLOCK_INDEX.get(blockId)); |
| 77 | } |
| 78 | |
| 79 | @OnlyIn(Dist.CLIENT) |
| 80 | public static Set<Map.Entry<ResourceLocation, ClientGunIndex>> getAllClientGunIndex() { |
| 81 | return ClientIndexManager.getAllGuns(); |
| 82 | } |
| 83 | |
| 84 | @OnlyIn(Dist.CLIENT) |
| 85 | public static Set<Map.Entry<ResourceLocation, ClientAmmoIndex>> getAllClientAmmoIndex() { |
nothing calls this directly
no outgoing calls
no test coverage detected