Skip to content

Developer Section: Simple Restrictions

Kessy edited this page Jan 6, 2026 · 1 revision

AStages Developer Section: Simple Restrictions

Simple Restrictions are a different type of restriction that allows end users to create and manage restrictions directly in-game using commands, without writing scripts or code.

They are designed to provide a simplified, command-driven interface while still integrating fully with AStages’ internal restriction system.


Command Structure

Starting from AStages 2.0.0, Simple Restrictions use a unified command structure:

/astages restrict <id> <stage> <type> <param1> <param2> ...
  • id
    A unique identifier for the restriction. It is used internally by AStages for:

    • Client/server synchronization
    • Removal and updates
    • Cache handling and networking
  • stage
    Represents the progression stage of the game. When a player has this stage, the restriction is disabled. For example, if an item is restricted, it cannot be used until the player obtains the specified stage.

  • type
    Identifies the type of Simple Restriction being created (e.g. astages:item, astages:ore, or custom types provided by plugins).

  • additional parameters
    Restriction-specific arguments defined by the restriction type itself.


Registration System

Starting from version 2.0.0, Simple Restrictions must be registered using the Forge / NeoForge registry system. This makes implementation easier and more consistent for developers, but requires explicit registration before a restriction type can be used. All restriction types—both classic and simple—are registered through the AStagesRegistries class.

Without proper registration, a Simple Restriction cannot be used in commands.


Start Developing custom Simple Restrictions

AStagesPlugin#registerSimpleRestriction method is used by developers to create custom simple restrictions and integrate them directly into the AStages system.

The workflow is the following:

  1. Define and register the restriction types
    Both the ARestrictionType and ASimpleRestrictionType must be registered beforehand using AStagesRegistries and the standard Forge / NeoForge DeferredRegister system.

  2. Register the simple restriction
    Using the provided container, the simple restriction is associated with:

    • A conversion target (the full restriction type)
    • A conversion logic
    • Optional cleanup logic
    • A command definition
  3. Start coding!

  • convertTo(...)
    Defines the full restriction type that will be used internally, especially during removal operations.

  • elaborateUsing(...)
    Converts the ASimpleRestriction into a real restriction instance and registers it on the server. The developer is responsible for:

    • Creating the restriction instance
    • Configuring it
    • Registering it into the correct manager

    ASimpleElaborator#commonOperations should be called in almost all cases, as it handles command autocompletion.

  • afterRemoveRun(...)
    Executed after the restriction has been fully removed by AStages. Removal itself must not be handled by the developer.

    This hook is only required for restrictions that need post-removal updates (e.g. AOreRestriction, which updates block textures after removal).

  • addCommand(...)
    Defines the command used to add the restriction.

    ASimpleElaborator#addRestrictionForType shows the recommended command behavior and can be used directly if no custom logic is required.


Example

@NotNullParams
public class YourPlugin implements AStagesPlugin {
    public static final DeferredRegister<ARestrictionType> RESTRICTION_TYPES = ARestrictionType.setCurrentDeferredRegister(DeferredRegister.create(AStagesRegistries.RESTRICTION_TYPES, YourMod.MODID));
    public static final DeferredRegister<ASimpleRestrictionType> SIMPLE_RESTRICTION_TYPES = ASimpleRestrictionType.setCurrentDeferredRegister(DeferredRegister.create(AStagesRegistries.SIMPLE_RESTRICTION_TYPES, YourMod.MODID));

    public static final ARestrictionType YOUR_RESTRICTION = ARestrictionType.create("new_type");
    public static final ASimpleRestrictionType YOUR_SIMPLE_RESTRICTION = ASimpleRestrictionType.create("new_type");

    @Override
    public void registerSimpleRestriction(SimpleRestrictionsContainer container) {
        container.registerFor(YOUR_SIMPLE_RESTRICTION)
            .convertTo(YOUR_RESTRICTION)
            .elaborateUsing((simple, markAsDirty) -> {
                var restriction = new YourRestriction(simple.id, simple.stage)
                    .restrict(fromStringToActualTypeMethod(simple.object))
                    .set(YourAttributes.ATTRIBUTE, value);

                YourManager.YOUR_RESTRICTION_INSTANCE.addRestriction(restriction);

                // Required in most cases
                ASimpleElaborator.commonOperations(simple);
            })
            .afterRemoveRun((id, type) -> {
                // Some code here that will run after the restriction is actually removed
            })
            .addCommand((context, literal) -> {
                literal.then(Commands.argument("your_argument", AnyArgument.argument())
                    .executes(c -> {
                        ...

                        return 1;
                    })
                );
            });
    }
}

Documentation:

  1. Home

  2. Stages
    - Usage
    - Utils

  3. Restrictions
    - Crop
    - Dimension
    - Effect
    - Enchant
    - Item (Old)
    - Loot
    - Mob
    - Ore
    - Pet
    - Recipe
    - Region
    - Screen
    - Structure

  4. Addons
    - Curios API
    - Pufferfish Skill's

  5. Simple Restrictions (via commands)
    Brand new and intuitive way to add restriction!

  6. Developers
    - Plugin
    - Restrictions
    - Simple Restrictions
    - Stage System
    - Utils

  7. Q&A
    A place where questions are on the agenda!

  8. Changelogs
    Changelogs since 0.6.0 version!

  9. Version Comparisons

  10. What's Happened? (FLOP!)
    New code formatting is coming!

Clone this wiki locally