-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- differentiate "synced" Index-Key-Value registries from simple Key-Value registries - start preparing registry remapping
- Loading branch information
1 parent
6ade139
commit f482232
Showing
24 changed files
with
605 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/class_2929Mixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.registry.sync; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import net.minecraft.class_2929; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; | ||
|
||
@Mixin(class_2929.class) | ||
public abstract class class_2929Mixin<T> implements IdsHolder<T> { | ||
@Shadow | ||
@Nullable | ||
public abstract T getById(int id); | ||
|
||
@Override | ||
public IdsHolder<T> fabric$new() { | ||
return (IdsHolder<T>) new class_2929<>(256); | ||
} | ||
|
||
@Override | ||
public int fabric$nextId() { | ||
int id = 0; | ||
|
||
while (this.getById(id) != null) id++; | ||
|
||
return id; | ||
} | ||
} |
49 changes: 39 additions & 10 deletions
49
.../main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/SimpleRegistryMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,52 @@ | ||
package net.legacyfabric.fabric.mixin.registry.sync.versioned; | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHolder; | ||
package net.legacyfabric.fabric.mixin.registry.sync.versioned; | ||
|
||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import net.minecraft.class_2929; | ||
import net.minecraft.util.registry.SimpleRegistry; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
|
||
@Mixin(SimpleRegistry.class) | ||
public abstract class SimpleRegistryMixin<K, V> implements RegistryHolder<V> { | ||
public abstract class SimpleRegistryMixin<K, V> implements SyncedRegistryHolder<V>, SyncedRegistrable<V> { | ||
@Shadow | ||
public abstract void add(int id, K identifier, V object); | ||
|
||
@Shadow | ||
@Final | ||
protected class_2929<V> field_13718; | ||
|
||
@Override | ||
public void fabric$register(int rawId, Identifier identifier, V value) { | ||
fabric$getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); | ||
add(rawId, fabric$toKeyType(identifier), value); | ||
fabric$getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); | ||
} | ||
|
||
@Override | ||
public void register(int rawId, Identifier identifier, V value) { | ||
getBeforeAddedCallback().invoker().onEntryAdding(rawId, identifier, value); | ||
add(rawId, toKeyType(identifier), value); | ||
getEntryAddedCallback().invoker().onEntryAdded(rawId, identifier, value); | ||
public IdsHolder<V> fabric$getIdsHolder() { | ||
return (IdsHolder<V>) field_13718; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
"class_2929Mixin", | ||
"versioned.SimpleRegistryMixin" | ||
], | ||
"client": [ | ||
|
39 changes: 35 additions & 4 deletions
39
...c-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,59 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.api.registry.v2; | ||
|
||
import java.util.function.Function; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.RegistryHolder; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.impl.registry.RegistryHelperImplementation; | ||
|
||
import java.util.function.Function; | ||
|
||
public class RegistryHelper { | ||
public static <T> void register(RegistryHolder<T> registry, Identifier identifier, T value) { | ||
RegistryHelperImplementation.register(registry, identifier, value); | ||
} | ||
|
||
public static <T> void registry(Identifier registryId, Identifier identifier, T value) { | ||
public static <T> void register(Identifier registryId, Identifier identifier, T value) { | ||
register(RegistryHelperImplementation.getRegistry(registryId), identifier, value); | ||
} | ||
|
||
public static <T> T register(RegistryHolder<T> registry, Identifier identifier, Function<Integer, T> valueConstructor) { | ||
return RegistryHelperImplementation.register(registry, identifier, valueConstructor); | ||
} | ||
|
||
public static <T> T registry(Identifier registryId, Identifier identifier, Function<Integer, T> valueConstructor) { | ||
public static <T> T register(Identifier registryId, Identifier identifier, Function<Integer, T> valueConstructor) { | ||
return register(RegistryHelperImplementation.<T>getRegistry(registryId), identifier, valueConstructor); | ||
} | ||
|
||
public static void addRegistry(Identifier identifier, RegistryHolder<?> registryHolder) { | ||
RegistryHelperImplementation.registerRegistry(identifier, registryHolder); | ||
} | ||
|
||
public static <T> RegistryHolder<T> getRegistry(Identifier identifier) { | ||
return RegistryHelperImplementation.getRegistry(identifier); | ||
} | ||
|
||
public static <T> T getValue(Identifier registryId, Identifier identifier) { | ||
return RegistryHelperImplementation.<T>getRegistry(registryId) | ||
.fabric$getValue(identifier); | ||
} | ||
|
||
public static <T> T getValue(RegistryHolder<T> registry, Identifier identifier) { | ||
return registry.fabric$getValue(identifier); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
...c-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryHolder.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...sync-api-v2/common/src/main/java/net/legacyfabric/fabric/api/registry/v2/RegistryIds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.api.registry.v2; | ||
|
||
import net.legacyfabric.fabric.api.util.Identifier; | ||
|
||
public class RegistryIds { | ||
public static final Identifier ITEMS = new Identifier("items"); | ||
public static final Identifier BLOCKS = new Identifier("blocks"); | ||
public static final Identifier BLOCK_ENTITY_TYPES = new Identifier("block_entity_types"); | ||
public static final Identifier STATUS_EFFECTS = new Identifier("status_effects"); | ||
public static final Identifier ENCHANTMENTS = new Identifier("enchantments"); | ||
public static final Identifier BIOMES = new Identifier("biomes"); | ||
public static final Identifier ENTITY_TYPES = new Identifier("entity_types"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletion
19
...src/main/java/net/legacyfabric/fabric/api/registry/v2/event/RegistryInitializedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.