diff --git a/build.gradle b/build.gradle index acac05cc..a4f16680 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.10-SNAPSHOT' + id 'fabric-loom' version '0.11-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 4c724287..73764d28 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,14 +2,14 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties -minecraft_version=1.18.1 -yarn_mappings=1.18.1+build.1 -loader_version=0.12.12 +minecraft_version=1.18.2 +yarn_mappings=1.18.2+build.1 +loader_version=0.13.3 # Mod Properties -mod_version = 1.1.5 +mod_version = 1.1.6 maven_group = com.github.clevernucleus archives_base_name = dataattributes # Dependencies -fabric_version=0.46.1+1.18 +fabric_version=0.51.1+1.18.2 diff --git a/src/main/java/com/github/clevernucleus/dataattributes/impl/AttributeDataManager.java b/src/main/java/com/github/clevernucleus/dataattributes/impl/AttributeDataManager.java index 5ec9dac5..4e4c85a5 100644 --- a/src/main/java/com/github/clevernucleus/dataattributes/impl/AttributeDataManager.java +++ b/src/main/java/com/github/clevernucleus/dataattributes/impl/AttributeDataManager.java @@ -262,12 +262,21 @@ public void refresh() { EntityTypeAttributes entityTypeAttributes = this.entityTypes.get(identifier); + entityTypeAttributes.attributes.keySet().forEach(c -> System.out.println("PENIS: " + c)); + @SuppressWarnings("unchecked") EntityType entityType = (EntityType)Registry.ENTITY_TYPE.get(identifier); DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); entityTypeAttributes.build(builder, DefaultAttributeRegistry.get(entityType)); this.containers.put(entityType, builder.build()); } + + this.containers.forEach((type, container) -> { + boolean l = container.has(DataAttributesAPI.getAttribute(new Identifier("dataattributes:level")).get()); + boolean l2 = container.has(DataAttributesAPI.getAttribute(new Identifier("playerex:constitution")).get()); + + System.out.println("TEST#1: " + type.toString() + "; level: " + l + "; constitution: " + l2); + }); } @Override diff --git a/src/main/java/com/github/clevernucleus/dataattributes/impl/EntityTypeAttributes.java b/src/main/java/com/github/clevernucleus/dataattributes/impl/EntityTypeAttributes.java index 6a9a2400..2a3c3dc5 100644 --- a/src/main/java/com/github/clevernucleus/dataattributes/impl/EntityTypeAttributes.java +++ b/src/main/java/com/github/clevernucleus/dataattributes/impl/EntityTypeAttributes.java @@ -14,7 +14,7 @@ import net.minecraft.util.registry.Registry; public final class EntityTypeAttributes { - private final Map attributes; + public final Map attributes; public EntityTypeAttributes() { this.attributes = new HashMap(); diff --git a/src/main/java/com/github/clevernucleus/dataattributes/mixin/SimpleRegistryMixin.java b/src/main/java/com/github/clevernucleus/dataattributes/mixin/SimpleRegistryMixin.java index 88aed7b7..5a24d78d 100644 --- a/src/main/java/com/github/clevernucleus/dataattributes/mixin/SimpleRegistryMixin.java +++ b/src/main/java/com/github/clevernucleus/dataattributes/mixin/SimpleRegistryMixin.java @@ -3,7 +3,9 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.function.Function; import org.apache.commons.lang3.Validate; import org.spongepowered.asm.mixin.Final; @@ -15,13 +17,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.github.clevernucleus.dataattributes.mutable.MutableSimpleRegistry; -import com.google.common.collect.BiMap; import com.mojang.serialization.Lifecycle; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.ObjectList; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryEntry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.SimpleRegistry; @@ -30,7 +32,7 @@ abstract class SimpleRegistryMixin implements MutableSimpleRegistry { @Final @Shadow - private ObjectList rawIdToEntry; + private ObjectList> rawIdToEntry; @Final @Shadow @@ -38,11 +40,19 @@ abstract class SimpleRegistryMixin implements MutableSimpleRegistry { @Final @Shadow - private BiMap idToEntry; + private Map> idToEntry; @Final @Shadow - private BiMap, T> keyToEntry; + private Map, RegistryEntry.Reference> keyToEntry; + + @Final + @Shadow + private Map> valueToEntry; + + @Final + @Shadow + private Function> valueToEntryFunction; @Final @Shadow @@ -51,6 +61,9 @@ abstract class SimpleRegistryMixin implements MutableSimpleRegistry { @Shadow private Lifecycle lifecycle; + @Shadow + private List> cachedEntries; + @Shadow private int nextId; @@ -62,10 +75,43 @@ private void init(CallbackInfo info) { this.idCache = new HashSet(); } + @SuppressWarnings("unchecked") + @Inject(method = "assertNotFrozen", at = @At("HEAD"), cancellable = true) + private void unfreeze(CallbackInfo info) { + if((SimpleRegistry)(Object)this == Registry.ATTRIBUTE) { + info.cancel(); + } + } + @SuppressWarnings("deprecation") private void remove(RegistryKey key, Lifecycle lifecycle) { Validate.notNull(key); + RegistryEntry.Reference reference = this.keyToEntry.get(key); + T value = reference.value(); + final int rawId = this.entryToRawId.getInt(value); + + this.rawIdToEntry.remove(rawId); + this.valueToEntry.remove(value); + this.idToEntry.remove(key.getValue()); + this.keyToEntry.remove(key); + this.nextId--; + this.lifecycle = this.lifecycle.add(lifecycle); + this.entryToLifecycle.remove(value); + this.cachedEntries = null; + this.entryToRawId.remove(value); + + for(T t : this.entryToRawId.keySet()) { + int i = this.entryToRawId.get(t); + + if(i > rawId) { + this.entryToRawId.replace(t, i - 1); + } + } + + /* + Validate.notNull(key); + T entry = this.keyToEntry.get(key); final int rawId = this.entryToRawId.getInt(entry); @@ -84,7 +130,7 @@ private void remove(RegistryKey key, Lifecycle lifecycle) { } } - this.rawIdToEntry.remove(rawId); + this.rawIdToEntry.remove(rawId);*/ } @SuppressWarnings("unchecked") diff --git a/src/main/resources/data/dataattributes/attributes/entity_types.json b/src/main/resources/data/dataattributes/attributes/entity_types.json new file mode 100644 index 00000000..7981a3f1 --- /dev/null +++ b/src/main/resources/data/dataattributes/attributes/entity_types.json @@ -0,0 +1,7 @@ +{ + "values": { + "minecraft:player": { + "dataattributes:level": 0.0 + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/dataattributes/attributes/overrides/level.json b/src/main/resources/data/dataattributes/attributes/overrides/level.json new file mode 100644 index 00000000..f4de0963 --- /dev/null +++ b/src/main/resources/data/dataattributes/attributes/overrides/level.json @@ -0,0 +1,7 @@ +{ + "fallbackValue": 0.0, + "minValue": 0.0, + "maxValue": 2147483647.0, + "translationKey": "playerex.attribute.name.level", + "stackingBehaviour": "FLAT" +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2e1eff73..2bc61b85 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,9 +26,9 @@ "dataattributes.mixins.json" ], "depends": { - "fabricloader": ">=0.12.12", - "fabric": ">=0.46.1", - "minecraft": "1.18.x", + "fabricloader": ">=0.13.3", + "fabric": ">=0.51.1", + "minecraft": "1.18.2", "java": ">=17" } } \ No newline at end of file