-
Notifications
You must be signed in to change notification settings - Fork 9
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.
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.
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.
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:
-
Define and register the restriction types
Both theARestrictionTypeandASimpleRestrictionTypemust be registered beforehand usingAStagesRegistriesand the standard Forge / NeoForgeDeferredRegistersystem. -
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
-
Start coding!
-
convertTo(...)
Defines the full restriction type that will be used internally, especially during removal operations. -
elaborateUsing(...)
Converts theASimpleRestrictioninto 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#commonOperationsshould 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#addRestrictionForTypeshows the recommended command behavior and can be used directly if no custom logic is required.
@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:
-
Restrictions
- Crop
- Dimension
- Effect
- Enchant
- Item (Old)
- Loot
- Mob
- Ore
- Pet
- Recipe
- Region
- Screen
- Structure -
Addons
- Curios API
- Pufferfish Skill's -
Simple Restrictions (via commands)
Brand new and intuitive way to add restriction! -
Developers
- Plugin
- Restrictions
- Simple Restrictions
- Stage System
- Utils -
Q&A
A place where questions are on the agenda! -
Changelogs
Changelogs since 0.6.0 version! -
What's Happened? (FLOP!)
New code formatting is coming!