use of net.minecraft.util.Identifier in project fabric by FabricMC.
the class KeyBindingModClient method onInitializeClient.
@Override
public void onInitializeClient() {
KeyBindingRegistry.INSTANCE.addCategory("fabric.test");
KeyBindingRegistry.INSTANCE.register(FabricKeyBinding.Builder.create(new Identifier("fabric:test"), InputUtil.Type.KEYSYM, 37, "fabric.test").build());
}
use of net.minecraft.util.Identifier in project fabric by FabricMC.
the class ResourceReloadModClient method onInitializeClient.
@Override
public void onInitializeClient() {
for (int i = 64; i >= 2; i--) {
final int _i = i;
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public void apply(ResourceManager var1) {
System.out.println("Reloading (should run as #" + _i + ")");
}
@Override
public Identifier getFabricId() {
return new Identifier("fabric:rrmc" + _i);
}
@Override
public Collection<Identifier> getFabricDependencies() {
return Collections.singletonList(new Identifier("fabric:rrmc" + (_i - 1)));
}
});
}
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("fabric:rrmc1");
}
@Override
public void apply(ResourceManager var1) {
System.out.println("Reloading (should run as #1)");
}
});
ResourceManagerHelper.get(ResourceType.ASSETS).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("fabric:rrmc_should_not_resolve");
}
@Override
public Collection<Identifier> getFabricDependencies() {
return Collections.singletonList(new Identifier("fabric:rrmc_nonexistent"));
}
@Override
public void apply(ResourceManager var1) {
}
});
}
use of net.minecraft.util.Identifier in project fabric by FabricMC.
the class MixinIdRegistry method remap.
@Override
public void remap(String name, Object2IntMap<Identifier> remoteIndexedEntries, RemapMode mode) throws RemapException {
// noinspection unchecked, ConstantConditions
SimpleRegistry<Object> registry = (SimpleRegistry<Object>) (Object) this;
// Throw on invalid conditions.
switch(mode) {
case AUTHORITATIVE:
break;
case REMOTE:
{
List<String> strings = null;
for (Identifier remoteId : remoteIndexedEntries.keySet()) {
if (!entries.keySet().contains(remoteId)) {
if (strings == null) {
strings = new ArrayList<>();
}
strings.add(" - " + remoteId);
}
}
if (strings != null) {
StringBuilder builder = new StringBuilder("Received ID map for " + name + " contains IDs unknown to the receiver!");
for (String s : strings) {
builder.append('\n').append(s);
}
throw new RemapException(builder.toString());
}
}
break;
case EXACT:
{
if (!entries.keySet().equals(remoteIndexedEntries.keySet())) {
List<String> strings = new ArrayList<>();
for (Identifier remoteId : remoteIndexedEntries.keySet()) {
if (!entries.keySet().contains(remoteId)) {
strings.add(" - " + remoteId + " (missing on local)");
}
}
for (Identifier localId : registry.getIds()) {
if (!remoteIndexedEntries.keySet().contains(localId)) {
strings.add(" - " + localId + " (missing on remote)");
}
}
StringBuilder builder = new StringBuilder("Local and remote ID sets for " + name + " do not match!");
for (String s : strings) {
builder.append('\n').append(s);
}
throw new RemapException(builder.toString());
}
}
break;
}
// compatibility.
if (fabric_prevIndexedEntries == null) {
fabric_prevIndexedEntries = new Object2IntOpenHashMap<>();
fabric_prevEntries = HashBiMap.create(entries);
for (Object o : registry) {
fabric_prevIndexedEntries.put(registry.getId(o), registry.getRawId(o));
}
}
Int2ObjectMap<Identifier> oldIdMap = new Int2ObjectOpenHashMap<>();
for (Object o : registry) {
oldIdMap.put(registry.getRawId(o), registry.getId(o));
}
// local side to the new entry list. For REMOTE, we instead drop them.
switch(mode) {
case AUTHORITATIVE:
{
int maxValue = 0;
Object2IntMap<Identifier> oldRemoteIndexedEntries = remoteIndexedEntries;
remoteIndexedEntries = new Object2IntOpenHashMap<>();
for (Identifier id : oldRemoteIndexedEntries.keySet()) {
int v = oldRemoteIndexedEntries.getInt(id);
remoteIndexedEntries.put(id, v);
if (v > maxValue)
maxValue = v;
}
for (Identifier id : registry.getIds()) {
if (!remoteIndexedEntries.containsKey(id)) {
FABRIC_LOGGER.warn("Adding " + id + " to saved/remote registry.");
remoteIndexedEntries.put(id, ++maxValue);
}
}
}
break;
case REMOTE:
{
// TODO: Is this what mods really want?
Set<Identifier> droppedIds = new HashSet<>();
for (Identifier id : registry.getIds()) {
if (!remoteIndexedEntries.containsKey(id)) {
Object object = registry.get(id);
int rid = registry.getRawId(object);
droppedIds.add(id);
// Emit RemoveObject events for removed objects.
// noinspection unchecked
fabric_getRemoveObjectEvent().invoker().onEntryRemoved(rid, id, (T) object);
}
}
// note: indexedEntries cannot be safely remove()d from
entries.keySet().removeAll(droppedIds);
}
break;
}
Int2IntMap idMap = new Int2IntOpenHashMap();
for (Object o : indexedEntries) {
Identifier id = registry.getId(o);
int rid = registry.getRawId(o);
// see above note
if (remoteIndexedEntries.containsKey(id)) {
idMap.put(rid, remoteIndexedEntries.getInt(id));
}
}
// entries was handled above, if it was necessary.
indexedEntries.clear();
nextId = 0;
List<Identifier> orderedRemoteEntries = new ArrayList<>(remoteIndexedEntries.keySet());
orderedRemoteEntries.sort(Comparator.comparingInt(remoteIndexedEntries::getInt));
for (Identifier identifier : orderedRemoteEntries) {
int id = remoteIndexedEntries.getInt(identifier);
T object = entries.get(identifier);
// throw an exception otherwise.
if (object == null) {
if (mode != RemapMode.AUTHORITATIVE) {
throw new RemapException(identifier + " missing from registry, but requested!");
} else {
FABRIC_LOGGER.warn(identifier + " missing from registry, but requested!");
}
continue;
}
// Add the new object, increment nextId to match.
indexedEntries.put(object, id);
if (nextId <= id) {
nextId = id + 1;
}
}
// noinspection unchecked
fabric_getRemapEvent().invoker().onRemap(new RemapStateImpl(registry, oldIdMap, idMap));
}
use of net.minecraft.util.Identifier in project fabric by FabricMC.
the class MixinIdRegistry method unmap.
@Override
public void unmap(String name) throws RemapException {
if (fabric_prevIndexedEntries != null) {
List<Identifier> addedIds = new ArrayList<>();
// Emit AddObject events for previously culled objects.
for (Identifier id : fabric_prevEntries.keySet()) {
if (!entries.containsKey(id)) {
assert fabric_prevIndexedEntries.containsKey(id);
addedIds.add(id);
}
}
entries.clear();
entries.putAll(fabric_prevEntries);
remap(name, fabric_prevIndexedEntries, RemapMode.AUTHORITATIVE);
for (Identifier id : addedIds) {
fabric_getAddObjectEvent().invoker().onEntryAdded(indexedEntries.getId(entries.get(id)), id, entries.get(id));
}
fabric_prevIndexedEntries = null;
fabric_prevEntries = null;
}
}
use of net.minecraft.util.Identifier in project fabric by FabricMC.
the class RegistrySyncManager method apply.
public static void apply(CompoundTag tag, RemappableRegistry.RemapMode mode) throws RemapException {
CompoundTag mainTag = tag.getCompound("registries");
Set<String> containedRegistries = Sets.newHashSet(mainTag.getKeys());
for (Identifier registryId : Registry.REGISTRIES.getIds()) {
if (!containedRegistries.remove(registryId.toString())) {
continue;
}
CompoundTag registryTag = mainTag.getCompound(registryId.toString());
MutableRegistry registry = Registry.REGISTRIES.get(registryId);
if (registry instanceof RemappableRegistry) {
Object2IntMap<Identifier> idMap = new Object2IntOpenHashMap<>();
for (String key : registryTag.getKeys()) {
idMap.put(new Identifier(key), registryTag.getInt(key));
}
((RemappableRegistry) registry).remap(registryId.toString(), idMap, mode);
}
}
if (!containedRegistries.isEmpty()) {
LOGGER.warn("[fabric-registry-sync] Could not find the following registries: " + Joiner.on(", ").join(containedRegistries));
}
}
Aggregations