mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-12 18:30:29 +00:00
Update to Forge's latest registry API
Forge 4.0.18 deprecated a lot of methods and moved where RegistryEvent.NewRegistry lives, so we needed to update. This does break the CC API a little bit (sorry!) though given Forge 1.18.2 is still in flux, that's probably inevitable.
This commit is contained in:
parent
78cce4981a
commit
e6339b2847
@ -6,5 +6,5 @@ mod_version=1.100.3
|
||||
# Minecraft properties (update mods.toml when changing)
|
||||
mc_version=1.18.2
|
||||
mapping_version=2022.02.13
|
||||
forge_version=40.0.2
|
||||
forge_version=40.0.19
|
||||
# NO SERIOUSLY, UPDATE mods.toml WHEN CHANGING
|
||||
|
@ -25,6 +25,6 @@ public abstract class PocketUpgradeDataProvider extends UpgradeDataProvider<IPoc
|
||||
{
|
||||
public PocketUpgradeDataProvider( @Nonnull DataGenerator generator )
|
||||
{
|
||||
super( generator, "Pocket Computer Upgrades", "computercraft/pocket_upgrades", PocketUpgradeSerialiser.TYPE );
|
||||
super( generator, "Pocket Computer Upgrades", "computercraft/pocket_upgrades", PocketUpgradeSerialiser.REGISTRY_ID );
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,13 @@
|
||||
*/
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||
import dan200.computercraft.internal.upgrades.SerialiserWithCraftingItem;
|
||||
import dan200.computercraft.internal.upgrades.SimpleSerialiser;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
||||
@ -33,11 +36,12 @@ import java.util.function.Function;
|
||||
public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends UpgradeSerialiser<T, PocketUpgradeSerialiser<?>>
|
||||
{
|
||||
/**
|
||||
* A {@link Class} representing an abstract {@link PocketUpgradeSerialiser}. This is largely intended for use with
|
||||
* Forge Registry methods/classes, such as {@link DeferredRegister} and {@link RegistryManager#getRegistry(Class)}.
|
||||
* The ID for the associated registry.
|
||||
*
|
||||
* This is largely intended for use with Forge Registry methods/classes, such as {@link DeferredRegister} and
|
||||
* {@link RegistryManager#getRegistry(ResourceKey)}.
|
||||
*/
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Class<PocketUpgradeSerialiser<?>> TYPE = (Class<PocketUpgradeSerialiser<?>>) (Class<?>) PocketUpgradeSerialiser.class;
|
||||
ResourceKey<Registry<PocketUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey( new ResourceLocation( ComputerCraft.MOD_ID, "pocket_upgrade_serialiser" ) );
|
||||
|
||||
/**
|
||||
* A convenient base class to inherit to implement {@link PocketUpgradeSerialiser}.
|
||||
|
@ -34,7 +34,7 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
|
||||
|
||||
public TurtleUpgradeDataProvider( DataGenerator generator )
|
||||
{
|
||||
super( generator, "Turtle Upgrades", "computercraft/turtle_upgrades", TurtleUpgradeSerialiser.TYPE );
|
||||
super( generator, "Turtle Upgrades", "computercraft/turtle_upgrades", TurtleUpgradeSerialiser.REGISTRY_ID );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,10 +5,13 @@
|
||||
*/
|
||||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||
import dan200.computercraft.internal.upgrades.SerialiserWithCraftingItem;
|
||||
import dan200.computercraft.internal.upgrades.SimpleSerialiser;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
@ -61,11 +64,12 @@ import java.util.function.Function;
|
||||
public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends UpgradeSerialiser<T, TurtleUpgradeSerialiser<?>>
|
||||
{
|
||||
/**
|
||||
* A {@link Class} representing an abstract {@link TurtleUpgradeSerialiser}. This is largely intended for use with
|
||||
* Forge Registry methods/classes, such as {@link DeferredRegister} and {@link RegistryManager#getRegistry(Class)}.
|
||||
* The ID for the associated registry.
|
||||
*
|
||||
* This is largely intended for use with Forge Registry methods/classes, such as {@link DeferredRegister} and
|
||||
* {@link RegistryManager#getRegistry(ResourceKey)}.
|
||||
*/
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Class<TurtleUpgradeSerialiser<?>> TYPE = (Class<TurtleUpgradeSerialiser<?>>) (Class<?>) TurtleUpgradeSerialiser.class;
|
||||
ResourceKey<Registry<TurtleUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_upgrade_serialiser" ) );
|
||||
|
||||
/**
|
||||
* A convenient base class to inherit to implement {@link TurtleUpgradeSerialiser}.
|
||||
|
@ -12,9 +12,11 @@ import com.google.gson.JsonParseException;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
||||
import dan200.computercraft.internal.upgrades.SerialiserWithCraftingItem;
|
||||
import dan200.computercraft.internal.upgrades.SimpleSerialiser;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
@ -43,16 +45,16 @@ public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends Upgr
|
||||
private final DataGenerator generator;
|
||||
private final String name;
|
||||
private final String folder;
|
||||
private final Class<R> klass;
|
||||
private final ResourceKey<Registry<R>> registry;
|
||||
|
||||
private List<T> upgrades;
|
||||
|
||||
protected UpgradeDataProvider( @Nonnull DataGenerator generator, @Nonnull String name, @Nonnull String folder, @Nonnull Class<R> klass )
|
||||
protected UpgradeDataProvider( @Nonnull DataGenerator generator, @Nonnull String name, @Nonnull String folder, @Nonnull ResourceKey<Registry<R>> registry )
|
||||
{
|
||||
this.generator = generator;
|
||||
this.name = name;
|
||||
this.folder = folder;
|
||||
this.klass = klass;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,8 +157,8 @@ public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends Upgr
|
||||
@Nonnull
|
||||
public final R existingSerialiser( @Nonnull ResourceLocation id )
|
||||
{
|
||||
var result = RegistryManager.ACTIVE.getRegistry( klass ).getValue( id );
|
||||
if( result == null ) throw new IllegalArgumentException( "No such serialiser " + klass );
|
||||
var result = RegistryManager.ACTIVE.getRegistry( registry ).getValue( id );
|
||||
if( result == null ) throw new IllegalArgumentException( "No such serialiser " + registry );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import java.util.stream.Stream;
|
||||
public final class PocketUpgrades
|
||||
{
|
||||
private static final UpgradeManager<PocketUpgradeSerialiser<?>, IPocketUpgrade> registry = new UpgradeManager<>(
|
||||
"pocket computer upgrade", "computercraft/pocket_upgrades", PocketUpgradeSerialiser.TYPE
|
||||
"pocket computer upgrade", "computercraft/pocket_upgrades", PocketUpgradeSerialiser.REGISTRY_ID
|
||||
);
|
||||
|
||||
private PocketUpgrades() {}
|
||||
|
@ -94,10 +94,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.*;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@ -256,7 +253,7 @@ public final class Registry
|
||||
|
||||
public static class ModTurtleSerialisers
|
||||
{
|
||||
static final DeferredRegister<TurtleUpgradeSerialiser<?>> SERIALISERS = DeferredRegister.create( TurtleUpgradeSerialiser.TYPE, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<TurtleUpgradeSerialiser<?>> SERIALISERS = DeferredRegister.create( TurtleUpgradeSerialiser.REGISTRY_ID.location(), ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<TurtleUpgradeSerialiser<TurtleSpeaker>> SPEAKER =
|
||||
SERIALISERS.register( "speaker", () -> TurtleUpgradeSerialiser.simpleWithCustomItem( TurtleSpeaker::new ) );
|
||||
@ -272,7 +269,7 @@ public final class Registry
|
||||
|
||||
public static class ModPocketUpgradeSerialisers
|
||||
{
|
||||
static final DeferredRegister<PocketUpgradeSerialiser<?>> SERIALISERS = DeferredRegister.create( PocketUpgradeSerialiser.TYPE, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<PocketUpgradeSerialiser<?>> SERIALISERS = DeferredRegister.create( PocketUpgradeSerialiser.REGISTRY_ID, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<PocketUpgradeSerialiser<PocketSpeaker>> SPEAKER =
|
||||
SERIALISERS.register( "speaker", () -> PocketUpgradeSerialiser.simpleWithCustomItem( PocketSpeaker::new ) );
|
||||
@ -312,17 +309,21 @@ public final class Registry
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRegistries( RegistryEvent.NewRegistry event )
|
||||
public static void registerRegistries( NewRegistryEvent event )
|
||||
{
|
||||
new RegistryBuilder<TurtleUpgradeSerialiser<?>>()
|
||||
.setName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_upgrade_serialiser" ) )
|
||||
.setType( TurtleUpgradeSerialiser.TYPE )
|
||||
.disableSaving().disableSync().create();
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Class<TurtleUpgradeSerialiser<?>> turtleType = (Class<TurtleUpgradeSerialiser<?>>) (Class<?>) TurtleUpgradeSerialiser.class;
|
||||
event.create( new RegistryBuilder<TurtleUpgradeSerialiser<?>>()
|
||||
.setName( TurtleUpgradeSerialiser.REGISTRY_ID.location() )
|
||||
.setType( turtleType )
|
||||
.disableSaving().disableSync() );
|
||||
|
||||
new RegistryBuilder<PocketUpgradeSerialiser<?>>()
|
||||
.setName( new ResourceLocation( ComputerCraft.MOD_ID, "pocket_upgrade_serialiser" ) )
|
||||
.setType( PocketUpgradeSerialiser.TYPE )
|
||||
.disableSaving().disableSync().create();
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Class<PocketUpgradeSerialiser<?>> pocketType = (Class<PocketUpgradeSerialiser<?>>) (Class<?>) PocketUpgradeSerialiser.class;
|
||||
event.create( new RegistryBuilder<PocketUpgradeSerialiser<?>>()
|
||||
.setName( PocketUpgradeSerialiser.REGISTRY_ID.location() )
|
||||
.setType( pocketType )
|
||||
.disableSaving().disableSync() );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -14,7 +14,7 @@ import java.util.stream.Stream;
|
||||
public final class TurtleUpgrades
|
||||
{
|
||||
private static final UpgradeManager<TurtleUpgradeSerialiser<?>, ITurtleUpgrade> registry = new UpgradeManager<>(
|
||||
"turtle upgrade", "computercraft/turtle_upgrades", TurtleUpgradeSerialiser.TYPE
|
||||
"turtle upgrade", "computercraft/turtle_upgrades", TurtleUpgradeSerialiser.REGISTRY_ID
|
||||
);
|
||||
|
||||
private TurtleUpgrades() {}
|
||||
|
@ -9,6 +9,8 @@ import com.google.gson.*;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.upgrades.IUpgradeBase;
|
||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
|
||||
@ -45,16 +47,16 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T, R>, T exten
|
||||
) {}
|
||||
|
||||
private final String kind;
|
||||
private final Class<R> klass;
|
||||
private final ResourceKey<Registry<R>> registry;
|
||||
|
||||
private Map<String, UpgradeWrapper<R, T>> current = Collections.emptyMap();
|
||||
private Map<T, UpgradeWrapper<R, T>> currentWrappers = Collections.emptyMap();
|
||||
|
||||
public UpgradeManager( @Nonnull String kind, @Nonnull String path, @Nonnull Class<R> klass )
|
||||
public UpgradeManager( @Nonnull String kind, @Nonnull String path, @Nonnull ResourceKey<Registry<R>> registry )
|
||||
{
|
||||
super( GSON, path );
|
||||
this.kind = kind;
|
||||
this.klass = klass;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -126,7 +128,7 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T, R>, T exten
|
||||
var root = GsonHelper.convertToJsonObject( json, "top element" );
|
||||
var serialiserId = new ResourceLocation( GsonHelper.getAsString( root, "type" ) );
|
||||
|
||||
var serialiser = RegistryManager.ACTIVE.getRegistry( klass ).getValue( serialiserId );
|
||||
var serialiser = RegistryManager.ACTIVE.getRegistry( registry ).getValue( serialiserId );
|
||||
if( serialiser == null ) throw new JsonSyntaxException( "Unknown upgrade type '" + serialiserId + "'" );
|
||||
|
||||
// TODO: Can we track which mod this resource came from and use that instead? It's theoretically possible,
|
||||
|
@ -42,8 +42,8 @@ public class UpgradesLoadedMessage implements NetworkMessage
|
||||
|
||||
public UpgradesLoadedMessage( @Nonnull FriendlyByteBuf buf )
|
||||
{
|
||||
turtleUpgrades = fromBytes( buf, RegistryManager.ACTIVE.getRegistry( TurtleUpgradeSerialiser.TYPE ) );
|
||||
pocketUpgrades = fromBytes( buf, RegistryManager.ACTIVE.getRegistry( PocketUpgradeSerialiser.TYPE ) );
|
||||
turtleUpgrades = fromBytes( buf, RegistryManager.ACTIVE.getRegistry( TurtleUpgradeSerialiser.REGISTRY_ID ) );
|
||||
pocketUpgrades = fromBytes( buf, RegistryManager.ACTIVE.getRegistry( PocketUpgradeSerialiser.REGISTRY_ID ) );
|
||||
}
|
||||
|
||||
private <R extends UpgradeSerialiser<? extends T, R>, T extends IUpgradeBase> Map<String, UpgradeManager.UpgradeWrapper<R, T>> fromBytes(
|
||||
|
@ -21,6 +21,6 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a
|
||||
[[dependencies.computercraft]]
|
||||
modId="forge"
|
||||
mandatory=true
|
||||
versionRange="[40.0.2,41)"
|
||||
versionRange="[40.0.19,41)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
Loading…
Reference in New Issue
Block a user