mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 04:27:59 +01:00
Fixed crash when toggling pony rendering of certain mob types
This commit is contained in:
parent
fcbc95e14e
commit
844bced2db
4 changed files with 29 additions and 21 deletions
|
@ -0,0 +1,17 @@
|
|||
package com.minelittlepony.client.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.render.entity.EntityRendererFactory;
|
||||
import net.minecraft.client.render.entity.EntityRenderers;
|
||||
import net.minecraft.entity.EntityType;
|
||||
|
||||
@Mixin(EntityRenderers.class)
|
||||
public interface MixinEntityRenderers {
|
||||
@Accessor
|
||||
public static Map<EntityType<?>, EntityRendererFactory<?>> getRendererFactories() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -60,13 +60,13 @@ public final class MobRenderers {
|
|||
pony.switchRenderer(state, EntityType.STRIDER, ParaspriteRenderer::new);
|
||||
});
|
||||
|
||||
private final BiConsumer<Boolean, PonyRenderDispatcher> changer;
|
||||
private final BiConsumer<MobRenderers, PonyRenderDispatcher> changer;
|
||||
|
||||
public final String name;
|
||||
|
||||
private boolean lastState;
|
||||
|
||||
private MobRenderers(String name, BiConsumer<Boolean, PonyRenderDispatcher> changer) {
|
||||
private MobRenderers(String name, BiConsumer<MobRenderers, PonyRenderDispatcher> changer) {
|
||||
this.name = name;
|
||||
this.changer = changer;
|
||||
}
|
||||
|
@ -85,16 +85,15 @@ public final class MobRenderers {
|
|||
return option().get();
|
||||
}
|
||||
|
||||
public static MobRenderers register(String name, BiConsumer<Boolean, PonyRenderDispatcher> changer) {
|
||||
public static MobRenderers register(String name, BiConsumer<MobRenderers, PonyRenderDispatcher> changer) {
|
||||
return REGISTRY.computeIfAbsent(name, n -> new MobRenderers(name, changer));
|
||||
}
|
||||
|
||||
void apply(PonyRenderDispatcher dispatcher) {
|
||||
boolean state = get();
|
||||
if (state != lastState) {
|
||||
MineLittlePony.logger.info(String.format("Ponify %s [%B] -> [%B]", name, lastState, state));
|
||||
lastState = state;
|
||||
changer.accept(state, dispatcher);
|
||||
changer.accept(this, dispatcher);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,13 @@
|
|||
package com.minelittlepony.client.render;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.minelittlepony.client.mixin.MixinEntityRenderers;
|
||||
import com.minelittlepony.client.model.IPonyModel;
|
||||
import com.minelittlepony.client.model.entity.race.PlayerModels;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.common.mixin.MixinEntityRenderDispatcher;
|
||||
import com.minelittlepony.mson.api.Mson;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -38,8 +36,6 @@ public class PonyRenderDispatcher {
|
|||
|
||||
private LevitatingItemRenderer magicRenderer = new LevitatingItemRenderer();
|
||||
|
||||
private final Map<EntityType<?>, EntityRenderer<?>> renderMap = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* Registers all new player skin types. (currently only pony and slimpony).
|
||||
*/
|
||||
|
@ -71,18 +67,13 @@ public class PonyRenderDispatcher {
|
|||
* @param factory The replacement value
|
||||
* @param <T> The entity type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
<T extends Entity, V extends T> void switchRenderer(boolean state, EntityType<V> type, Function<EntityRendererFactory.Context, EntityRenderer<T>> factory) {
|
||||
if (state) {
|
||||
if (!renderMap.containsKey(type)) {
|
||||
renderMap.put(type, ((MixinEntityRenderDispatcher)MinecraftClient.getInstance().getEntityRenderDispatcher()).getEntityRenderers().get(type));
|
||||
<T extends Entity, V extends T> void switchRenderer(MobRenderers state, EntityType<V> type, Function<EntityRendererFactory.Context, EntityRenderer<T>> factory) {
|
||||
Mson.getInstance().getEntityRendererRegistry().registerEntityRenderer(type, ctx -> {
|
||||
if (!state.get()) {
|
||||
return MixinEntityRenderers.getRendererFactories().get(type).create(ctx);
|
||||
}
|
||||
Mson.getInstance().getEntityRendererRegistry().registerEntityRenderer(type, factory);
|
||||
} else {
|
||||
if (renderMap.containsKey(type)) {
|
||||
Mson.getInstance().getEntityRendererRegistry().registerEntityRenderer(type, m -> (EntityRenderer<T>)renderMap.get(type));
|
||||
}
|
||||
}
|
||||
return factory.apply(ctx);
|
||||
});
|
||||
}
|
||||
|
||||
public LevitatingItemRenderer getMagicRenderer() {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"MixinCamera",
|
||||
"MixinDefaultPlayerSkin",
|
||||
"MixinEntityRenderDispatcher",
|
||||
"MixinEntityRenderers",
|
||||
"MixinSkullBlockEntityRenderer",
|
||||
"MixinFirstPersonRenderer",
|
||||
"MixinItemRenderer",
|
||||
|
|
Loading…
Reference in a new issue