2018-04-25 21:29:49 +02:00
|
|
|
package com.minelittlepony;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
2018-05-01 12:40:18 +02:00
|
|
|
import com.minelittlepony.mixin.MixinRenderManager;
|
2018-04-25 21:29:49 +02:00
|
|
|
import com.minelittlepony.hdskins.gui.EntityPonyModel;
|
|
|
|
import com.minelittlepony.hdskins.gui.RenderPonyModel;
|
2018-04-28 16:39:32 +02:00
|
|
|
import com.minelittlepony.model.player.PlayerModels;
|
2018-05-26 23:37:50 +02:00
|
|
|
import com.minelittlepony.render.LevitatingItemRenderer;
|
2018-04-25 21:29:49 +02:00
|
|
|
import com.minelittlepony.render.player.RenderPonyPlayer;
|
2018-05-15 16:26:52 +02:00
|
|
|
import com.minelittlepony.render.ponies.MobRenderers;
|
2018-04-25 21:29:49 +02:00
|
|
|
import com.mumfrey.liteloader.util.ModUtilities;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.entity.Render;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderManager;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render manager responsible for replacing and restoring entity renderers when the client settings change.
|
|
|
|
* Old values of persisted internally.
|
|
|
|
*/
|
|
|
|
public class PonyRenderManager {
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-05-26 23:37:50 +02:00
|
|
|
private LevitatingItemRenderer magicRenderer = new LevitatingItemRenderer();
|
|
|
|
|
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
private final Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap();
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Registers all new player skin types. (currently only pony and slimpony).
|
|
|
|
*/
|
2018-05-01 12:38:13 +02:00
|
|
|
public void initialisePlayerRenderers(RenderManager manager) {
|
2018-04-25 21:29:49 +02:00
|
|
|
// Preview on the select skin gui
|
2018-05-01 12:38:13 +02:00
|
|
|
ModUtilities.addRenderer(EntityPonyModel.class, new RenderPonyModel(manager));
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-05-11 20:20:10 +02:00
|
|
|
for (PlayerModels i : PlayerModels.values()) {
|
|
|
|
if (i != PlayerModels.HUMAN) {
|
|
|
|
registerPlayerSkin(manager, i);
|
|
|
|
}
|
|
|
|
}
|
2018-04-28 16:39:32 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 12:40:18 +02:00
|
|
|
private void registerPlayerSkin(RenderManager manager, PlayerModels playerModel) {
|
|
|
|
addPlayerSkin(manager, false, playerModel);
|
|
|
|
addPlayerSkin(manager, true, playerModel);
|
2018-04-30 09:00:15 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 12:40:18 +02:00
|
|
|
private void addPlayerSkin(RenderManager manager, boolean slimArms, PlayerModels playerModel) {
|
|
|
|
RenderPonyPlayer renderer = new RenderPonyPlayer(manager, slimArms, playerModel.getModel(slimArms));
|
|
|
|
|
|
|
|
((MixinRenderManager)manager).getSkinMap().put(playerModel.getId(slimArms), renderer);
|
2018-04-25 21:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers all entity model replacements. (except for players).
|
|
|
|
*/
|
2018-05-01 12:38:13 +02:00
|
|
|
public void initializeMobRenderers(RenderManager manager, PonyConfig config) {
|
2018-05-15 16:26:52 +02:00
|
|
|
for (MobRenderers i : MobRenderers.values()) {
|
|
|
|
i.apply(this, manager);
|
2018-05-11 13:52:42 +02:00
|
|
|
}
|
2018-04-25 21:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-15 16:26:52 +02:00
|
|
|
*
|
|
|
|
* Replaces an entity renderer depending on whether we want ponies or not.
|
|
|
|
*
|
|
|
|
* @param state True if we want ponies (the original will be stored)
|
2018-04-25 21:29:49 +02:00
|
|
|
* @param manager The render manager
|
|
|
|
* @param type The type to replace
|
|
|
|
* @param renderer The replacement value
|
|
|
|
* @param <T> The entity type
|
|
|
|
*/
|
2018-05-11 13:52:42 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2018-05-15 16:26:52 +02:00
|
|
|
public <T extends Entity, V extends T> void switchRenderer(boolean state, RenderManager manager, Class<V> type, Render<T> renderer) {
|
|
|
|
if (state) {
|
|
|
|
if (!renderMap.containsKey(type)) {
|
|
|
|
renderMap.put(type, manager.getEntityClassRenderObject(type));
|
|
|
|
}
|
|
|
|
ModUtilities.addRenderer((Class<T>)type, renderer);
|
|
|
|
} else {
|
|
|
|
if (renderMap.containsKey(type)) {
|
|
|
|
ModUtilities.addRenderer(type, (Render<V>)renderMap.get(type));
|
|
|
|
}
|
2018-04-25 21:29:49 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
public LevitatingItemRenderer getMagicRenderer() {
|
|
|
|
return magicRenderer;
|
|
|
|
}
|
2018-04-25 21:29:49 +02:00
|
|
|
}
|