|
| 1 | +/* |
| 2 | + * Numismatics |
| 3 | + * Copyright (c) 2024 The Railways Team |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +package dev.ithundxr.createnumismatics.compat.computercraft.implementation.fabric; |
| 20 | + |
| 21 | +import com.google.common.collect.ImmutableMap; |
| 22 | +import dan200.computercraft.api.detail.VanillaDetailRegistries; |
| 23 | +import dan200.computercraft.api.peripheral.PeripheralLookup; |
| 24 | +import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy; |
| 25 | +import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour; |
| 26 | +import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.BankTerminalPeripheral; |
| 27 | +import dev.ithundxr.createnumismatics.content.bank.AuthorizedCardItem; |
| 28 | +import dev.ithundxr.createnumismatics.content.bank.CardItem; |
| 29 | +import dev.ithundxr.createnumismatics.content.bank.IDCardItem; |
| 30 | +import dev.ithundxr.createnumismatics.registry.NumismaticsBlocks; |
| 31 | +import dev.ithundxr.createnumismatics.registry.NumismaticsTags; |
| 32 | +import dev.ithundxr.createnumismatics.util.Utils; |
| 33 | +import net.minecraft.core.registries.Registries; |
| 34 | +import org.jetbrains.annotations.Nullable; |
| 35 | + |
| 36 | +import java.util.Map; |
| 37 | +import java.util.UUID; |
| 38 | + |
| 39 | +public class ActualComputerCraftProxyImpl { |
| 40 | + public static void registerWithDependency() { |
| 41 | + /* Comment if computercraft.implementation is not in the source set */ |
| 42 | + ComputerCraftProxy.computerFactory = ComputerBehaviour::new; |
| 43 | + |
| 44 | + PeripheralLookup.get().registerFallback((level, blockPos, blockState, blockEntity, direction) -> ComputerBehaviour.peripheralProvider(level, blockPos)); |
| 45 | + |
| 46 | + Utils.runOnceRegistered(Registries.BLOCK, () -> { |
| 47 | + PeripheralLookup.get().registerForBlocks( |
| 48 | + (world, pos, state, blockEntity, context) -> BankTerminalPeripheral.INSTANCE, |
| 49 | + NumismaticsBlocks.BANK_TERMINAL.get() |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + VanillaDetailRegistries.ITEM_STACK.addProvider((detailMap, stack) -> { |
| 54 | + Map<Object, @Nullable Object> cardDetails = null; |
| 55 | + if (NumismaticsTags.AllItemTags.CARDS.matches(stack)) { |
| 56 | + UUID accountID = CardItem.get(stack); |
| 57 | + if (accountID != null) { |
| 58 | + cardDetails = Map.of( |
| 59 | + "AccountID", accountID.toString() |
| 60 | + ); |
| 61 | + } |
| 62 | + } else if (NumismaticsTags.AllItemTags.AUTHORIZED_CARDS.matches(stack)) { |
| 63 | + AuthorizedCardItem.AuthorizationPair authorizationPair = AuthorizedCardItem.get(stack); |
| 64 | + if (authorizationPair != null) { |
| 65 | + UUID accountID = authorizationPair.accountID(); |
| 66 | + UUID authorizationID = authorizationPair.authorizationID(); |
| 67 | + cardDetails = Map.of( |
| 68 | + "AccountID", accountID.toString(), |
| 69 | + "AuthorizationID", authorizationID.toString() |
| 70 | + ); |
| 71 | + } |
| 72 | + } else if (NumismaticsTags.AllItemTags.ID_CARDS.matches(stack)) { |
| 73 | + UUID id = IDCardItem.get(stack); |
| 74 | + if (id != null) { |
| 75 | + cardDetails = Map.of( |
| 76 | + "ID", id.toString() |
| 77 | + ); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + if (cardDetails != null) |
| 82 | + detailMap.put("numismatics", ImmutableMap.of("card", cardDetails)); |
| 83 | + }); |
| 84 | + } |
| 85 | +} |
0 commit comments