mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
remap ItemModelMap
This commit is contained in:
parent
61d8ac9778
commit
a9853c2d45
9 changed files with 109 additions and 15 deletions
src/main
java/net/fabricmc/fabric
mixin/registry
registry
resources
|
@ -66,7 +66,7 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
|
|||
IdRegistry<Object> registry = (IdRegistry<Object>) (Object) this;
|
||||
if (listeners != null) {
|
||||
for (RegistryListener listener : listeners) {
|
||||
listener.beforeRegistered(registry, id, identifier, object, !registry.contains(identifier));
|
||||
listener.beforeRegistryRegistration(registry, id, identifier, object, !registry.contains(identifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
|
|||
|
||||
if (listeners != null) {
|
||||
for (RegistryListener listener : listeners) {
|
||||
listener.beforeCleared(registry);
|
||||
listener.beforeRegistryCleared(registry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
|
|||
|
||||
if (listeners != null) {
|
||||
for (RegistryListener listener : listeners) {
|
||||
listener.beforeRegistered(registry, id, identifier, object, false);
|
||||
listener.beforeRegistryRegistration(registry, id, identifier, object, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018 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.fabricmc.fabric.mixin.registry.client;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.fabricmc.fabric.registry.ListenableRegistry;
|
||||
import net.fabricmc.fabric.registry.RegistryListener;
|
||||
import net.minecraft.client.render.item.ItemModelMap;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedModelManager;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(ItemModelMap.class)
|
||||
public class MixinItemModelMap implements RegistryListener<Item> {
|
||||
@Shadow
|
||||
public Int2ObjectMap<ModelIdentifier> field_4129;
|
||||
@Shadow
|
||||
private Int2ObjectMap<BakedModel> field_4130;
|
||||
|
||||
private Map<Identifier, ModelIdentifier> fabricModelIdMap;
|
||||
private Map<Identifier, BakedModel> fabricModelMap;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void onInit(BakedModelManager bakedModelManager, CallbackInfo info) {
|
||||
((ListenableRegistry<Item>) Registry.ITEMS).registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistryCleared(Registry<Item> registry) {
|
||||
if (fabricModelIdMap == null) {
|
||||
fabricModelIdMap = new HashMap<>();
|
||||
fabricModelMap = new HashMap<>();
|
||||
}
|
||||
|
||||
for (Identifier id : registry.keys()) {
|
||||
Item object = registry.get(id);
|
||||
int rawId = registry.getRawId(object);
|
||||
ModelIdentifier modelId = field_4129.get(rawId);
|
||||
BakedModel bakedModel = field_4130.get(rawId);
|
||||
|
||||
if (modelId != null) {
|
||||
fabricModelIdMap.put(id, modelId);
|
||||
}
|
||||
|
||||
if (bakedModel != null) {
|
||||
fabricModelMap.put(id, bakedModel);
|
||||
}
|
||||
}
|
||||
|
||||
field_4129.clear();
|
||||
field_4130.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistryRegistration(Registry<Item> registry, int id, Identifier identifier, Item object, boolean isNew) {
|
||||
if (fabricModelIdMap != null && fabricModelIdMap.containsKey(identifier)) {
|
||||
field_4129.put(id, fabricModelIdMap.get(identifier));
|
||||
}
|
||||
|
||||
if (fabricModelMap != null && fabricModelMap.containsKey(identifier)) {
|
||||
field_4130.put(id, fabricModelMap.get(identifier));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,6 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public interface RegistryListener<T> {
|
||||
default void beforeCleared(Registry<T> registry) {}
|
||||
default void beforeRegistered(Registry<T> registry, int id, Identifier identifier, T object, boolean isNew) {}
|
||||
default void beforeRegistryCleared(Registry<T> registry) {}
|
||||
default void beforeRegistryRegistration(Registry<T> registry, int id, Identifier identifier, T object, boolean isNew) {}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ import net.minecraft.world.biome.Biome;
|
|||
|
||||
public class BootstrapBiomeRegistryListener implements RegistryListener<Biome> {
|
||||
@Override
|
||||
public void beforeCleared(Registry<Biome> registry) {
|
||||
public void beforeRegistryCleared(Registry<Biome> registry) {
|
||||
((ExtendedIdList) Biome.PARENT_BIOME_ID_MAP).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistered(Registry<Biome> registry, int id, Identifier identifier, Biome object, boolean isNew) {
|
||||
public void beforeRegistryRegistration(Registry<Biome> registry, int id, Identifier identifier, Biome object, boolean isNew) {
|
||||
// refer net.minecraft.biome.Biomes
|
||||
if (object.hasParent()) {
|
||||
Biome.PARENT_BIOME_ID_MAP.add(object, id);
|
||||
|
|
|
@ -26,12 +26,12 @@ import net.minecraft.util.registry.Registry;
|
|||
|
||||
public class BootstrapBlockRegistryListener implements RegistryListener<Block> {
|
||||
@Override
|
||||
public void beforeCleared(Registry<Block> registry) {
|
||||
public void beforeRegistryCleared(Registry<Block> registry) {
|
||||
((ExtendedIdList) Block.BLOCKSTATE_ID_LIST).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistered(Registry<Block> registry, int id, Identifier identifier, Block object, boolean isNew) {
|
||||
public void beforeRegistryRegistration(Registry<Block> registry, int id, Identifier identifier, Block object, boolean isNew) {
|
||||
// refer net.minecraft.block.Blocks
|
||||
for (BlockState state : object.getStateFactory().getStates()) {
|
||||
state.method_11590();
|
||||
|
|
|
@ -27,12 +27,12 @@ import net.minecraft.util.registry.Registry;
|
|||
|
||||
public class BootstrapFluidRegistryListener implements RegistryListener<Fluid> {
|
||||
@Override
|
||||
public void beforeCleared(Registry<Fluid> registry) {
|
||||
public void beforeRegistryCleared(Registry<Fluid> registry) {
|
||||
((ExtendedIdList) Block.BLOCKSTATE_ID_LIST).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistered(Registry<Fluid> registry, int id, Identifier identifier, Fluid object, boolean isNew) {
|
||||
public void beforeRegistryRegistration(Registry<Fluid> registry, int id, Identifier identifier, Fluid object, boolean isNew) {
|
||||
// refer net.minecraft.fluid.Fluids
|
||||
for (FluidState state : object.getStateFactory().getStates()) {
|
||||
Fluid.field_15904.method_10205(state);
|
||||
|
|
|
@ -25,12 +25,12 @@ import net.minecraft.util.registry.Registry;
|
|||
|
||||
public class BootstrapItemRegistryListener implements RegistryListener<Item> {
|
||||
@Override
|
||||
public void beforeCleared(Registry<Item> registry) {
|
||||
public void beforeRegistryCleared(Registry<Item> registry) {
|
||||
Item.BLOCK_ITEM_MAP.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistered(Registry<Item> registry, int id, Identifier identifier, Item object, boolean isNew) {
|
||||
public void beforeRegistryRegistration(Registry<Item> registry, int id, Identifier identifier, Item object, boolean isNew) {
|
||||
// refer net.minecraft.item.Items
|
||||
if (object instanceof ItemBlock) {
|
||||
((ItemBlock) object).method_7713(Item.BLOCK_ITEM_MAP, object);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class IdListUpdater<K, V> implements RegistryListener<K> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeCleared(Registry<K> registry) {
|
||||
public void beforeRegistryCleared(Registry<K> registry) {
|
||||
mapperCache.clear();
|
||||
for (Identifier id : registry.keys()) {
|
||||
int rawId = registry.getRawId(registry.get(id));
|
||||
|
@ -56,7 +56,7 @@ public class IdListUpdater<K, V> implements RegistryListener<K> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistered(Registry<K> registry, int id, Identifier identifier, K object, boolean isNew) {
|
||||
public void beforeRegistryRegistration(Registry<K> registry, int id, Identifier identifier, K object, boolean isNew) {
|
||||
if (mapperCache.containsKey(identifier)) {
|
||||
mappers.add(mapperCache.get(identifier), id);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"networking.MixinClientPlayNetworkHandler",
|
||||
"registry.client.MixinBlockColorMap",
|
||||
"registry.client.MixinItemColorMap",
|
||||
"registry.client.MixinItemModelMap",
|
||||
"resources.MixinMinecraftGame"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue