Fix crash caused by PonySkullRenderer.resolve() being called too early.

This commit is contained in:
Matthew Messinger 2019-07-21 18:15:37 -04:00
parent 127c150107
commit 37433ce75d
4 changed files with 10 additions and 13 deletions

View file

@ -93,6 +93,9 @@ public class MineLittlePony implements ClientModInitializer {
ClientTickCallback.EVENT.register(this::onTick);
ClientReadyCallback.EVENT.register(this::onClientReady);
ScreenInitCallback.EVENT.register(this::onScreenInit);
if (config.ponyskulls.get()) {
PonySkullRenderer.resolve();
}
if (FabricLoader.getInstance().isModLoaded("hdskins")) {
IndirectHDSkins.initialize();
@ -135,8 +138,6 @@ public class MineLittlePony implements ClientModInitializer {
}
}
}
PonySkullRenderer.resolve();
}
private void onScreenInit(Screen screen, ScreenInitCallback.ButtonList buttons) {

View file

@ -1,5 +1,6 @@
package com.minelittlepony.client.gui;
import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.LiteralText;
@ -155,5 +156,7 @@ public class GuiPonySettings extends GameGui {
public void onClose() {
super.onClose();
config.save();
PonySkullRenderer.resolve();
}
}

View file

@ -3,7 +3,6 @@ package com.minelittlepony.client.render.layer;
import com.minelittlepony.client.model.AbstractPonyModel;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.render.IPonyRender;
import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer;
import com.minelittlepony.model.BodyPart;
import com.mojang.authlib.GameProfile;
@ -11,6 +10,7 @@ import net.minecraft.block.AbstractSkullBlock;
import net.minecraft.block.SkullBlock.SkullType;
import net.minecraft.block.entity.SkullBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.block.entity.SkullBlockEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.entity.EquipmentSlot;
@ -97,7 +97,7 @@ public class LayerPonyCustomHead<T extends LivingEntity, M extends EntityModel<T
SkullType type = ((AbstractSkullBlock) ((BlockItem) itemstack.getItem()).getBlock()).getSkullType();
PonySkullRenderer.resolve().render(-0.5F, 0, -0.5F, null, 180, type, profile, -1, limbSwing);
SkullBlockEntityRenderer.INSTANCE.render(-0.5F, 0, -0.5F, null, 180, type, profile, -1, limbSwing);
}
@Override

View file

@ -28,7 +28,7 @@ import static com.mojang.blaze3d.platform.GlStateManager.*;
*/
public class PonySkullRenderer extends SkullBlockEntityRenderer {
public static PonySkullRenderer ponyInstance = new PonySkullRenderer();
private static final PonySkullRenderer ponyInstance = new PonySkullRenderer();
private static SkullBlockEntityRenderer backup = null;
private static final Map<SkullBlock.SkullType, ISkull> skullMap = SystemUtil.consume(Maps.newHashMap(), (skullMap) -> {
@ -44,27 +44,20 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer {
*
* Original/Existing renderer is stored to a backup variable as a fallback in case of mods.
*/
public static SkullBlockEntityRenderer resolve() {
public static void resolve() {
if (MineLittlePony.getInstance().getConfig().ponyskulls.get()) {
if (!(INSTANCE instanceof PonySkullRenderer)) {
backup = INSTANCE;
BlockEntityRendererRegistry.INSTANCE.register(SkullBlockEntity.class, ponyInstance);
INSTANCE = ponyInstance;
}
} else {
if ((INSTANCE instanceof PonySkullRenderer)) {
ponyInstance = (PonySkullRenderer) INSTANCE;
if (backup == null) {
backup = new SkullBlockEntityRenderer();
}
BlockEntityRendererRegistry.INSTANCE.register(SkullBlockEntity.class, backup);
INSTANCE = backup;
}
}
INSTANCE.setRenderManager(BlockEntityRenderDispatcher.INSTANCE);
return INSTANCE;
}
@Override