Skip to content

Commit

Permalink
rework entity attribute registration (fixes #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed May 20, 2024
1 parent 90ee2c4 commit fae06be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void onInitialize(ModContainer mod) {
configurator.registerConfig(ArcanusConfig.class);

RegistryService registryService = RegistryService.get();
ArcanusEntityAttributes.registerAll(registryService);
ArcanusEntityAttributes.registerAll();
ArcanusEntities.ENTITY_TYPES.accept(registryService);
ArcanusBlocks.BLOCKS.accept(registryService);
ArcanusItems.ITEM_GROUPS.accept(registryService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import net.minecraft.entity.attribute.ClampedEntityAttribute;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.registry.RegistryKeys;
import org.jetbrains.annotations.ApiStatus;

public class ArcanusEntityAttributes {

private static boolean isInitialized = false;
private static volatile boolean isInitialized = false;
private static final RegistryHandler<EntityAttribute> ENTITY_ATTRIBUTES = RegistryHandler.create(RegistryKeys.ENTITY_ATTRIBUTE, Arcanus.MOD_ID);

public static final RegistrySupplier<EntityAttribute> MAX_MANA = ENTITY_ATTRIBUTES.register("max_mana", () -> new ClampedEntityAttribute(Arcanus.translationKey("attribute.name.generic", "max_mana"), 10d, 0d, 1024d).setTracked(true));
Expand All @@ -22,10 +23,11 @@ public class ArcanusEntityAttributes {
public static final RegistrySupplier<EntityAttribute> MAGIC_RESISTANCE = ENTITY_ATTRIBUTES.register("magic_resistance", () -> new ClampedEntityAttribute(Arcanus.translationKey("attribute.name.generic", "magic_resistance"), 1d, 0d, 1024d).setTracked(true));
public static final RegistrySupplier<EntityAttribute> SPELL_COOL_DOWN = ENTITY_ATTRIBUTES.register("spell_cool_down", () -> new ClampedEntityAttribute(Arcanus.translationKey("attribute.name.generic", "spell_cool_down"), 1d, 0d, 1024d).setTracked(true));

public static void registerAll(RegistryService registryService) {
ArcanusEntityAttributes.ENTITY_ATTRIBUTES.accept(registryService);
isInitialized = true;
@ApiStatus.Internal
public static synchronized void registerAll() {
if(!isInitialized) {
ArcanusEntityAttributes.ENTITY_ATTRIBUTES.accept(RegistryService.get());
isInitialized = true;
}
}

public static boolean isInitialized() { return isInitialized; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,17 @@ public LivingEntityMixin(EntityType<?> type, World world) {

@ModifyReturnValue(method = "createAttributes", at = @At("RETURN"))
private static DefaultAttributeContainer.Builder arcanuscontinuum$createPlayerAttributes(DefaultAttributeContainer.Builder builder) {
if(ArcanusEntityAttributes.isInitialized())
return builder
.add(ArcanusEntityAttributes.MAX_MANA.get())
.add(ArcanusEntityAttributes.MANA_REGEN.get())
.add(ArcanusEntityAttributes.BURNOUT_REGEN.get())
.add(ArcanusEntityAttributes.MANA_LOCK.get())
.add(ArcanusEntityAttributes.SPELL_POTENCY.get())
.add(ArcanusEntityAttributes.MAGIC_RESISTANCE.get())
.add(ArcanusEntityAttributes.MANA_COST.get())
.add(ArcanusEntityAttributes.SPELL_COOL_DOWN.get());
else
return builder;
ArcanusEntityAttributes.registerAll();

return builder
.add(ArcanusEntityAttributes.MAX_MANA.get())
.add(ArcanusEntityAttributes.MANA_REGEN.get())
.add(ArcanusEntityAttributes.BURNOUT_REGEN.get())
.add(ArcanusEntityAttributes.MANA_LOCK.get())
.add(ArcanusEntityAttributes.SPELL_POTENCY.get())
.add(ArcanusEntityAttributes.MAGIC_RESISTANCE.get())
.add(ArcanusEntityAttributes.MANA_COST.get())
.add(ArcanusEntityAttributes.SPELL_COOL_DOWN.get());
}

@WrapOperation(method = "handleFrictionAndCalculateMovement", at = @At(value = "INVOKE",
Expand Down

0 comments on commit fae06be

Please sign in to comment.