Search in sources :

Example 61 with Identifier

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());
}
Also used : Identifier(net.minecraft.util.Identifier)

Example 62 with Identifier

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) {
        }
    });
}
Also used : SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) Identifier(net.minecraft.util.Identifier) Collection(java.util.Collection) ResourceManager(net.minecraft.resource.ResourceManager)

Example 63 with Identifier

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));
}
Also used : SimpleRegistry(net.minecraft.util.registry.SimpleRegistry) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) RemapStateImpl(net.fabricmc.fabric.impl.registry.RemapStateImpl) RemapException(net.fabricmc.fabric.impl.registry.RemapException) Identifier(net.minecraft.util.Identifier) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)

Example 64 with Identifier

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;
    }
}
Also used : Identifier(net.minecraft.util.Identifier)

Example 65 with Identifier

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));
    }
}
Also used : Identifier(net.minecraft.util.Identifier) MutableRegistry(net.minecraft.util.registry.MutableRegistry) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

Identifier (net.minecraft.util.Identifier)343 NbtList (net.minecraft.nbt.NbtList)36 ItemStack (net.minecraft.item.ItemStack)31 Item (net.minecraft.item.Item)28 NbtCompound (net.minecraft.nbt.NbtCompound)22 NbtElement (net.minecraft.nbt.NbtElement)22 Inject (org.spongepowered.asm.mixin.injection.Inject)22 IOException (java.io.IOException)18 Block (net.minecraft.block.Block)18 MinecraftClient (net.minecraft.client.MinecraftClient)15 BlockItem (net.minecraft.item.BlockItem)15 BlockPos (net.minecraft.util.math.BlockPos)15 Map (java.util.Map)12 BlockState (net.minecraft.block.BlockState)12 ArrayList (java.util.ArrayList)11 VertexConsumer (net.minecraft.client.render.VertexConsumer)11 ResourceManager (net.minecraft.resource.ResourceManager)11 SoundEvent (net.minecraft.sound.SoundEvent)11 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)10 LiteralText (net.minecraft.text.LiteralText)10