Skip to content

Commit 50d817f

Browse files
committed
fix: computer craft compat no longer crashes when CC is not present
1 parent 09d74f6 commit 50d817f

File tree

7 files changed

+202
-131
lines changed

7 files changed

+202
-131
lines changed

changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
------------------------------------------------------
2-
Numismatics 1.0.7
2+
Numismatics 1.1.0
33
------------------------------------------------------
44
Additions
55
- Computer Craft: Tweaked compat for vendors and brass depositors

common/src/main/java/dev/ithundxr/createnumismatics/compat/computercraft/ComputerCraftProxy.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
2424
import dev.architectury.injectables.annotations.ExpectPlatform;
2525
import dev.ithundxr.createnumismatics.compat.Mods;
26+
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ActualComputerCraftProxy;
2627
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.Details;
2728
import dev.ithundxr.createnumismatics.multiloader.fluid.MultiloaderFluidStack;
2829
import net.minecraft.world.item.ItemStack;
@@ -33,12 +34,7 @@
3334
public class ComputerCraftProxy {
3435
public static void register() {
3536
fallbackFactory = FallbackComputerBehaviour::new;
36-
Mods.COMPUTERCRAFT.executeIfInstalled(() -> ComputerCraftProxy::registerWithDependency);
37-
}
38-
39-
@ExpectPlatform
40-
static void registerWithDependency() {
41-
throw new AssertionError();
37+
Mods.COMPUTERCRAFT.executeIfInstalled(() -> ActualComputerCraftProxy::registerWithDependency);
4238
}
4339

4440
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> fallbackFactory;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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;
20+
21+
import dev.architectury.injectables.annotations.ExpectPlatform;
22+
23+
public class ActualComputerCraftProxy {
24+
@ExpectPlatform
25+
public static void registerWithDependency() {
26+
throw new AssertionError();
27+
}
28+
}

fabric/src/main/java/dev/ithundxr/createnumismatics/compat/computercraft/fabric/ComputerCraftProxyImpl.java

-62
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,11 @@
1818

1919
package dev.ithundxr.createnumismatics.compat.computercraft.fabric;
2020

21-
import com.google.common.collect.ImmutableMap;
2221
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour;
2322
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
24-
import dan200.computercraft.api.detail.VanillaDetailRegistries;
25-
import dan200.computercraft.api.peripheral.PeripheralLookup;
2623
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy;
27-
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour;
28-
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.BankTerminalPeripheral;
29-
import dev.ithundxr.createnumismatics.content.bank.AuthorizedCardItem;
30-
import dev.ithundxr.createnumismatics.content.bank.CardItem;
31-
import dev.ithundxr.createnumismatics.content.bank.IDCardItem;
32-
import dev.ithundxr.createnumismatics.registry.NumismaticsBlocks;
33-
import dev.ithundxr.createnumismatics.registry.NumismaticsTags;
34-
import dev.ithundxr.createnumismatics.util.Utils;
35-
import net.minecraft.core.registries.Registries;
36-
import org.jetbrains.annotations.Nullable;
37-
38-
import java.util.Map;
39-
import java.util.UUID;
4024

4125
public class ComputerCraftProxyImpl {
42-
public static void registerWithDependency() {
43-
/* Comment if computercraft.implementation is not in the source set */
44-
ComputerCraftProxy.computerFactory = ComputerBehaviour::new;
45-
46-
PeripheralLookup.get().registerFallback((level, blockPos, blockState, blockEntity, direction) -> ComputerBehaviour.peripheralProvider(level, blockPos));
47-
48-
Utils.runOnceRegistered(Registries.BLOCK, () -> {
49-
PeripheralLookup.get().registerForBlocks(
50-
(world, pos, state, blockEntity, context) -> BankTerminalPeripheral.INSTANCE,
51-
NumismaticsBlocks.BANK_TERMINAL.get()
52-
);
53-
});
54-
55-
VanillaDetailRegistries.ITEM_STACK.addProvider((detailMap, stack) -> {
56-
Map<Object, @Nullable Object> cardDetails = null;
57-
if (NumismaticsTags.AllItemTags.CARDS.matches(stack)) {
58-
UUID accountID = CardItem.get(stack);
59-
if (accountID != null) {
60-
cardDetails = Map.of(
61-
"AccountID", accountID.toString()
62-
);
63-
}
64-
} else if (NumismaticsTags.AllItemTags.AUTHORIZED_CARDS.matches(stack)) {
65-
AuthorizedCardItem.AuthorizationPair authorizationPair = AuthorizedCardItem.get(stack);
66-
if (authorizationPair != null) {
67-
UUID accountID = authorizationPair.accountID();
68-
UUID authorizationID = authorizationPair.authorizationID();
69-
cardDetails = Map.of(
70-
"AccountID", accountID.toString(),
71-
"AuthorizationID", authorizationID.toString()
72-
);
73-
}
74-
} else if (NumismaticsTags.AllItemTags.ID_CARDS.matches(stack)) {
75-
UUID id = IDCardItem.get(stack);
76-
if (id != null) {
77-
cardDetails = Map.of(
78-
"ID", id.toString()
79-
);
80-
}
81-
}
82-
83-
if (cardDetails != null)
84-
detailMap.put("numismatics", ImmutableMap.of("card", cardDetails));
85-
});
86-
}
87-
8826
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) {
8927
if (ComputerCraftProxy.computerFactory == null)
9028
return ComputerCraftProxy.fallbackFactory.apply(sbe);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}

forge/src/main/java/dev/ithundxr/createnumismatics/compat/computercraft/forge/ComputerCraftProxyImpl.java

-62
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,11 @@
1818

1919
package dev.ithundxr.createnumismatics.compat.computercraft.forge;
2020

21-
import com.google.common.collect.ImmutableMap;
2221
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour;
2322
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
24-
import dan200.computercraft.api.ForgeComputerCraftAPI;
25-
import dan200.computercraft.api.detail.VanillaDetailRegistries;
2623
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy;
27-
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour;
28-
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.peripherals.BankTerminalPeripheral;
29-
import dev.ithundxr.createnumismatics.content.bank.AuthorizedCardItem;
30-
import dev.ithundxr.createnumismatics.content.bank.CardItem;
31-
import dev.ithundxr.createnumismatics.content.bank.IDCardItem;
32-
import dev.ithundxr.createnumismatics.registry.NumismaticsBlocks;
33-
import dev.ithundxr.createnumismatics.registry.NumismaticsTags;
34-
import net.minecraft.world.level.block.state.BlockState;
35-
import net.minecraftforge.common.util.LazyOptional;
36-
import org.jetbrains.annotations.Nullable;
37-
38-
import java.util.Map;
39-
import java.util.UUID;
4024

4125
public class ComputerCraftProxyImpl {
42-
public static void registerWithDependency() {
43-
/* Comment if computercraft.implementation is not in the source set */
44-
ComputerCraftProxy.computerFactory = ComputerBehaviour::new;
45-
46-
ForgeComputerCraftAPI.registerPeripheralProvider((level, pos, direction) -> {
47-
BlockState state = level.getBlockState(pos);
48-
49-
if (NumismaticsBlocks.BANK_TERMINAL.has(state)) {
50-
return LazyOptional.of(() -> BankTerminalPeripheral.INSTANCE);
51-
}
52-
53-
return LazyOptional.empty();
54-
});
55-
56-
VanillaDetailRegistries.ITEM_STACK.addProvider((detailMap, stack) -> {
57-
Map<Object, @Nullable Object> cardDetails = null;
58-
if (NumismaticsTags.AllItemTags.CARDS.matches(stack)) {
59-
UUID accountID = CardItem.get(stack);
60-
if (accountID != null) {
61-
cardDetails = Map.of(
62-
"AccountID", accountID.toString()
63-
);
64-
}
65-
} else if (NumismaticsTags.AllItemTags.AUTHORIZED_CARDS.matches(stack)) {
66-
AuthorizedCardItem.AuthorizationPair authorizationPair = AuthorizedCardItem.get(stack);
67-
if (authorizationPair != null) {
68-
UUID accountID = authorizationPair.accountID();
69-
UUID authorizationID = authorizationPair.authorizationID();
70-
cardDetails = Map.of(
71-
"AccountID", accountID.toString(),
72-
"AuthorizationID", authorizationID.toString()
73-
);
74-
}
75-
} else if (NumismaticsTags.AllItemTags.ID_CARDS.matches(stack)) {
76-
UUID id = IDCardItem.get(stack);
77-
if (id != null) {
78-
cardDetails = Map.of(
79-
"ID", id.toString()
80-
);
81-
}
82-
}
83-
84-
if (cardDetails != null)
85-
detailMap.put("numismatics", ImmutableMap.of("card", cardDetails));
86-
});
87-
}
8826
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) {
8927
if (ComputerCraftProxy.computerFactory == null)
9028
return ComputerCraftProxy.fallbackFactory.apply(sbe);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.forge;
20+
21+
import com.google.common.collect.ImmutableMap;
22+
import dan200.computercraft.api.ForgeComputerCraftAPI;
23+
import dan200.computercraft.api.detail.VanillaDetailRegistries;
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 net.minecraft.world.level.block.state.BlockState;
33+
import net.minecraftforge.common.util.LazyOptional;
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+
ForgeComputerCraftAPI.registerPeripheralProvider((level, pos, direction) -> {
45+
BlockState state = level.getBlockState(pos);
46+
47+
if (NumismaticsBlocks.BANK_TERMINAL.has(state)) {
48+
return LazyOptional.of(() -> BankTerminalPeripheral.INSTANCE);
49+
}
50+
51+
return LazyOptional.empty();
52+
});
53+
54+
VanillaDetailRegistries.ITEM_STACK.addProvider((detailMap, stack) -> {
55+
Map<Object, @Nullable Object> cardDetails = null;
56+
if (NumismaticsTags.AllItemTags.CARDS.matches(stack)) {
57+
UUID accountID = CardItem.get(stack);
58+
if (accountID != null) {
59+
cardDetails = Map.of(
60+
"AccountID", accountID.toString()
61+
);
62+
}
63+
} else if (NumismaticsTags.AllItemTags.AUTHORIZED_CARDS.matches(stack)) {
64+
AuthorizedCardItem.AuthorizationPair authorizationPair = AuthorizedCardItem.get(stack);
65+
if (authorizationPair != null) {
66+
UUID accountID = authorizationPair.accountID();
67+
UUID authorizationID = authorizationPair.authorizationID();
68+
cardDetails = Map.of(
69+
"AccountID", accountID.toString(),
70+
"AuthorizationID", authorizationID.toString()
71+
);
72+
}
73+
} else if (NumismaticsTags.AllItemTags.ID_CARDS.matches(stack)) {
74+
UUID id = IDCardItem.get(stack);
75+
if (id != null) {
76+
cardDetails = Map.of(
77+
"ID", id.toString()
78+
);
79+
}
80+
}
81+
82+
if (cardDetails != null)
83+
detailMap.put("numismatics", ImmutableMap.of("card", cardDetails));
84+
});
85+
}
86+
}

0 commit comments

Comments
 (0)