Fix baubles support. I blame Forge (specifically CPW) for breaking lazy classloading. This would never have happened with LiteLoader.

This commit is contained in:
Sollace 2019-03-16 09:36:51 +02:00
parent 466053be4e
commit ee64143a6a
3 changed files with 38 additions and 12 deletions

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.extern;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.item.ItemAlicornAmulet;
import baubles.api.BaubleType;
@ -16,7 +17,11 @@ import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
public class BaubleAlicornAmulet extends ItemAlicornAmulet implements IBauble {
class BaubleAlicornAmulet extends ItemAlicornAmulet implements IBauble {
static {
Unicopia.log.warn("Loaded BaubleAlicornAmulet.class If this is called, baubles must be present. Otherwise the game has probably already crashed...");
}
public BaubleAlicornAmulet(String domain, String name) {
super(domain, name);

View file

@ -1,9 +1,9 @@
package com.minelittlepony.unicopia.extern;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.forgebullshit.FUF;
import com.minelittlepony.unicopia.item.ItemAlicornAmulet;
import baubles.api.BaubleType;
import baubles.api.BaublesApi;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@ -12,30 +12,49 @@ public class Baubles {
private static boolean checkComplete;
private static boolean modIsActive;
static boolean isModActive() {
@FUF(reason = "Forge is so strict with their class loading it's a ff**8 joke")
public static boolean isModActive() {
if (!checkComplete) {
checkComplete = true;
try {
modIsActive = BaubleType.AMULET.getValidSlots().length > 0;
} catch (Exception e) {
modIsActive = baubles.api.BaubleType.AMULET.getValidSlots().length > 0;
} catch (Throwable e) {
Unicopia.log.error("Baubles are not present. Continuing without them.");
modIsActive = false;
}
}
if (modIsActive) {
Unicopia.log.debug("Baubles detected. baubles.api.BaubleType.AMULET.getValidSlots().length > 0 is true.");
}
return modIsActive;
}
public static ItemAlicornAmulet alicornAmulet(String domain, String name) {
if (isModActive()) {
return new BaubleAlicornAmulet(domain, name);
public static ItemAlicornAmulet alicornAmulet() {
try {
if (isModActive()) {
Unicopia.log.debug("Constructing BaubleAlicornAmulet.");
// FUCK YOU FORGE YOU PIECE OF SHIT
// DON'T LOAD THIS GOD DAMN CLASS UNTIL I FUCKING TELL YOU TO
Class<?> cls = ClassLoader.getSystemClassLoader().loadClass("com.minelittlepony.unicopia.extern.BaubleAlicornAmulet");
return (ItemAlicornAmulet)cls.getConstructor(String.class, String.class).newInstance(Unicopia.MODID, "alicorn_amulet");
}
} catch (Throwable e) {
Unicopia.log.error("Unicopia-Baubles support failed to load.", e);
}
return new ItemAlicornAmulet(domain, name);
return new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet");
}
public static int isBaubleEquipped(EntityPlayer player, Item bauble) {
if (isModActive()) {
return BaublesApi.isBaubleEquipped(player, bauble);
return baubles.api.BaublesApi.isBaubleEquipped(player, bauble);
}
return -1;

View file

@ -141,7 +141,8 @@ public class UItems {
public static final ItemSpell curse = new ItemCurse(Unicopia.MODID, "corrupted_gem");
public static final ItemOfHolding bag_of_holding = new ItemOfHolding(Unicopia.MODID, "bag_of_holding");
public static final ItemAlicornAmulet alicorn_amulet = Baubles.alicornAmulet(Unicopia.MODID, "alicorn_amulet");
public static final ItemAlicornAmulet alicorn_amulet = Baubles.isModActive()
? Baubles.alicornAmulet() : new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet");
public static final ItemSpellbook spellbook = new ItemSpellbook(Unicopia.MODID, "spellbook");
public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2);
@ -231,6 +232,7 @@ public class UItems {
.setUseAction(EnumAction.DRINK)
.setContainerItem(Items.GLASS_BOTTLE);
static void init(IForgeRegistry<Item> registry) {
RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r
.replace(Items.APPLE, red_apple)