Skip to content

Commit

Permalink
Debug and cleaning
Browse files Browse the repository at this point in the history
Commit purely for cleanliness and old debugging. Nothing new.
  • Loading branch information
CleverNucleus committed Jun 6, 2022
1 parent 0bffb8c commit 630b6cc
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'maven-publish'
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends LivingEntity> entityType = (EntityType<? extends LivingEntity>)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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraft.util.registry.Registry;

public final class EntityTypeAttributes {
private final Map<Identifier, Double> attributes;
public final Map<Identifier, Double> attributes;

public EntityTypeAttributes() {
this.attributes = new HashMap<Identifier, Double>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -30,19 +32,27 @@ abstract class SimpleRegistryMixin<T> implements MutableSimpleRegistry<T> {

@Final
@Shadow
private ObjectList<T> rawIdToEntry;
private ObjectList<RegistryEntry.Reference<T>> rawIdToEntry;

@Final
@Shadow
private Object2IntMap<T> entryToRawId;

@Final
@Shadow
private BiMap<Identifier, T> idToEntry;
private Map<Identifier, RegistryEntry.Reference<T>> idToEntry;

@Final
@Shadow
private BiMap<RegistryKey<T>, T> keyToEntry;
private Map<RegistryKey<T>, RegistryEntry.Reference<T>> keyToEntry;

@Final
@Shadow
private Map<T, RegistryEntry.Reference<T>> valueToEntry;

@Final
@Shadow
private Function<T, RegistryEntry.Reference<T>> valueToEntryFunction;

@Final
@Shadow
Expand All @@ -51,6 +61,9 @@ abstract class SimpleRegistryMixin<T> implements MutableSimpleRegistry<T> {
@Shadow
private Lifecycle lifecycle;

@Shadow
private List<RegistryEntry.Reference<T>> cachedEntries;

@Shadow
private int nextId;

Expand All @@ -62,10 +75,43 @@ private void init(CallbackInfo info) {
this.idCache = new HashSet<Identifier>();
}

@SuppressWarnings("unchecked")
@Inject(method = "assertNotFrozen", at = @At("HEAD"), cancellable = true)
private void unfreeze(CallbackInfo info) {
if((SimpleRegistry<T>)(Object)this == Registry.ATTRIBUTE) {
info.cancel();
}
}

@SuppressWarnings("deprecation")
private <V extends T> void remove(RegistryKey<T> key, Lifecycle lifecycle) {
Validate.notNull(key);

RegistryEntry.Reference<T> 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);
Expand All @@ -84,7 +130,7 @@ private <V extends T> void remove(RegistryKey<T> key, Lifecycle lifecycle) {
}
}
this.rawIdToEntry.remove(rawId);
this.rawIdToEntry.remove(rawId);*/
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": {
"minecraft:player": {
"dataattributes:level": 0.0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"fallbackValue": 0.0,
"minValue": 0.0,
"maxValue": 2147483647.0,
"translationKey": "playerex.attribute.name.level",
"stackingBehaviour": "FLAT"
}
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 630b6cc

Please sign in to comment.