mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-01 10:07:56 +00:00
Rewrite upgrades to use dynamic registries
Ever since 1.17, turtle and pocket upgrades have been loaded from datpacks, rather than being hard-coded in Java. However, upgrades have always been stored in our own registry-like structure, rather than using vanilla's registries. This has become a bit of a problem with the introduction of components. The upgrade components now hold the upgrade object (rather than just its id), which means we need the upgrades to be available much earlier (e.g. when reading recipes). The easiest fix here is to store upgrades in proper registries instead. This means that upgrades can no longer be reloaded (it requires a world restart), but otherwise is much nicer: - UpgradeData now stores a Holder<T> rather than a T. - UpgradeSerialiser has been renamed to UpgradeType. This now just provides a Codec<T>, rather than JSON and network reading/writing functions. - Upgrade classes no longer implement getUpgradeID(), but instead have a getType() function, which returns the associated UpgradeType. - Upgrades are now stored in turtle_upgrade (or pocket_upgrade) rather than turtle_upgrades (or pocket_upgrades). This will break existing datapacks, sorry!
This commit is contained in:
@@ -6,7 +6,7 @@ package dan200.computercraft.api.client;
|
||||
|
||||
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||
import dan200.computercraft.api.upgrades.UpgradeType;
|
||||
import dan200.computercraft.impl.client.FabricComputerCraftAPIClientService;
|
||||
|
||||
/**
|
||||
@@ -27,12 +27,12 @@ public final class FabricComputerCraftAPIClient {
|
||||
* This method may be used as a {@link dan200.computercraft.api.client.turtle.RegisterTurtleUpgradeModeller}, for
|
||||
* convenient use in multi-loader code.
|
||||
*
|
||||
* @param serialiser The turtle upgrade serialiser.
|
||||
* @param modeller The upgrade modeller.
|
||||
* @param <T> The type of the turtle upgrade.
|
||||
* @param type The turtle upgrade type.
|
||||
* @param modeller The upgrade modeller.
|
||||
* @param <T> The type of the turtle upgrade.
|
||||
*/
|
||||
public static <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(UpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
|
||||
getInstance().registerTurtleUpgradeModeller(serialiser, modeller);
|
||||
public static <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(UpgradeType<T> type, TurtleUpgradeModeller<T> modeller) {
|
||||
getInstance().registerTurtleUpgradeModeller(type, modeller);
|
||||
}
|
||||
|
||||
private static FabricComputerCraftAPIClientService getInstance() {
|
||||
|
@@ -6,7 +6,7 @@ package dan200.computercraft.impl.client;
|
||||
|
||||
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||
import dan200.computercraft.api.upgrades.UpgradeType;
|
||||
import dan200.computercraft.impl.Services;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface FabricComputerCraftAPIClientService {
|
||||
return instance == null ? Services.raise(FabricComputerCraftAPIClientService.class, Instance.ERROR) : instance;
|
||||
}
|
||||
|
||||
<T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(UpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller);
|
||||
<T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(UpgradeType<T> type, TurtleUpgradeModeller<T> modeller);
|
||||
|
||||
final class Instance {
|
||||
static final @Nullable FabricComputerCraftAPIClientService INSTANCE;
|
||||
|
Reference in New Issue
Block a user