Interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade>

Type Parameters:
T - The type of turtle upgrade this is responsible for serialising.
All Superinterfaces:
UpgradeSerialiser<T>

public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends UpgradeSerialiser<T>
Reads a ITurtleUpgrade from disk and reads/writes it to a network packet.

These should be registered in a Registry while the game is loading, much like RecipeSerializers.

If your turtle upgrade doesn't have any associated configurable parameters (like most upgrades), you can use simple(Function) or simpleWithCustomItem(BiFunction) to create a basic upgrade serialiser.

Example (Forge)


 static final DeferredRegister<TurtleUpgradeSerialiser<?>> SERIALISERS = DeferredRegister.create( TurtleUpgradeSerialiser.TYPE, "my_mod" );

 // Register a new upgrade serialiser called "my_upgrade".
 public static final RegistryObject<TurtleUpgradeSerialiser<MyUpgrade>> MY_UPGRADE =
     SERIALISERS.register( "my_upgrade", () -> TurtleUpgradeSerialiser.simple( MyUpgrade::new ) );

 // Then in your constructor
 SERIALISERS.register( bus );
 

We can then define a new upgrade using JSON by placing the following in data/<my_mod>/computercraft/turtle_upgrades/<my_upgrade_id>.json}.


 {
     "type": my_mod:my_upgrade",
 }
 

Finally, we need to register a model for our upgrade. The way to do this varies on mod loader, see TurtleUpgradeModeller for more information.

TurtleUpgradeDataProvider provides a data provider to aid with generating these JSON files.

See Also:
  • Method Details

    • registryId

      static net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<TurtleUpgradeSerialiser<?>>> registryId()
      The ID for the associated registry.
      Returns:
      The registry key.
    • simple

      static <T extends ITurtleUpgrade> TurtleUpgradeSerialiser<T> simple(Function<net.minecraft.resources.ResourceLocation,T> factory)
      Create an upgrade serialiser for a simple upgrade. This is similar to a SimpleCraftingRecipeSerializer, but for upgrades.

      If you might want to vary the item, it's suggested you use simpleWithCustomItem(BiFunction) instead.

      Type Parameters:
      T - The type of the generated upgrade.
      Parameters:
      factory - Generate a new upgrade with a specific ID.
      Returns:
      The serialiser for this upgrade
    • simpleWithCustomItem

      static <T extends ITurtleUpgrade> TurtleUpgradeSerialiser<T> simpleWithCustomItem(BiFunction<net.minecraft.resources.ResourceLocation,net.minecraft.world.item.ItemStack,T> factory)
      Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
      Type Parameters:
      T - The type of the generated upgrade.
      Parameters:
      factory - Generate a new upgrade with a specific ID and crafting item. The returned upgrade's UpgradeBase.getCraftingItem() MUST equal the provided item.
      Returns:
      The serialiser for this upgrade.
      See Also: