Skip to content
Open
3 changes: 2 additions & 1 deletion docs/content/Modpacks/Changes/v8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ A large number of machine feature interfaces have been removed, and have had the
- Example usage: `SimpleCookingRecipeBuilder.campfireCooking("cooking_chicken").input(new ItemStack(Items.CHICKEN)).output(new ItemStacks(Items.COOKED_CHICKEN)).cookingTime(100).experience(100).save(provider);`
- `GTFluidImpl` has been merged into `GTFluid`, use `GTFluid.Flowing` and `GTFluid.Source` instead of `GTFluidImpl.Flowing` and `GTFluidImpl.Source`.
- Item behaviors have been moved to `common/item/behavior`, and some items have been moved from `api/item` to `common/item`.
- Changed the minimum value of the `compat.minimap.surfaceRockProspectRange` and `compat.minimap.oreBlockProspectRange` configs from -1 to 0. The behavior is still disabled with 0.
- Changed the minimum value of the `compat.minimap.surfaceRockProspectRange` and `compat.minimap.oreBlockProspectRange` configs from -1 to 0. The behavior is still disabled with 0.
- All materials are now stored in a single registry, instead of a registry per addon. Replace references to `GTCEuAPI.materialManager` with `GTRegistries.MATERIALS`.
3 changes: 0 additions & 3 deletions src/main/java/com/gregtechceu/gtceu/api/GTCEuAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.gregtechceu.gtceu.api.addon.IGTAddon;
import com.gregtechceu.gtceu.api.block.ICoilType;
import com.gregtechceu.gtceu.api.block.IFilterType;
import com.gregtechceu.gtceu.api.data.chemical.material.IMaterialRegistryManager;
import com.gregtechceu.gtceu.api.machine.multiblock.IBatteryData;
import com.gregtechceu.gtceu.api.registry.GTRegistry;
import com.gregtechceu.gtceu.common.block.BatteryBlock;
Expand All @@ -28,8 +27,6 @@ public class GTCEuAPI {

/** Will always be available */
public static GTCEu instance;
/** Will be available at the Construction stage */
public static IMaterialRegistryManager materialManager;
Comment thread
gustovafing marked this conversation as resolved.

/** Will be available at the Pre-Initialization stage */
@Getter
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/com/gregtechceu/gtceu/api/addon/IGTAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ default void registerTagPrefixes() {}
*/
default void registerElements() {}

/**
* Call init on your custom Material class(es) here
*
* @deprecated use {@link com.gregtechceu.gtceu.api.data.chemical.material.event.MaterialRegistryEvent} and
* {@link com.gregtechceu.gtceu.api.data.chemical.material.event.MaterialEvent} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.21")
default void registerMaterials() {}
Comment thread
gustovafing marked this conversation as resolved.

/**
* Call init on your custom Sound class(es) here
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gregtechceu.gtceu.api.data.chemical;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTCEuAPI;
import com.gregtechceu.gtceu.api.data.chemical.material.ItemMaterialData;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidProperty;
Expand All @@ -12,6 +11,7 @@
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.data.tag.TagUtil;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTMaterials;

import net.minecraft.MethodsReturnNonnullByDefault;
Expand Down Expand Up @@ -97,7 +97,7 @@ public static MaterialStack getMaterialStack(ItemLike itemLike) {
public static Material getMaterial(Fluid fluid) {
if (FLUID_MATERIAL.isEmpty()) {
Set<TagKey<Fluid>> allFluidTags = BuiltInRegistries.FLUID.getTagNames().collect(Collectors.toSet());
for (final Material material : GTCEuAPI.materialManager.getRegisteredMaterials()) {
for (final Material material : GTRegistries.MATERIALS.values()) {
if (material.hasProperty(PropertyKey.FLUID)) {
FluidProperty property = material.getProperty(PropertyKey.FLUID);
FluidStorageKey.allKeys().stream()
Expand Down Expand Up @@ -209,7 +209,7 @@ public static MaterialEntry getMaterialEntry(TagKey<Item> tag) {
// lookups.
Set<TagKey<Item>> allItemTags = BuiltInRegistries.ITEM.getTagNames().collect(Collectors.toSet());
for (TagPrefix prefix : TagPrefix.values()) {
for (Material material : GTCEuAPI.materialManager.getRegisteredMaterials()) {
for (Material material : GTRegistries.MATERIALS.values()) {
prefix.getItemTags(material).stream()
.filter(allItemTags::contains)
.forEach(tagKey -> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gregtechceu.gtceu.api.data.chemical.material;

import com.gregtechceu.gtceu.api.GTCEuAPI;
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.Element;
import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlag;
Expand All @@ -16,6 +15,7 @@
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys;
import com.gregtechceu.gtceu.api.item.tool.MaterialToolTier;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.api.registry.registrate.BuilderBase;
import com.gregtechceu.gtceu.common.data.GTMaterials;
import com.gregtechceu.gtceu.common.data.GTMedicalConditions;
Expand Down Expand Up @@ -150,7 +150,7 @@ protected Material(ResourceLocation resourceLocation) {
}

protected void registerMaterial() {
GTCEuAPI.materialManager.getRegistry(getModid()).register(this);
GTRegistries.MATERIALS.register(getResourceLocation(), this);
}

public String getName() {
Expand All @@ -176,7 +176,7 @@ public boolean shouldGenerateRecipesFor(@NotNull TagPrefix prefix) {
}

public void addFlags(MaterialFlag... flags) {
if (!GTCEuAPI.materialManager.canModifyMaterials())
if (!GTRegistries.MATERIALS.canModifyMaterials())
throw new IllegalStateException("Cannot add flag to material when registry is frozen!");
this.flags.addFlags(flags).verify(this);
}
Expand Down Expand Up @@ -533,7 +533,7 @@ public <T extends IMaterialProperty> void removeProperty(PropertyKey<T> key) {
}

public <T extends IMaterialProperty> void setProperty(PropertyKey<T> key, IMaterialProperty property) {
if (!GTCEuAPI.materialManager.canModifyMaterials()) {
if (!GTRegistries.MATERIALS.canModifyMaterials()) {
throw new IllegalStateException("Cannot add properties to a Material when registry is frozen!");
}
properties.setProperty(key, property);
Expand Down Expand Up @@ -1875,7 +1875,7 @@ public Material buildAndRegister() {

@Override
@HideFromJS
public Material register() {
public @NotNull Material register() {
return value = buildAndRegister();
}
}
Expand Down

This file was deleted.

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
}
}
Loading
Loading