Skip to content

Commit

Permalink
Small mixins clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Dec 7, 2024
1 parent c67afeb commit c568aa5
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class BiDefaultedRegistryMixin<K, V> implements SyncedFabricRegi

@Override
public V fabric$getValue(Identifier id) {
K key = (K) fabric$toKeyType(id);
K key = fabric$toKeyType(id);
V value = ((BiDefaultedRegistry<K, V>) (Object) this).get(key);

if (value == this.defaultValue && !Objects.equals(this.defaultKey.toString(), key.toString())) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,33 @@

@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixin<K, V> implements SyncedFabricRegistry<V>, SyncedRegistrable<V>, DesynchronizeableRegistrable {
// 1.8+
@Shadow
public abstract void add(int id, K identifier, V object);

// 1.9+
@Mutable
@Shadow
@Final
protected class_2929<V> field_13718;

// 1.8+
@Shadow
public abstract K getIdentifier(Object par1);

// 1.9+
@Shadow
public abstract int getRawId(Object object);

// 1.7+
@Shadow
public abstract Object getByRawId(int index);

@Unique
private boolean synchronize = true;

@Override
public void setSynchronize(boolean isSynchronize) {
public void fabric$setSynchronize(boolean isSynchronize) {
this.synchronize = isSynchronize;
}

@Override
public boolean canSynchronize() {
public boolean fabric$canSynchronize() {
return this.synchronize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@
import net.legacyfabric.fabric.api.util.Identifier;

@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixinV2<V> implements SyncedFabricRegistry<V>, SyncedRegistrable<V>, DesynchronizeableRegistrable {
// 1.8+
public abstract class SimpleRegistryMixin<V> implements SyncedFabricRegistry<V>, SyncedRegistrable<V>, DesynchronizeableRegistrable {
@Shadow
public abstract void add(int id, String identifier, Object object);

// 1.9+
@Shadow
public abstract int getRawId(Object object);

// 1.7+
@Shadow
public abstract Object getByRawId(int index);

Expand All @@ -62,12 +59,12 @@ public abstract class SimpleRegistryMixinV2<V> implements SyncedFabricRegistry<V
private boolean synchronize = true;

@Override
public void setSynchronize(boolean isSynchronize) {
public void fabric$setSynchronize(boolean isSynchronize) {
this.synchronize = isSynchronize;
}

@Override
public boolean canSynchronize() {
public boolean fabric$canSynchronize() {
return this.synchronize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"mixins": [
"versioned.BiDefaultedRegistryMixin",
"versioned.PlayerManagerMixin",
"versioned.SimpleRegistryMixinV2"
"versioned.SimpleRegistryMixin"
],
"client": [
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class BiDefaultedRegistryMixin<K, V> implements SyncedFabricRegi

@Override
public V fabric$getValue(Identifier id) {
K key = (K) fabric$toKeyType(id);
K key = fabric$toKeyType(id);
V value = ((BiDefaultedRegistry<K, V>) (Object) this).get(key);

if (value == this.defaultValue && !Objects.equals(this.defaultKey.toString(), key.toString())) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,16 @@
import net.legacyfabric.fabric.api.util.Identifier;

@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixinV2<K, V> implements SyncedFabricRegistry<V>, SyncedRegistrable<V>, DesynchronizeableRegistrable {
// 1.8+
public abstract class SimpleRegistryMixin<K, V> implements SyncedFabricRegistry<V>, SyncedRegistrable<V>, DesynchronizeableRegistrable {
@Shadow
public abstract void add(int id, K identifier, V object);

// 1.8+
@Shadow
public abstract K getIdentifier(Object par1);

// 1.9+
@Shadow
public abstract int getRawId(Object object);

// 1.7+
@Shadow
public abstract Object getByRawId(int index);

Expand All @@ -63,12 +59,12 @@ public abstract class SimpleRegistryMixinV2<K, V> implements SyncedFabricRegistr
private boolean synchronize = true;

@Override
public void setSynchronize(boolean isSynchronize) {
public void fabric$setSynchronize(boolean isSynchronize) {
this.synchronize = isSynchronize;
}

@Override
public boolean canSynchronize() {
public boolean fabric$canSynchronize() {
return this.synchronize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"mixins": [
"versioned.BiDefaultedRegistryMixin",
"versioned.PlayerManagerMixin",
"versioned.SimpleRegistryMixinV2"
"versioned.SimpleRegistryMixin"
],
"client": [
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package net.legacyfabric.fabric.api.registry.v2.registry.registrable;

public interface DesynchronizeableRegistrable {
default boolean canSynchronize() {
default boolean fabric$canSynchronize() {
return true;
}

void setSynchronize(boolean synchronize);
void fabric$setSynchronize(boolean synchronize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static <T> void registerRegistry(Identifier identifier, FabricRegistry<T>
boolean remappable = true;

if (holder instanceof DesynchronizeableRegistrable) {
remappable = ((DesynchronizeableRegistrable) holder).canSynchronize();
remappable = ((DesynchronizeableRegistrable) holder).fabric$canSynchronize();
}

if (holder instanceof SyncedRegistrableFabricRegistry && remappable) {
Expand Down Expand Up @@ -137,7 +137,7 @@ public static <T> void register(FabricRegistry<T> registry, Identifier identifie
boolean remappable = true;

if (registry instanceof DesynchronizeableRegistrable) {
remappable = ((DesynchronizeableRegistrable) registry).canSynchronize();
remappable = ((DesynchronizeableRegistrable) registry).fabric$canSynchronize();
}

if (registry instanceof SyncedRegistrable && remappable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder;

@Mixin(IdList.class)
public abstract class IdListMixinV2<T> implements IdsHolder<T> {
public abstract class IdListMixin<T> implements IdsHolder<T> {
@Shadow
public abstract T fromId(int index);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import net.legacyfabric.fabric.impl.registry.accessor.RegistryIdSetter;

@Mixin(MutableRegistry.class)
public abstract class MutableRegistryMixinV2<K, V> implements FabricRegistry<V>, RegistryIdSetter, Registrable<V> {
public abstract class MutableRegistryMixin<K, V> implements FabricRegistry<V>, RegistryIdSetter, Registrable<V> {
@Shadow
public abstract void put(Object key, Object value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable;

@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixinV2<K, V> implements SyncedRegistrableFabricRegistry<V>, DesynchronizeableRegistrable {
public abstract class SimpleRegistryMixin<K, V> implements SyncedRegistrableFabricRegistry<V>, DesynchronizeableRegistrable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"defaultRequire": 1
},
"mixins": [
"IdListMixinV2",
"MutableRegistryMixinV2",
"SimpleRegistryMixinV2",
"IdListMixin",
"MutableRegistryMixin",
"SimpleRegistryMixin",
"WorldSaveHandlerMixin"
],
"client": [
Expand Down

0 comments on commit c568aa5

Please sign in to comment.