-
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.
Start working on new registry remapper
- Loading branch information
1 parent
f482232
commit d949960
Showing
13 changed files
with
204 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
minVersionExcluded=1.10.2 | ||
minVersionExcluded=1.8.9 | ||
maxVersionIncluded=1.12.2 |
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
24 changes: 24 additions & 0 deletions
24
...common/src/main/java/net/legacyfabric/fabric/api/registry/v2/registry/SyncedRegistry.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,24 @@ | ||
/* | ||
* 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.registry; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistryHolder; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.SyncedRegistrable; | ||
|
||
public interface SyncedRegistry<T> extends SyncedRegistryHolder<T>, SyncedRegistrable<T> { | ||
} |
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
105 changes: 105 additions & 0 deletions
105
...c-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.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,105 @@ | ||
/* | ||
* 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.impl.registry; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.HashBiMap; | ||
|
||
import net.minecraft.nbt.NbtCompound; | ||
|
||
import net.legacyfabric.fabric.api.logger.v1.Logger; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.SyncedRegistry; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.impl.logger.LoggerImpl; | ||
|
||
public class RegistryRemapper<T> { | ||
protected static final Logger LOGGER = Logger.get(LoggerImpl.API, "RegistryRemapper"); | ||
private final SyncedRegistry<T> registry; | ||
private BiMap<Identifier, Integer> entryDump; | ||
private BiMap<Identifier, Integer> missingMap = HashBiMap.create(); | ||
|
||
public RegistryRemapper(SyncedRegistry<T> registry) { | ||
this.registry = registry; | ||
} | ||
|
||
public void dump() { | ||
if (this.entryDump != null && !this.entryDump.isEmpty()) return; | ||
|
||
this.entryDump = HashBiMap.create(); | ||
|
||
LOGGER.debug("Dumping registry %s.", this.registry.fabric$getId()); | ||
|
||
this.registry.stream() | ||
.collect(Collectors.toMap( | ||
this.registry::fabric$getId, | ||
this.registry::fabric$getRawId | ||
)) | ||
.entrySet() | ||
.stream() | ||
.filter(entry -> entry.getKey() != null && entry.getValue() != -1) | ||
.forEach(entry -> { | ||
T value = this.registry.fabric$getValue(entry.getKey()); | ||
LOGGER.debug("[%s] %s %s %s", this.registry.fabric$getId(), entry.getKey(), entry.getValue(), value); | ||
this.entryDump.put(entry.getKey(), entry.getValue()); | ||
}); | ||
} | ||
|
||
public NbtCompound toNbt() { | ||
this.dump(); | ||
|
||
NbtCompound nbt = new NbtCompound(); | ||
this.entryDump.forEach((key, value) -> nbt.putInt(key.toString(), value)); | ||
return nbt; | ||
} | ||
|
||
public void readNbt(NbtCompound tag) { | ||
this.entryDump = HashBiMap.create(); | ||
|
||
for (String key : tag.getKeys()) { | ||
Identifier identifier = new Identifier(key); | ||
int id = tag.getInt(key); | ||
this.entryDump.put(identifier, id); | ||
} | ||
} | ||
|
||
public void remap() { | ||
LOGGER.info("Remapping registry %s", this.registry.fabric$getId()); | ||
|
||
this.dump(); | ||
|
||
IdsHolder<T> dumpIds = getDumpIds(); | ||
} | ||
|
||
private IdsHolder<T> getDumpIds() { | ||
IdsHolder<T> ids = this.registry.fabric$getIdsHolder().fabric$new(); | ||
|
||
this.entryDump.forEach((id, rawId) -> { | ||
T value = this.registry.fabric$getValue(id); | ||
|
||
if (value == null) { | ||
LOGGER.warn("[%s] Missing entry %s with raw id %s", this.registry.fabric$getId(), id, rawId); | ||
this.missingMap.put(id, rawId); | ||
} else { | ||
ids.fabric$setValue(value, rawId); | ||
} | ||
}); | ||
} | ||
} |
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