-
Notifications
You must be signed in to change notification settings - Fork 376
Remove material manager and merge addon material registries into single unified material registry #4816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gustovafing
wants to merge
12
commits into
1.20.1
Choose a base branch
from
gus/material-registry
base: 1.20.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Remove material manager and merge addon material registries into single unified material registry #4816
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e3f1bdf
refactor some registrate stuff
gustovafing ac0a3d7
remove material registry impl class
gustovafing 4234b3d
switch material registry to RL registry
gustovafing fe2d74d
merge all mod mat registries into unified material registry
gustovafing 4ef71a6
spotless
gustovafing 2e5c686
remove network id
gustovafing e900d81
remove fallback material
gustovafing 0025171
fixes
gustovafing 3aaf50a
lang generator
gustovafing 799d788
Merge branch '1.20.1' into gus/material-registry
gustovafing b90d834
Merge branch '1.20.1' into gus/material-registry
gustovafing c64b89a
switch material registry string get
gustovafing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 0 additions & 117 deletions
117
src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/IMaterialRegistryManager.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
...in/java/com/gregtechceu/gtceu/api/data/chemical/material/event/MaterialRegistryEvent.java
This file was deleted.
Oops, something went wrong.
102 changes: 71 additions & 31 deletions
102
...main/java/com/gregtechceu/gtceu/api/data/chemical/material/registry/MaterialRegistry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,98 @@ | ||
| package com.gregtechceu.gtceu.api.data.chemical.material.registry; | ||
|
|
||
| import com.gregtechceu.gtceu.GTCEu; | ||
| import com.gregtechceu.gtceu.api.addon.AddonFinder; | ||
| import com.gregtechceu.gtceu.api.addon.IGTAddon; | ||
| import com.gregtechceu.gtceu.api.data.chemical.material.Material; | ||
| import com.gregtechceu.gtceu.api.registry.GTRegistry; | ||
| import com.gregtechceu.gtceu.api.registry.registrate.GTRegistrate; | ||
| import com.gregtechceu.gtceu.common.registry.GTRegistration; | ||
| import com.gregtechceu.gtceu.common.data.GTMaterials; | ||
|
|
||
| import net.minecraft.resources.ResourceLocation; | ||
|
|
||
| import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; | ||
| import lombok.Getter; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.UnmodifiableView; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Set; | ||
|
|
||
| public abstract class MaterialRegistry extends GTRegistry.String<Material> { | ||
| public class MaterialRegistry extends GTRegistry.RL<Material> { | ||
|
|
||
| @Getter | ||
| private final GTRegistrate registrate; | ||
| private final Set<java.lang.String> usedNamespaces = new ObjectOpenHashSet<>(); | ||
|
|
||
| public MaterialRegistry(java.lang.String modId) { | ||
| super(new ResourceLocation(modId, "material")); | ||
| IGTAddon addon = AddonFinder.getAddon(modId); | ||
| this.registrate = addon != null ? addon.getRegistrate() : | ||
| GTCEu.MOD_ID.equals(modId) ? GTRegistration.REGISTRATE : GTRegistrate.create(modId); | ||
| } | ||
| private Phase registrationPhase = Phase.PRE; | ||
|
|
||
| public abstract void register(Material material); | ||
| public MaterialRegistry() { | ||
| super(GTCEu.id("material")); | ||
| } | ||
|
|
||
| @NotNull | ||
| public abstract Collection<Material> getAllMaterials(); | ||
| public Material get(java.lang.String name) { | ||
| ResourceLocation location = ResourceLocation.tryParse(GTCEu.appendIdString(name)); | ||
| if (location != null) return get(location); | ||
| return GTMaterials.NULL; | ||
| } | ||
|
|
||
| /** | ||
| * Set the fallback material for this registry. | ||
| * This is only for manual fallback usage. | ||
| * | ||
| * @param material the fallback material | ||
| */ | ||
| public abstract void setFallbackMaterial(@NotNull Material material); | ||
| @Override | ||
| public <T extends Material> T register(@NotNull ResourceLocation key, @NotNull T value) { | ||
| if (registrationPhase == Phase.CLOSED || registrationPhase == Phase.FROZEN) { | ||
| GTCEu.LOGGER.error( | ||
| "Materials cannot be registered in the PostMaterialEvent (or after)! Must be added in the MaterialEvent. Skipping material {}...", | ||
| key); | ||
| return null; | ||
| } | ||
| super.register(key, value); | ||
| usedNamespaces.add(key.getNamespace()); | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * This is only for manual fallback usage. | ||
| * Accessible when in phases: | ||
| * <ul> | ||
| * <li>{@link Phase#CLOSED}</li> | ||
| * <li>{@link Phase#FROZEN}</li> | ||
| * </ul> | ||
| * | ||
| * @return the fallback material, used for when another material does not exist | ||
| * @return all registered materials. | ||
| */ | ||
| @NotNull | ||
| public abstract Material getFallbackMaterial(); | ||
| public @UnmodifiableView Set<Material> values() { | ||
| if (registrationPhase == Phase.PRE || registrationPhase == Phase.OPEN) | ||
| throw new IllegalStateException("Cannot retrieve all materials before registration"); | ||
| return super.values(); | ||
| } | ||
|
|
||
| /** | ||
| * @return the network ID for this registry | ||
| */ | ||
| public abstract int getNetworkId(); | ||
| public void closeRegistry() { | ||
| registrationPhase = Phase.CLOSED; | ||
| } | ||
|
|
||
| @Override | ||
| public void freeze() { | ||
| super.freeze(); | ||
| registrationPhase = Phase.FROZEN; | ||
| } | ||
|
|
||
| @Override | ||
| public void unfreeze() { | ||
| super.unfreeze(); | ||
| registrationPhase = Phase.OPEN; | ||
| } | ||
|
|
||
| @NotNull | ||
| public abstract java.lang.String getModid(); | ||
| public Phase getPhase() { | ||
| return registrationPhase; | ||
| } | ||
|
|
||
| public boolean canModifyMaterials() { | ||
| return getPhase() != Phase.FROZEN && getPhase() != Phase.PRE; | ||
| } | ||
|
|
||
| public enum Phase { | ||
| /** Material Registration and Modification is not started */ | ||
| PRE, | ||
| /** Material Registration and Modification is available */ | ||
| OPEN, | ||
| /** Material Registration is unavailable and only Modification is available */ | ||
| CLOSED, | ||
| /** Material Registration and Modification is unavailable */ | ||
| FROZEN | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.