Fix mixin crash

This commit is contained in:
embeddedt 2023-04-29 16:36:10 -04:00
parent 5ac369acb8
commit 21177ea0e4
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 87 additions and 65 deletions

View File

@ -9,6 +9,7 @@ import net.minecraftforge.client.ItemModelMesherForge;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IRegistryDelegate;
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
import org.embeddedt.modernfix.util.ItemMesherMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.*;
@ -37,71 +38,7 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
private void replaceLocationMap(CallbackInfo ci) {
overrideLocations = new HashMap<>();
// need to replace this map because mods query locations through it
locations = new Map<IRegistryDelegate<Item>, ModelResourceLocation>() {
@Override
public int size() {
return ForgeRegistries.ITEMS.getValues().size();
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(Object key) {
return true;
}
@Override
public boolean containsValue(Object value) {
return false;
}
@Override
public ModelResourceLocation get(Object key) {
return getLocation(((IRegistryDelegate<Item>)key).get());
}
@Nullable
@Override
public ModelResourceLocation put(IRegistryDelegate<Item> key, ModelResourceLocation value) {
throw new UnsupportedOperationException();
}
@Override
public ModelResourceLocation remove(Object key) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(@NotNull Map<? extends IRegistryDelegate<Item>, ? extends ModelResourceLocation> m) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Set<IRegistryDelegate<Item>> keySet() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Collection<ModelResourceLocation> values() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Set<Entry<IRegistryDelegate<Item>, ModelResourceLocation>> entrySet() {
throw new UnsupportedOperationException();
}
};
locations = new ItemMesherMap(this::getLocation);
}
private ModelResourceLocation getLocation(Item item) {

View File

@ -0,0 +1,85 @@
package org.embeddedt.modernfix.util;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IRegistryDelegate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
public class ItemMesherMap implements Map<IRegistryDelegate<Item>, ModelResourceLocation> {
private final Function<Item, ModelResourceLocation> getLocation;
public ItemMesherMap(Function<Item, ModelResourceLocation> getLocation) {
this.getLocation = getLocation;
}
@Override
public int size() {
return ForgeRegistries.ITEMS.getValues().size();
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(Object key) {
return true;
}
@Override
public boolean containsValue(Object value) {
return false;
}
@Override
public ModelResourceLocation get(Object key) {
return getLocation.apply(((IRegistryDelegate<Item>)key).get());
}
@Nullable
@Override
public ModelResourceLocation put(IRegistryDelegate<Item> key, ModelResourceLocation value) {
throw new UnsupportedOperationException();
}
@Override
public ModelResourceLocation remove(Object key) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(@NotNull Map<? extends IRegistryDelegate<Item>, ? extends ModelResourceLocation> m) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Set<IRegistryDelegate<Item>> keySet() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Collection<ModelResourceLocation> values() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public Set<Map.Entry<IRegistryDelegate<Item>, ModelResourceLocation>> entrySet() {
throw new UnsupportedOperationException();
}
}