From 42c69eb5571b1b7c0f8e222bcee87f4b41c32257 Mon Sep 17 00:00:00 2001 From: Nicholas Ignoffo Date: Thu, 28 Jun 2018 21:56:25 -0700 Subject: [PATCH] Rework of ritual registration Moves to annotation based registration. Configs are handled for automatically --- .../java/WayofTime/bloodmagic/BloodMagic.java | 14 +- .../WayofTime/bloodmagic/ConfigHandler.java | 47 +----- .../block/BlockRitualController.java | 29 ++-- .../client/gui/GuiBloodMagicConfig.java | 1 + .../DataProviderRitualController.java | 9 +- .../bloodmagic/item/ItemRitualDiviner.java | 100 +++--------- .../bloodmagic/registry/ModRituals.java | 138 +--------------- .../WayofTime/bloodmagic/ritual/Ritual.java | 3 +- .../bloodmagic/ritual/RitualManager.java | 148 ++++++++++++++++++ .../bloodmagic/ritual/RitualRegister.java | 49 ++++++ .../bloodmagic/ritual/RitualRegistry.java | 124 --------------- .../ritual/imperfect/ImperfectRitual.java | 4 +- .../imperfect/ImperfectRitualRegistry.java | 99 ------------ .../ritual/types/RitualAltarBuilder.java | 6 +- .../ritual/types/RitualAnimalGrowth.java | 1 + .../ritual/types/RitualArmourEvolve.java | 1 + .../ritual/types/RitualCobblestone.java | 1 + .../ritual/types/RitualContainment.java | 1 + .../ritual/types/RitualCrushing.java | 1 + .../ritual/types/RitualCrystalHarvest.java | 1 + .../ritual/types/RitualCrystalSplit.java | 6 +- .../ritual/types/RitualEllipsoid.java | 7 +- .../ritual/types/RitualExpulsion.java | 1 + .../ritual/types/RitualFeatheredKnife.java | 1 + .../ritual/types/RitualFelling.java | 1 + .../ritual/types/RitualForsakenSoul.java | 1 + .../ritual/types/RitualFullStomach.java | 1 + .../ritual/types/RitualGreenGrove.java | 1 + .../ritual/types/RitualHarvest.java | 1 + .../ritual/types/RitualInterdiction.java | 1 + .../ritual/types/RitualJumping.java | 1 + .../bloodmagic/ritual/types/RitualLava.java | 1 + .../types/RitualLivingArmourDowngrade.java | 1 + .../bloodmagic/ritual/types/RitualMeteor.java | 1 + .../bloodmagic/ritual/types/RitualPlacer.java | 1 + .../bloodmagic/ritual/types/RitualPortal.java | 6 +- .../bloodmagic/ritual/types/RitualPump.java | 1 + .../ritual/types/RitualRegeneration.java | 1 + .../bloodmagic/ritual/types/RitualSpeed.java | 1 + .../ritual/types/RitualSuppression.java | 1 + .../ritual/types/RitualUpgradeRemove.java | 1 + .../bloodmagic/ritual/types/RitualWater.java | 1 + .../ritual/types/RitualWellOfSuffering.java | 1 + .../bloodmagic/ritual/types/RitualZephyr.java | 1 + .../types/imperfect/ImperfectRitualDay.java | 1 + .../types/imperfect/ImperfectRitualNight.java | 2 + .../types/imperfect/ImperfectRitualRain.java | 2 + .../imperfect/ImperfectRitualResistance.java | 2 + .../imperfect/ImperfectRitualZombie.java | 2 + .../tile/TileImperfectRitualStone.java | 8 +- .../tile/TileMasterRitualStone.java | 11 +- .../util/handler/event/ClientHandler.java | 3 +- .../bloodmagic/util/helper/RitualHelper.java | 40 ++--- .../assets/bloodmagic/lang/en_US.lang | 2 +- 54 files changed, 321 insertions(+), 569 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/ritual/RitualManager.java create mode 100644 src/main/java/WayofTime/bloodmagic/ritual/RitualRegister.java delete mode 100644 src/main/java/WayofTime/bloodmagic/ritual/RitualRegistry.java delete mode 100644 src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitualRegistry.java diff --git a/src/main/java/WayofTime/bloodmagic/BloodMagic.java b/src/main/java/WayofTime/bloodmagic/BloodMagic.java index 1374c78c..c132d776 100644 --- a/src/main/java/WayofTime/bloodmagic/BloodMagic.java +++ b/src/main/java/WayofTime/bloodmagic/BloodMagic.java @@ -3,7 +3,7 @@ package WayofTime.bloodmagic; import WayofTime.bloodmagic.api.BloodMagicPlugin; import WayofTime.bloodmagic.api.IBloodMagicPlugin; import WayofTime.bloodmagic.core.registry.OrbRegistry; -import WayofTime.bloodmagic.ritual.RitualRegistry; +import WayofTime.bloodmagic.ritual.RitualManager; import WayofTime.bloodmagic.client.gui.GuiHandler; import WayofTime.bloodmagic.command.CommandBloodMagic; import WayofTime.bloodmagic.core.RegistrarBloodMagic; @@ -19,7 +19,9 @@ import com.google.common.collect.Lists; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; +import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.*; @@ -37,6 +39,7 @@ public class BloodMagic { public static final String DEPEND = "required-after:guideapi;"; public static final boolean IS_DEV = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); public static final List> PLUGINS = Lists.newArrayList(); + public static final RitualManager RITUAL_MANAGER = new RitualManager(new Configuration(new File(Loader.instance().getConfigDir(), MODID + "/" + "rituals.cfg"))); public static final CreativeTabs TAB_BM = new CreativeTabs(MODID + ".creativeTab") { @Override public ItemStack getTabIconItem() { @@ -75,6 +78,7 @@ public class BloodMagic { ModTranquilityHandlers.init(); ModDungeons.init(); + RITUAL_MANAGER.discover(event.getAsmData()); proxy.preInit(); } @@ -86,8 +90,7 @@ public class BloodMagic { PluginUtil.handlePluginStep(PluginUtil.RegistrationStep.PLUGIN_REGISTER); ModRecipes.init(); - ModRituals.initRituals(); - ModRituals.initImperfectRituals(); + ModRituals.initHarvestHandlers(); MeteorConfigHandler.init(new File(configDir, "meteors")); ModArmourTrackers.init(); NetworkRegistry.INSTANCE.registerGuiHandler(BloodMagic.instance, new GuiHandler()); @@ -103,11 +106,6 @@ public class BloodMagic { proxy.postInit(); } - @Mod.EventHandler - public void loadComplete(FMLLoadCompleteEvent event) { - RitualRegistry.orderLookupList(); - } - @Mod.EventHandler public void modMapping(FMLModIdMappingEvent event) { diff --git a/src/main/java/WayofTime/bloodmagic/ConfigHandler.java b/src/main/java/WayofTime/bloodmagic/ConfigHandler.java index a16e13bc..4bed50be 100644 --- a/src/main/java/WayofTime/bloodmagic/ConfigHandler.java +++ b/src/main/java/WayofTime/bloodmagic/ConfigHandler.java @@ -18,8 +18,6 @@ public class ConfigHandler public static ConfigBlacklist blacklist = new ConfigBlacklist(); @Config.Comment({ "Value modifiers for various features" }) public static ConfigValues values = new ConfigValues(); - @Config.Comment({ "Toggles for all rituals" }) - public static ConfigRituals rituals = new ConfigRituals(); @Config.Comment({ "Settings that only pertain to the client" }) public static ConfigClient client = new ConfigClient(); @Config.Comment({ "Compatibility settings" }) @@ -31,6 +29,7 @@ public class ConfigHandler if (event.getModID().equals(BloodMagic.MODID)) { ConfigManager.sync(event.getModID(), Config.Type.INSTANCE); // Sync config values + BloodMagic.RITUAL_MANAGER.syncConfig(); MeteorConfigHandler.handleMeteors(false); // Reload meteors } } @@ -69,50 +68,6 @@ public class ConfigHandler public boolean shouldResyncMeteors = true; } - public static class ConfigRituals - { - public boolean ritualAnimalGrowth = true; - public boolean ritualContainment = true; - public boolean ritualCrushing = true; - public boolean ritualExpulsion = true; - public boolean ritualFeatheredKnife = true; - public boolean ritualFullStomach = true; - public boolean ritualGreenGrove = true; - public boolean ritualHarvest = true; - public boolean ritualInterdiction = true; - public boolean ritualJumping = true; - public boolean ritualLava = true; - public boolean ritualMagnetic = true; - public boolean ritualRegeneration = true; - public boolean ritualSpeed = true; - public boolean ritualSuppression = true; - public boolean ritualWater = true; - public boolean ritualWellOfSuffering = true; - public boolean ritualZephyr = true; - public boolean ritualUpgradeRemove = true; - public boolean ritualArmourEvolve = true; - public boolean ritualForsakenSoul = true; - public boolean ritualCrystalHarvest = true; - public boolean ritualPlacer = true; - public boolean ritualFelling = true; - public boolean ritualPump = true; - public boolean ritualAltarBuilder = true; - public boolean ritualPortal = true; - public boolean ritualMeteor = true; - public boolean ritualDowngrade = true; - public boolean ritualEllipsoid = true; - public boolean ritualCrystalSplit = true; - public ConfigImperfectRituals imperfect = new ConfigImperfectRituals(); - } - - public static class ConfigImperfectRituals - { - public boolean imperfectRitualNight = true; - public boolean imperfectRitualRain = true; - public boolean imperfectRitualResistance = true; - public boolean imperfectRitualZombie = true; - } - public static class ConfigClient { @Config.Comment({ "Always render the beams between routing nodes.", "If disabled, the beams will only render while the Node Router is held." }) diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java b/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java index e1c71e8f..d08eb08c 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java @@ -4,8 +4,6 @@ import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.event.RitualEvent; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone; -import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry; -import WayofTime.bloodmagic.ritual.RitualRegistry; import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import WayofTime.bloodmagic.util.helper.RitualHelper; @@ -56,13 +54,22 @@ public class BlockRitualController extends BlockEnum imple return false; String key = RitualHelper.getValidRitual(world, pos); - EnumFacing direction = RitualHelper.getDirectionOfRitual(world, pos, key); - // TODO: Give a message stating that this ritual is not a valid ritual. - if (!key.isEmpty() && direction != null && RitualHelper.checkValidRitual(world, pos, key, direction)) { - if (((TileMasterRitualStone) tile).activateRitual(heldItem, player, RitualRegistry.getRitualForId(key))) { - ((TileMasterRitualStone) tile).setDirection(direction); - if (state.getValue(getProperty()) == EnumRitualController.INVERTED) - ((TileMasterRitualStone) tile).setInverted(true); + if (!key.isEmpty()) { + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(key); + if (ritual != null) { + EnumFacing direction = RitualHelper.getDirectionOfRitual(world, pos, ritual); + // TODO: Give a message stating that this ritual is not a valid ritual. + if (direction != null && RitualHelper.checkValidRitual(world, pos, ritual, direction)) { + if (((TileMasterRitualStone) tile).activateRitual(heldItem, player, BloodMagic.RITUAL_MANAGER.getRitual(key))) { + ((TileMasterRitualStone) tile).setDirection(direction); + if (state.getValue(getProperty()) == EnumRitualController.INVERTED) + ((TileMasterRitualStone) tile).setInverted(true); + } + } else { + player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true); + } + } else { + player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true); } } else { player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true); @@ -70,7 +77,7 @@ public class BlockRitualController extends BlockEnum imple } } else if (state.getValue(getProperty()) == EnumRitualController.IMPERFECT && tile instanceof TileImperfectRitualStone) { IBlockState ritualBlock = world.getBlockState(pos.up()); - ImperfectRitual ritual = ImperfectRitualRegistry.getRitualForBlock(ritualBlock); + ImperfectRitual ritual = BloodMagic.RITUAL_MANAGER.getImperfectRitual(ritualBlock); if (ritual == null) return false; @@ -120,7 +127,7 @@ public class BlockRitualController extends BlockEnum imple else return new ResourceLocation("bloodmagic", "ritual_" + mrs.getCurrentRitual().getName()); } else if (state.getValue(getProperty()).equals(EnumRitualController.IMPERFECT)) { - ImperfectRitual imperfectRitual = ImperfectRitualRegistry.getRitualForBlock(world.getBlockState(pos.up())); + ImperfectRitual imperfectRitual = BloodMagic.RITUAL_MANAGER.getImperfectRitual(world.getBlockState(pos.up())); if (imperfectRitual != null) return new ResourceLocation("bloodmagic", "ritual_" + imperfectRitual.getName()); } diff --git a/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java b/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java index a13b950c..f96654ca 100644 --- a/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java +++ b/src/main/java/WayofTime/bloodmagic/client/gui/GuiBloodMagicConfig.java @@ -26,6 +26,7 @@ public class GuiBloodMagicConfig extends GuiConfig { List elements = Lists.newArrayList(); elements.addAll(ConfigElement.from(ConfigHandler.class).getChildElements()); + elements.add(new ConfigElement(BloodMagic.RITUAL_MANAGER.getConfig().getCategory("rituals"))); if (Minecraft.getMinecraft().world != null) elements.add(new DummyElementEditHUD(BloodMagic.NAME, "config." + BloodMagic.MODID + ".edit_hud")); diff --git a/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java b/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java index 9b8c8c12..cadada2e 100644 --- a/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java +++ b/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java @@ -1,8 +1,7 @@ package WayofTime.bloodmagic.compat.waila.provider; +import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.util.Constants; -import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry; -import WayofTime.bloodmagic.ritual.RitualRegistry; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.tile.TileMasterRitualStone; @@ -64,15 +63,15 @@ public class DataProviderRitualController implements IWailaDataProvider { tag.setBoolean("active", mrs.isActive()); if (mrs.getOwner() != null) tag.setString("owner", PlayerHelper.getUsernameFromUUID(mrs.getOwner())); - tag.setBoolean("enabled", RitualRegistry.ritualEnabled(mrs.getCurrentRitual())); + tag.setBoolean("enabled", BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(mrs.getCurrentRitual()), false)); } } else { tag.setBoolean("master", false); - ImperfectRitual ritual = ImperfectRitualRegistry.getRitualForBlock(world.getBlockState(pos.up())); + ImperfectRitual ritual = BloodMagic.RITUAL_MANAGER.getImperfectRitual(world.getBlockState(pos.up())); if (ritual != null) { tag.setString("ritual", ritual.getUnlocalizedName()); - tag.setBoolean("enabled", ImperfectRitualRegistry.ritualEnabled(ritual)); + tag.setBoolean("enabled", BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(ritual), false)); } } diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemRitualDiviner.java b/src/main/java/WayofTime/bloodmagic/item/ItemRitualDiviner.java index e55a482d..6d026756 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemRitualDiviner.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemRitualDiviner.java @@ -6,10 +6,8 @@ import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks; import WayofTime.bloodmagic.ritual.EnumRuneType; import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.ritual.RitualComponent; -import WayofTime.bloodmagic.ritual.RitualRegistry; import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.tile.TileMasterRitualStone; -import WayofTime.bloodmagic.util.ChatUtil; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.handler.event.ClientHandler; @@ -40,6 +38,7 @@ import org.lwjgl.input.Keyboard; import javax.annotation.Nonnull; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class ItemRitualDiviner extends Item implements IVariantProvider { @@ -63,7 +62,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { if (Strings.isNullOrEmpty(getCurrentRitual(stack))) return displayName; - Ritual ritual = RitualRegistry.getRitualForId(getCurrentRitual(stack)); + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(getCurrentRitual(stack)); if (ritual == null) return displayName; @@ -114,7 +113,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileMasterRitualStone) { - Ritual ritual = RitualRegistry.getRitualForId(this.getCurrentRitual(stack)); + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(this.getCurrentRitual(stack)); if (ritual != null) { EnumFacing direction = getDirection(stack); List components = Lists.newArrayList(); @@ -161,7 +160,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileMasterRitualStone) { - Ritual ritual = RitualRegistry.getRitualForId(this.getCurrentRitual(itemStack)); + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(this.getCurrentRitual(itemStack)); TileMasterRitualStone masterRitualStone = (TileMasterRitualStone) tile; if (ritual != null) { @@ -207,9 +206,9 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { if (!stack.hasTagCompound()) return; - Ritual ritual = RitualRegistry.getRitualForId(this.getCurrentRitual(stack)); + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(this.getCurrentRitual(stack)); if (ritual != null) { - tooltip.add(TextHelper.localize("tooltip.bloodmagic.diviner.currentRitual") + TextHelper.localize(ritual.getUnlocalizedName())); + tooltip.add(TextHelper.localize("tooltip.bloodmagic.diviner.currentRitual", TextHelper.localize(ritual.getUnlocalizedName()))); boolean sneaking = Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); boolean extraInfo = sneaking && Keyboard.isKeyDown(Keyboard.KEY_M); @@ -303,7 +302,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { if (player.isSneaking()) { if (!world.isRemote) { - cycleRitual(stack, player); + cycleRitual(stack, player, false); } return new ActionResult<>(EnumActionResult.SUCCESS, stack); @@ -314,7 +313,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { @Override public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) { - if (entityLiving instanceof EntityPlayer) { + if (!entityLiving.world.isRemote && entityLiving instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entityLiving; RayTraceResult ray = this.rayTrace(player.getEntityWorld(), player, false); @@ -324,7 +323,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { if (!player.isSwingInProgress) { if (player.isSneaking()) { - cycleRitualBackwards(stack, player); + cycleRitual(stack, player, true); } else { cycleDirection(stack, player); } @@ -396,83 +395,36 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { } /** - * Cycles the selected ritual to the next available ritual that is enabled. - * - * @param stack - The ItemStack of the ritual diviner - * @param player - The player using the ritual diviner + * Cycles the ritual forward or backward */ - public void cycleRitual(ItemStack stack, EntityPlayer player) { + public void cycleRitual(ItemStack stack, EntityPlayer player, boolean reverse) { String key = getCurrentRitual(stack); - List idList = RitualRegistry.getOrderedIds(); + List rituals = BloodMagic.RITUAL_MANAGER.getSortedRituals(); + if (reverse) + Collections.reverse(rituals = Lists.newArrayList(rituals)); + String firstId = ""; boolean foundId = false; boolean foundFirst = false; - for (String str : idList) { - Ritual ritual = RitualRegistry.getRitualForId(str); + for (Ritual ritual : rituals) { + String id = BloodMagic.RITUAL_MANAGER.getId(ritual); - if (!RitualRegistry.ritualEnabled(ritual) || !canDivinerPerformRitual(stack, ritual)) { + if (!BloodMagic.RITUAL_MANAGER.enabled(id, false) || !canDivinerPerformRitual(stack, ritual)) { continue; } if (!foundFirst) { - firstId = str; + firstId = id; foundFirst = true; } if (foundId) { - setCurrentRitual(stack, str); - notifyRitualChange(str, player); + setCurrentRitual(stack, id); + notifyRitualChange(id, player); return; - } else { - if (str.equals(key)) { - foundId = true; - continue; - } - } - } - - if (foundFirst) { - setCurrentRitual(stack, firstId); - notifyRitualChange(firstId, player); - } - } - - /** - * Does the same as cycleRitual but instead cycles backwards. - * - * @param stack - * @param player - */ - public void cycleRitualBackwards(ItemStack stack, EntityPlayer player) { - String key = getCurrentRitual(stack); - List idList = RitualRegistry.getOrderedIds(); - String firstId = ""; - boolean foundId = false; - boolean foundFirst = false; - - for (int i = idList.size() - 1; i >= 0; i--) { - String str = idList.get(i); - Ritual ritual = RitualRegistry.getRitualForId(str); - - if (!RitualRegistry.ritualEnabled(ritual) || !canDivinerPerformRitual(stack, ritual)) { - continue; - } - - if (!foundFirst) { - firstId = str; - foundFirst = true; - } - - if (foundId) { - setCurrentRitual(stack, str); - notifyRitualChange(str, player); - return; - } else { - if (str.equals(key)) { - foundId = true; - continue; - } + } else if (id.equals(key)) { + foundId = true; } } @@ -499,7 +451,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { } public void notifyRitualChange(String key, EntityPlayer player) { - Ritual ritual = RitualRegistry.getRitualForId(key); + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(key); if (ritual != null) { player.sendStatusMessage(new TextComponentTranslation(ritual.getUnlocalizedName()), true); } @@ -512,7 +464,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { NBTTagCompound tag = stack.getTagCompound(); - tag.setString(Constants.NBT.CURRENT_RITUAL, key); + tag.setString("current_ritual", key); } public String getCurrentRitual(ItemStack stack) { @@ -521,7 +473,7 @@ public class ItemRitualDiviner extends Item implements IVariantProvider { } NBTTagCompound tag = stack.getTagCompound(); - return tag.getString(Constants.NBT.CURRENT_RITUAL); + return tag.getString("current_ritual"); } public boolean canPlaceRitualStone(EnumRuneType rune, ItemStack stack) { diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java b/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java index c3da05f3..f33bbf22 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRituals.java @@ -1,150 +1,14 @@ package WayofTime.bloodmagic.registry; -import WayofTime.bloodmagic.ConfigHandler; import WayofTime.bloodmagic.ritual.harvest.HarvestRegistry; -import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry; -import WayofTime.bloodmagic.ritual.RitualRegistry; -import WayofTime.bloodmagic.ritual.Ritual; -import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; -import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid; import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerPlantable; import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerStem; import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerTall; -import WayofTime.bloodmagic.ritual.types.imperfect.ImperfectRitualNight; -import WayofTime.bloodmagic.ritual.types.imperfect.ImperfectRitualRain; -import WayofTime.bloodmagic.ritual.types.imperfect.ImperfectRitualResistance; -import WayofTime.bloodmagic.ritual.types.imperfect.ImperfectRitualZombie; -import WayofTime.bloodmagic.ritual.types.*; import net.minecraft.init.Blocks; public class ModRituals { - public static Ritual waterRitual; - public static Ritual lavaRitual; - public static Ritual greenGroveRitual; - public static Ritual jumpRitual; - public static Ritual sufferingRitual; - public static Ritual featheredKnifeRitual; - public static Ritual regenerationRitual; - public static Ritual animalGrowthRitual; - public static Ritual harvestRitual; - public static Ritual magneticRitual; - public static Ritual crushingRitual; - public static Ritual stomachRitual; - public static Ritual interdictionRitual; - public static Ritual containmentRitual; - public static Ritual speedRitual; - public static Ritual suppressionRitual; - public static Ritual expulsionRitual; - public static Ritual zephyrRitual; - public static Ritual upgradeRemoveRitual; - public static Ritual armourEvolveRitual; - public static Ritual forsakenSoulRitual; - public static Ritual crystalHarvestRitual; - - public static Ritual placerRitual; - public static Ritual fellingRitual; - public static Ritual pumpRitual; - public static Ritual altarBuilderRitual; - public static Ritual portalRitual; - - public static Ritual ellipsoidRitual; - public static Ritual crystalSplitRitual; - - public static Ritual meteorRitual; - - public static Ritual downgradeRitual; - - public static ImperfectRitual imperfectNight; - public static ImperfectRitual imperfectRain; - public static ImperfectRitual imperfectResistance; - public static ImperfectRitual imperfectZombie; - - public static void initRituals() - { - waterRitual = new RitualWater(); - RitualRegistry.registerRitual(waterRitual, ConfigHandler.rituals.ritualWater); - lavaRitual = new RitualLava(); - RitualRegistry.registerRitual(lavaRitual, ConfigHandler.rituals.ritualLava); - greenGroveRitual = new RitualGreenGrove(); - RitualRegistry.registerRitual(greenGroveRitual, ConfigHandler.rituals.ritualGreenGrove); - jumpRitual = new RitualJumping(); - RitualRegistry.registerRitual(jumpRitual, ConfigHandler.rituals.ritualJumping); - sufferingRitual = new RitualWellOfSuffering(); - RitualRegistry.registerRitual(sufferingRitual, ConfigHandler.rituals.ritualWellOfSuffering); - featheredKnifeRitual = new RitualFeatheredKnife(); - RitualRegistry.registerRitual(featheredKnifeRitual, ConfigHandler.rituals.ritualFeatheredKnife); - regenerationRitual = new RitualRegeneration(); - RitualRegistry.registerRitual(regenerationRitual, ConfigHandler.rituals.ritualRegeneration); - animalGrowthRitual = new RitualAnimalGrowth(); - RitualRegistry.registerRitual(animalGrowthRitual, ConfigHandler.rituals.ritualAnimalGrowth); - harvestRitual = new RitualHarvest(); - RitualRegistry.registerRitual(harvestRitual, ConfigHandler.rituals.ritualHarvest); - initHarvestHandlers(); - magneticRitual = new RitualMagnetic(); - RitualRegistry.registerRitual(magneticRitual, ConfigHandler.rituals.ritualMagnetic); - crushingRitual = new RitualCrushing(); - RitualRegistry.registerRitual(crushingRitual, ConfigHandler.rituals.ritualCrushing); - stomachRitual = new RitualFullStomach(); - RitualRegistry.registerRitual(stomachRitual, ConfigHandler.rituals.ritualFullStomach); - interdictionRitual = new RitualInterdiction(); - RitualRegistry.registerRitual(interdictionRitual, ConfigHandler.rituals.ritualInterdiction); - containmentRitual = new RitualContainment(); - RitualRegistry.registerRitual(containmentRitual, ConfigHandler.rituals.ritualContainment); - speedRitual = new RitualSpeed(); - RitualRegistry.registerRitual(speedRitual, ConfigHandler.rituals.ritualSpeed); - suppressionRitual = new RitualSuppression(); - RitualRegistry.registerRitual(suppressionRitual, ConfigHandler.rituals.ritualSuppression); - zephyrRitual = new RitualZephyr(); - RitualRegistry.registerRitual(zephyrRitual, ConfigHandler.rituals.ritualZephyr); - expulsionRitual = new RitualExpulsion(); - RitualRegistry.registerRitual(expulsionRitual, ConfigHandler.rituals.ritualExpulsion); - upgradeRemoveRitual = new RitualUpgradeRemove(); - RitualRegistry.registerRitual(upgradeRemoveRitual, ConfigHandler.rituals.ritualUpgradeRemove); - armourEvolveRitual = new RitualArmourEvolve(); - RitualRegistry.registerRitual(armourEvolveRitual, ConfigHandler.rituals.ritualArmourEvolve); - forsakenSoulRitual = new RitualForsakenSoul(); - RitualRegistry.registerRitual(forsakenSoulRitual, ConfigHandler.rituals.ritualForsakenSoul); - crystalHarvestRitual = new RitualCrystalHarvest(); - RitualRegistry.registerRitual(crystalHarvestRitual, ConfigHandler.rituals.ritualCrystalHarvest); - placerRitual = new RitualPlacer(); - RitualRegistry.registerRitual(placerRitual, ConfigHandler.rituals.ritualPlacer); - fellingRitual = new RitualFelling(); - RitualRegistry.registerRitual(fellingRitual, ConfigHandler.rituals.ritualFelling); - pumpRitual = new RitualPump(); - RitualRegistry.registerRitual(pumpRitual, ConfigHandler.rituals.ritualPump); - altarBuilderRitual = new RitualAltarBuilder(); - RitualRegistry.registerRitual(altarBuilderRitual, ConfigHandler.rituals.ritualAltarBuilder); - portalRitual = new RitualPortal(); - RitualRegistry.registerRitual(portalRitual, ConfigHandler.rituals.ritualPortal); - meteorRitual = new RitualMeteor(); - RitualRegistry.registerRitual(meteorRitual, ConfigHandler.rituals.ritualMeteor); - - downgradeRitual = new RitualLivingArmourDowngrade(); - RitualRegistry.registerRitual(downgradeRitual, ConfigHandler.rituals.ritualDowngrade); - - ellipsoidRitual = new RitualEllipsoid(); - RitualRegistry.registerRitual(ellipsoidRitual, ConfigHandler.rituals.ritualEllipsoid); - - crystalSplitRitual = new RitualCrystalSplit(); - RitualRegistry.registerRitual(crystalSplitRitual, ConfigHandler.rituals.ritualCrystalSplit); - - RitualCrushing.registerCuttingFluid(ItemCuttingFluid.FluidType.BASIC.getStack(), 250, 0.5); - RitualCrushing.registerCuttingFluid(ItemCuttingFluid.FluidType.EXPLOSIVE.getStack(), 25, 0.05); - } - - public static void initImperfectRituals() - { - imperfectNight = new ImperfectRitualNight(); - ImperfectRitualRegistry.registerRitual(imperfectNight, ConfigHandler.rituals.imperfect.imperfectRitualNight); - imperfectRain = new ImperfectRitualRain(); - ImperfectRitualRegistry.registerRitual(imperfectRain, ConfigHandler.rituals.imperfect.imperfectRitualRain); - imperfectResistance = new ImperfectRitualResistance(); - ImperfectRitualRegistry.registerRitual(imperfectResistance, ConfigHandler.rituals.imperfect.imperfectRitualResistance); - imperfectZombie = new ImperfectRitualZombie(); - ImperfectRitualRegistry.registerRitual(imperfectZombie, ConfigHandler.rituals.imperfect.imperfectRitualZombie); - } - + // TODO Move elsewhere public static void initHarvestHandlers() { HarvestRegistry.registerRangeAmplifier(Blocks.DIAMOND_BLOCK.getDefaultState(), 15); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java b/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java index 472fa682..be545f56 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java @@ -18,8 +18,7 @@ import java.util.Map.Entry; import java.util.function.Consumer; /** - * Abstract class for creating new rituals. Rituals need be registered with - * {@link RitualRegistry#registerRitual(Ritual, String)} + * Abstract class for creating new rituals. Register your ritual by annotating it with {@link RitualRegister} */ public abstract class Ritual { diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualManager.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualManager.java new file mode 100644 index 00000000..e6e2287b --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualManager.java @@ -0,0 +1,148 @@ +package WayofTime.bloodmagic.ritual; + +import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; +import WayofTime.bloodmagic.util.BMLog; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import net.minecraft.block.state.IBlockState; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.fml.common.discovery.ASMDataTable; + +import java.util.*; + +public class RitualManager { + + private final Map rituals; + private final Map ritualsReverse; + private final List sortedRituals; + private final Map imperfectRituals; + private final Map imperfectRitualsReverse; + private final Configuration config; + + public RitualManager(Configuration config) { + this.rituals = Maps.newTreeMap(); + this.ritualsReverse = Maps.newHashMap(); + this.sortedRituals = Lists.newArrayList(); + this.imperfectRituals = Maps.newTreeMap(); + this.imperfectRitualsReverse = Maps.newHashMap(); + this.config = config; + } + + public void discover(ASMDataTable dataTable) { + Set data = dataTable.getAll(RitualRegister.class.getName()); + for (ASMDataTable.ASMData found : data) { + try { + Class discoveredClass = Class.forName(found.getClassName()); + if (!Ritual.class.isAssignableFrom(discoveredClass)) + throw new BadRitualException("Annotated class " + found.getClassName() + " does not inherit from " + Ritual.class.getName()); + + Class ritualClass = discoveredClass.asSubclass(Ritual.class); + RitualRegister ritualRegister = ritualClass.getAnnotation(RitualRegister.class); + String id = ritualRegister.value(); + Ritual ritual = ritualRegister.factory().newInstance().apply(ritualClass); + if (ritual == null) { + BMLog.DEFAULT.error("Error creating ritual instance for {}.", id); + continue; + } + + rituals.put(id, ritual); + ritualsReverse.put(ritual, id); + BMLog.DEBUG.info("Registered ritual {}", id); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + Set imperfectData = dataTable.getAll(RitualRegister.Imperfect.class.getName()); + for (ASMDataTable.ASMData found : imperfectData) { + try { + Class discoveredClass = Class.forName(found.getClassName()); + if (!ImperfectRitual.class.isAssignableFrom(discoveredClass)) + throw new BadRitualException("Annotated class " + found.getClassName() + " does not inherit from " + ImperfectRitual.class.getName()); + + Class ritualClass = discoveredClass.asSubclass(ImperfectRitual.class); + RitualRegister.Imperfect ritualRegister = ritualClass.getAnnotation(RitualRegister.Imperfect.class); + String id = ritualRegister.value(); + ImperfectRitual ritual = ritualRegister.factory().newInstance().apply(ritualClass); + if (ritual == null) { + BMLog.DEFAULT.error("Error creating imperfect ritual instance for {}.", id); + continue; + } + + imperfectRituals.put(id, ritual); + imperfectRitualsReverse.put(ritual, id); + BMLog.DEBUG.info("Registered imperfect ritual {}", id); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + syncConfig(); + + // Sort rituals + sortedRituals.addAll(rituals.values()); + // Oh dear this is probably so slow + sortedRituals.sort((o1, o2) -> { + Set components = Sets.newHashSet(); + o1.gatherComponents(components::add); + int initialSize = components.size(); + components.clear(); + o2.gatherComponents(components::add); + return Integer.compare(initialSize, components.size()); + }); + } + + public Ritual getRitual(String id) { + return rituals.get(id); + } + + public String getId(Ritual ritual) { + return ritualsReverse.get(ritual); + } + + public ImperfectRitual getImperfectRitual(IBlockState state) { + for (ImperfectRitual ritual : imperfectRituals.values()) + if (ritual.getBlockRequirement().test(state)) + return ritual; + + return null; + } + + public String getId(ImperfectRitual ritual) { + return imperfectRitualsReverse.get(ritual); + } + + public Collection getRituals() { + return rituals.values(); + } + + public Collection getImperfectRituals() { + return imperfectRituals.values(); + } + + public List getSortedRituals() { + return sortedRituals; + } + + public void syncConfig() { + config.addCustomCategoryComment("rituals", "Toggles for all rituals"); + rituals.forEach((k, v) -> config.getBoolean(k, "rituals", true, "Enable the " + k + " ritual.")); + imperfectRituals.forEach((k, v) -> config.getBoolean(k, "rituals.imperfect", true, "Enable the " + k + " imperfect ritual.")); + config.save(); + } + + public boolean enabled(String id, boolean imperfect) { + return id != null && config.getBoolean(id, "rituals" + (imperfect ? ".imperfect" : ""), true, ""); + } + + public Configuration getConfig() { + return config; + } + + public static class BadRitualException extends RuntimeException { + public BadRitualException(String message) { + super(message); + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualRegister.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualRegister.java new file mode 100644 index 00000000..b077056f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualRegister.java @@ -0,0 +1,49 @@ +package WayofTime.bloodmagic.ritual; + +import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.function.Function; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface RitualRegister { + + String value(); + + Class, Ritual>> factory() default DefaultRitualFactory.class; + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + @interface Imperfect { + + String value(); + + Class, ImperfectRitual>> factory() default DefaultImperfectRitualFactory.class; + } + + class DefaultRitualFactory implements Function, Ritual> { + @Override + public Ritual apply(Class aClass) { + try { + return aClass.newInstance(); + } catch (Exception e) { + return null; + } + } + } + + class DefaultImperfectRitualFactory implements Function, ImperfectRitual> { + @Override + public ImperfectRitual apply(Class aClass) { + try { + return aClass.newInstance(); + } catch (Exception e) { + return null; + } + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualRegistry.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualRegistry.java deleted file mode 100644 index 66039e2b..00000000 --- a/src/main/java/WayofTime/bloodmagic/ritual/RitualRegistry.java +++ /dev/null @@ -1,124 +0,0 @@ -package WayofTime.bloodmagic.ritual; - -import WayofTime.bloodmagic.util.BMLog; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Lists; - -import javax.annotation.Nullable; -import java.util.*; - -public class RitualRegistry { - public static final Map enabledRituals = new HashMap<>(); - private static final BiMap registry = HashBiMap.create(); - private static final List lookupList = new ArrayList<>(); - /** - * Ordered list for actions that depend on the order that the rituals were - * registered in - */ - private static final ArrayList orderedIdList = new ArrayList<>(); - - private static boolean locked; - - /** - * The safe way to register a new Ritual. - * - * @param ritual - The ritual to register. - * @param id - The ID for the ritual. Cannot be duplicated. - */ - public static void registerRitual(Ritual ritual, String id, boolean enabled) { - if (locked) { - BMLog.DEFAULT.error("This registry has been locked. Please register your ritual earlier."); - BMLog.DEFAULT.error("If you reflect this, I will hunt you down. - TehNut"); - return; - } - - if (ritual != null) { - if (registry.containsKey(id)) - BMLog.DEFAULT.error("Duplicate ritual id: {}", id); - else { - registry.put(id, ritual); - enabledRituals.put(ritual, enabled); - orderedIdList.add(id); - } - } - } - - public static void registerRitual(Ritual ritual, boolean enabled) { - registerRitual(ritual, ritual.getName(), enabled); - } - - public static void registerRitual(Ritual ritual, String id) { - registerRitual(ritual, id, true); - } - - public static void registerRitual(Ritual ritual) { - registerRitual(ritual, ritual.getName()); - } - - @Nullable - public static Ritual getRitualForId(String id) { - Ritual ritual = registry.get(id); - return ritual != null ? ritual.getNewCopy() : null; - } - - public static String getIdForRitual(Ritual ritual) { - return registry.inverse().get(ritual); - } - - public static boolean isMapEmpty() { - return registry.isEmpty(); - } - - public static int getMapSize() { - return registry.size(); - } - - public static boolean ritualEnabled(Ritual ritual) { - try { - return enabledRituals.get(ritual); - } catch (NullPointerException e) { - BMLog.DEFAULT.error("Invalid Ritual was called"); - return false; - } - } - - public static boolean ritualEnabled(String id) { - return ritualEnabled(getRitualForId(id)); - } - - public static BiMap getRegistry() { - return HashBiMap.create(registry); - } - - public static Map getEnabledMap() { - return new HashMap<>(enabledRituals); - } - - public static ArrayList getIds() { - return new ArrayList<>(lookupList); - } - - public static ArrayList getOrderedIds() { - return orderedIdList; - } - - public static ArrayList getRituals() { - return new ArrayList<>(registry.values()); - } - - public static void orderLookupList() { - locked = true; // Lock registry so no no rituals can be registered - lookupList.clear(); // Make sure it's empty - lookupList.addAll(registry.keySet()); - lookupList.sort((o1, o2) -> { - Ritual ritual1 = registry.get(o1); - Ritual ritual2 = registry.get(o2); - List first = Lists.newArrayList(); - ritual1.gatherComponents(first::add); - List second = Lists.newArrayList(); - ritual2.gatherComponents(second::add); - return first.size() > second.size() ? -1 : 0; // Put earlier if bigger - }); - } -} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitual.java b/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitual.java index dae1c461..6aa24daa 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitual.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitual.java @@ -7,9 +7,7 @@ import net.minecraft.world.World; import java.util.function.Predicate; /** - * Abstract class for creating new imperfect rituals. ImperfectRituals need be - * registered with - * {@link ImperfectRitualRegistry#registerRitual(ImperfectRitual)} + * Abstract class for creating new imperfect rituals. To register, annotate your class with {@link WayofTime.bloodmagic.ritual.RitualRegister.Imperfect} */ public abstract class ImperfectRitual { diff --git a/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitualRegistry.java b/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitualRegistry.java deleted file mode 100644 index 2417a24d..00000000 --- a/src/main/java/WayofTime/bloodmagic/ritual/imperfect/ImperfectRitualRegistry.java +++ /dev/null @@ -1,99 +0,0 @@ -package WayofTime.bloodmagic.ritual.imperfect; - -import WayofTime.bloodmagic.util.BMLog; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import net.minecraft.block.state.IBlockState; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -public class ImperfectRitualRegistry { - public static final Map enabledRituals = new HashMap<>(); - private static final BiMap registry = HashBiMap.create(); - - /** - * The safe way to register a new Ritual. - * - * @param imperfectRitual - The imperfect ritual to register. - * @param id - The ID for the imperfect ritual. Cannot be duplicated. - */ - public static void registerRitual(ImperfectRitual imperfectRitual, String id, boolean enabled) { - if (imperfectRitual != null) { - if (registry.containsKey(id)) - BMLog.DEFAULT.error("Duplicate imperfect ritual id: {}", id); - else { - registry.put(id, imperfectRitual); - enabledRituals.put(imperfectRitual, enabled); - } - } - } - - public static void registerRitual(ImperfectRitual imperfectRitual, String id) { - registerRitual(imperfectRitual, id, true); - } - - public static void registerRitual(ImperfectRitual imperfectRitual, boolean enabled) { - registerRitual(imperfectRitual, imperfectRitual.getName(), enabled); - } - - public static void registerRitual(ImperfectRitual imperfectRitual) { - registerRitual(imperfectRitual, imperfectRitual.getName()); - } - - @Nullable - public static ImperfectRitual getRitualForBlock(IBlockState state) { - for (ImperfectRitual imperfectRitual : getRegistry().values()) - if (imperfectRitual.getBlockRequirement().test(state)) - return imperfectRitual; - - return null; - } - - public static ImperfectRitual getRitualForId(String id) { - return registry.get(id); - } - - public static String getIdForRitual(ImperfectRitual imperfectRitual) { - return registry.inverse().get(imperfectRitual); - } - - public static boolean isMapEmpty() { - return registry.isEmpty(); - } - - public static int getMapSize() { - return registry.size(); - } - - public static boolean ritualEnabled(ImperfectRitual imperfectRitual) { - try { - return enabledRituals.get(imperfectRitual); - } catch (NullPointerException e) { - BMLog.DEFAULT.error("Invalid Imperfect Ritual was called"); - return false; - } - } - - public static boolean ritualEnabled(String id) { - return ritualEnabled(getRitualForId(id)); - } - - public static BiMap getRegistry() { - return HashBiMap.create(registry); - } - - public static BiMap getEnabledMap() { - return HashBiMap.create(enabledRituals); - } - - public static ArrayList getIds() { - return new ArrayList<>(registry.keySet()); - } - - public static ArrayList getRituals() { - return new ArrayList<>(registry.values()); - } -} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAltarBuilder.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAltarBuilder.java index c1572201..4c7783b4 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAltarBuilder.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAltarBuilder.java @@ -1,14 +1,11 @@ package WayofTime.bloodmagic.ritual.types; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ritual.*; import WayofTime.bloodmagic.util.BlockStack; import WayofTime.bloodmagic.altar.AltarComponent; import WayofTime.bloodmagic.altar.ComponentType; import WayofTime.bloodmagic.altar.AltarTier; -import WayofTime.bloodmagic.ritual.EnumRuneType; -import WayofTime.bloodmagic.ritual.IMasterRitualStone; -import WayofTime.bloodmagic.ritual.Ritual; -import WayofTime.bloodmagic.ritual.RitualComponent; import WayofTime.bloodmagic.block.BlockBloodRune; import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks; import WayofTime.bloodmagic.util.Utils; @@ -29,6 +26,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.function.Consumer; +@RitualRegister("altar_builder") public class RitualAltarBuilder extends Ritual { private Iterator altarComponentsIterator = new ArrayList<>(AltarTier.SIX.getAltarComponents()).iterator(); private boolean cycleDone = false; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAnimalGrowth.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAnimalGrowth.java index f7724e6a..260447b2 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAnimalGrowth.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualAnimalGrowth.java @@ -21,6 +21,7 @@ import net.minecraftforge.items.IItemHandler; import java.util.List; import java.util.function.Consumer; +@RitualRegister("animal_growth") public class RitualAnimalGrowth extends Ritual { public static final double rawWillDrain = 0.05; public static final double vengefulWillDrain = 0.02; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualArmourEvolve.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualArmourEvolve.java index 90447806..175069ea 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualArmourEvolve.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualArmourEvolve.java @@ -14,6 +14,7 @@ import net.minecraft.world.World; import java.util.List; import java.util.function.Consumer; +@RitualRegister("armour_evolve") public class RitualArmourEvolve extends Ritual { public static final String CHECK_RANGE = "fillRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCobblestone.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCobblestone.java index cf481fa9..ab8516e2 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCobblestone.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCobblestone.java @@ -12,6 +12,7 @@ import net.minecraft.world.World; import java.util.function.Consumer; +@RitualRegister("cobblestone") public class RitualCobblestone extends Ritual { public static final String COBBLESTONE_RANGE = "cobblestoneRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualContainment.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualContainment.java index 4ad43168..51c8432e 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualContainment.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualContainment.java @@ -9,6 +9,7 @@ import net.minecraft.world.World; import java.util.function.Consumer; +@RitualRegister("containment") public class RitualContainment extends Ritual { public static final String CONTAINMENT_RANGE = "containmentRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java index 01cab915..1ad10719 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrushing.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.function.Consumer; +@RitualRegister("crushing") public class RitualCrushing extends Ritual { public static final String CRUSHING_RANGE = "crushingRange"; public static final String CHEST_RANGE = "chest"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalHarvest.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalHarvest.java index 62d86acc..5f5e9be2 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalHarvest.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalHarvest.java @@ -10,6 +10,7 @@ import net.minecraft.world.World; import java.util.function.Consumer; +@RitualRegister("crystal_harvest") public class RitualCrystalHarvest extends Ritual { public static final String CRYSTAL_RANGE = "crystal"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalSplit.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalSplit.java index 5930d6d9..a52f5181 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalSplit.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualCrystalSplit.java @@ -2,6 +2,7 @@ package WayofTime.bloodmagic.ritual.types; import java.util.function.Consumer; +import WayofTime.bloodmagic.ritual.*; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; @@ -12,13 +13,10 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks; -import WayofTime.bloodmagic.ritual.EnumRuneType; -import WayofTime.bloodmagic.ritual.IMasterRitualStone; -import WayofTime.bloodmagic.ritual.Ritual; -import WayofTime.bloodmagic.ritual.RitualComponent; import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.tile.TileDemonCrystal; +@RitualRegister("crystal_split") public class RitualCrystalSplit extends Ritual { public RitualCrystalSplit() diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualEllipsoid.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualEllipsoid.java index e47a8c74..74bbdaa8 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualEllipsoid.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualEllipsoid.java @@ -2,6 +2,7 @@ package WayofTime.bloodmagic.ritual.types; import java.util.function.Consumer; +import WayofTime.bloodmagic.ritual.*; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; @@ -14,12 +15,8 @@ import net.minecraft.world.World; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import WayofTime.bloodmagic.BloodMagic; -import WayofTime.bloodmagic.ritual.AreaDescriptor; -import WayofTime.bloodmagic.ritual.EnumRuneType; -import WayofTime.bloodmagic.ritual.IMasterRitualStone; -import WayofTime.bloodmagic.ritual.Ritual; -import WayofTime.bloodmagic.ritual.RitualComponent; +@RitualRegister("ellipsoid") public class RitualEllipsoid extends Ritual { public static final String SPHEROID_RANGE = "spheroidRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualExpulsion.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualExpulsion.java index 10209075..393645d2 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualExpulsion.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualExpulsion.java @@ -25,6 +25,7 @@ import java.util.Random; import java.util.UUID; import java.util.function.Consumer; +@RitualRegister("expulsion") public class RitualExpulsion extends Ritual { public static final String EXPULSION_RANGE = "expulsionRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFeatheredKnife.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFeatheredKnife.java index dd347421..ddddf20b 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFeatheredKnife.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFeatheredKnife.java @@ -26,6 +26,7 @@ import net.minecraft.world.World; import java.util.List; import java.util.function.Consumer; +@RitualRegister("feathered_knife") public class RitualFeatheredKnife extends Ritual { public static final String ALTAR_RANGE = "altar"; public static final String DAMAGE_RANGE = "damage"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFelling.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFelling.java index c4b33b27..749ff388 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFelling.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFelling.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.function.Consumer; +@RitualRegister("felling") public class RitualFelling extends Ritual { public static final String FELLING_RANGE = "fellingRange"; public static final String CHEST_RANGE = "chest"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualForsakenSoul.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualForsakenSoul.java index ee49bbcd..c56ff474 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualForsakenSoul.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualForsakenSoul.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +@RitualRegister("forsaken_soul") public class RitualForsakenSoul extends Ritual { public static final String CRYSTAL_RANGE = "crystal"; public static final String DAMAGE_RANGE = "damage"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFullStomach.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFullStomach.java index f0a739ea..0b4153a6 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFullStomach.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualFullStomach.java @@ -15,6 +15,7 @@ import net.minecraftforge.items.IItemHandler; import java.util.List; import java.util.function.Consumer; +@RitualRegister("full_stomach") public class RitualFullStomach extends Ritual { public static final String FILL_RANGE = "fillRange"; public static final String CHEST_RANGE = "chest"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualGreenGrove.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualGreenGrove.java index f2aa95ad..fdc69092 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualGreenGrove.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualGreenGrove.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Random; import java.util.function.Consumer; +@RitualRegister("green_grove") public class RitualGreenGrove extends Ritual { public static final String GROW_RANGE = "growing"; public static final String LEECH_RANGE = "leech"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualHarvest.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualHarvest.java index faa582ad..b04ba5b2 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualHarvest.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualHarvest.java @@ -30,6 +30,7 @@ import java.util.function.Consumer; * {@link HarvestRegistry#registerRangeAmplifier(net.minecraft.block.state.IBlockState, int)} to register a * new amplifier. */ +@RitualRegister("harvest") public class RitualHarvest extends Ritual { public static final String HARVEST_RANGE = "harvestRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualInterdiction.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualInterdiction.java index a9eb84b3..861b2f32 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualInterdiction.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualInterdiction.java @@ -9,6 +9,7 @@ import net.minecraft.world.World; import java.util.function.Consumer; +@RitualRegister("interdiction") public class RitualInterdiction extends Ritual { public static final String INTERDICTION_RANGE = "interdictionRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualJumping.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualJumping.java index e34a008d..78c89219 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualJumping.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualJumping.java @@ -11,6 +11,7 @@ import net.minecraft.world.World; import java.util.List; import java.util.function.Consumer; +@RitualRegister("jumping") public class RitualJumping extends Ritual { public static final String JUMP_RANGE = "jumpRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLava.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLava.java index d81a2ace..ae953425 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLava.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLava.java @@ -28,6 +28,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler; import java.util.List; import java.util.function.Consumer; +@RitualRegister("lava") public class RitualLava extends Ritual { public static final String LAVA_RANGE = "lavaRange"; public static final String FIRE_FUSE_RANGE = "fireFuse"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLivingArmourDowngrade.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLivingArmourDowngrade.java index d0f9e4b5..35aa10ba 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLivingArmourDowngrade.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualLivingArmourDowngrade.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +@RitualRegister("armour_downgrade") public class RitualLivingArmourDowngrade extends Ritual { public static final String DOWNGRADE_RANGE = "containmentRange"; private int internalTimer = 0; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualMeteor.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualMeteor.java index e8b9c652..0abb6a48 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualMeteor.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualMeteor.java @@ -15,6 +15,7 @@ import net.minecraft.world.World; import java.util.List; import java.util.function.Consumer; +@RitualRegister("meteor") public class RitualMeteor extends Ritual { public static final String ITEM_RANGE = "itemRange"; public static final double destructiveWillDrain = 50; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPlacer.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPlacer.java index d18f1cb5..c421f794 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPlacer.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPlacer.java @@ -15,6 +15,7 @@ import net.minecraftforge.items.IItemHandler; import java.util.function.Consumer; +@RitualRegister("placer") public class RitualPlacer extends Ritual { public static final String PLACER_RANGE = "placerRange"; public static final String CHEST_RANGE = "chest"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPortal.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPortal.java index fd3b83f4..8ec0b006 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPortal.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPortal.java @@ -1,10 +1,7 @@ package WayofTime.bloodmagic.ritual.types; import WayofTime.bloodmagic.BloodMagic; -import WayofTime.bloodmagic.ritual.EnumRuneType; -import WayofTime.bloodmagic.ritual.IMasterRitualStone; -import WayofTime.bloodmagic.ritual.Ritual; -import WayofTime.bloodmagic.ritual.RitualComponent; +import WayofTime.bloodmagic.ritual.*; import WayofTime.bloodmagic.teleport.PortalLocation; import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks; import WayofTime.bloodmagic.ritual.portal.LocationsHandler; @@ -20,6 +17,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries; import java.util.UUID; import java.util.function.Consumer; +@RitualRegister("portal") public class RitualPortal extends Ritual { public static final String PORTAL_NBT_TAG = "PortalRitualTag"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPump.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPump.java index 50667a6a..e7d6b74c 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPump.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualPump.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.List; import java.util.function.Consumer; +@RitualRegister("pump") public class RitualPump extends Ritual { public static final String PUMP_RANGE = "pumpRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualRegeneration.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualRegeneration.java index f480edc7..e851b8ad 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualRegeneration.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualRegeneration.java @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; +@RitualRegister("regeneration") public class RitualRegeneration extends Ritual { public static final String HEAL_RANGE = "heal"; public static final String VAMPIRE_RANGE = "vampire"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSpeed.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSpeed.java index cc9390f9..c40fb66a 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSpeed.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSpeed.java @@ -16,6 +16,7 @@ import net.minecraft.world.World; import java.util.List; import java.util.function.Consumer; +@RitualRegister("speed") public class RitualSpeed extends Ritual { public static final String SPEED_RANGE = "sanicRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSuppression.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSuppression.java index 8866eee8..5934ab9f 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSuppression.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualSuppression.java @@ -11,6 +11,7 @@ import net.minecraft.world.World; import java.util.function.Consumer; +@RitualRegister("suppression") public class RitualSuppression extends Ritual { public static final String SUPPRESSION_RANGE = "suppressionRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualUpgradeRemove.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualUpgradeRemove.java index 65120c45..ba9d5a04 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualUpgradeRemove.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualUpgradeRemove.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map.Entry; import java.util.function.Consumer; +@RitualRegister("upgrade_remove") public class RitualUpgradeRemove extends Ritual { public static final String CHECK_RANGE = "fillRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWater.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWater.java index 569998a1..c63b3b6d 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWater.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWater.java @@ -8,6 +8,7 @@ import net.minecraft.world.World; import java.util.function.Consumer; +@RitualRegister("water") public class RitualWater extends Ritual { public static final String WATER_RANGE = "waterRange"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWellOfSuffering.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWellOfSuffering.java index 8d07813f..a1c96a08 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWellOfSuffering.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualWellOfSuffering.java @@ -17,6 +17,7 @@ import net.minecraftforge.fml.common.registry.EntityRegistry; import java.util.List; import java.util.function.Consumer; +@RitualRegister("well_of_suffering") public class RitualWellOfSuffering extends Ritual { public static final String ALTAR_RANGE = "altar"; public static final String DAMAGE_RANGE = "damage"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualZephyr.java b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualZephyr.java index d21d4e8c..780e5061 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/RitualZephyr.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/RitualZephyr.java @@ -13,6 +13,7 @@ import net.minecraft.world.World; import java.util.List; import java.util.function.Consumer; +@RitualRegister("zephyr") public class RitualZephyr extends Ritual { public static final String ZEPHYR_RANGE = "zephyrRange"; public static final String CHEST_RANGE = "chest"; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualDay.java b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualDay.java index 8c6d4eda..9d2a87ed 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualDay.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualDay.java @@ -6,6 +6,7 @@ import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +//@RitualRegister.Imperfect("day") public class ImperfectRitualDay extends ImperfectRitual { public ImperfectRitualDay() { super("day", s -> s.getBlock() == Blocks.GOLD_BLOCK, 5000, true, "ritual." + BloodMagic.MODID + ".imperfect.day"); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualNight.java b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualNight.java index 504fe1a0..f5a8746b 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualNight.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualNight.java @@ -1,11 +1,13 @@ package WayofTime.bloodmagic.ritual.types.imperfect; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ritual.RitualRegister; import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +@RitualRegister.Imperfect("night") public class ImperfectRitualNight extends ImperfectRitual { public ImperfectRitualNight() { super("night", s -> s.getBlock() == Blocks.LAPIS_BLOCK, 100, true, "ritual." + BloodMagic.MODID + ".imperfect.night"); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualRain.java b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualRain.java index 58e1ec6c..b7790a1e 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualRain.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualRain.java @@ -1,11 +1,13 @@ package WayofTime.bloodmagic.ritual.types.imperfect; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ritual.RitualRegister; import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +@RitualRegister.Imperfect("rain") public class ImperfectRitualRain extends ImperfectRitual { public ImperfectRitualRain() { super("rain", s -> s.getBlock() == Blocks.WATER, 5000, true, "ritual." + BloodMagic.MODID + ".imperfect.rain"); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualResistance.java b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualResistance.java index 9bb7e0de..b0281f53 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualResistance.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualResistance.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.ritual.types.imperfect; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ritual.RitualRegister; import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import net.minecraft.entity.player.EntityPlayer; @@ -8,6 +9,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.MobEffects; import net.minecraft.potion.PotionEffect; +@RitualRegister.Imperfect("resistance") public class ImperfectRitualResistance extends ImperfectRitual { public ImperfectRitualResistance() { super("resistance", s -> s.getBlock() == Blocks.BEDROCK, 5000, "ritual." + BloodMagic.MODID + ".imperfect.resistance"); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualZombie.java b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualZombie.java index 4c539eb4..bc8cb7cf 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualZombie.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/types/imperfect/ImperfectRitualZombie.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.ritual.types.imperfect; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.ritual.RitualRegister; import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import net.minecraft.entity.monster.EntityZombie; @@ -9,6 +10,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.MobEffects; import net.minecraft.potion.PotionEffect; +@RitualRegister.Imperfect("zombie") public class ImperfectRitualZombie extends ImperfectRitual { public ImperfectRitualZombie() { super("zombie", s -> s.getBlock() == Blocks.COAL_BLOCK, 5000, "ritual." + BloodMagic.MODID + ".imperfect.zombie"); diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileImperfectRitualStone.java b/src/main/java/WayofTime/bloodmagic/tile/TileImperfectRitualStone.java index 7e8b1d12..27b4e876 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileImperfectRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileImperfectRitualStone.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.tile; -import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry; +import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.core.data.SoulTicket; import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone; import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual; import WayofTime.bloodmagic.util.helper.NetworkHelper; @@ -9,6 +10,7 @@ import WayofTime.bloodmagic.tile.base.TileBase; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import javax.annotation.Nullable; @@ -17,9 +19,9 @@ public class TileImperfectRitualStone extends TileBase implements IImperfectRitu @Override public boolean performRitual(World world, BlockPos pos, @Nullable ImperfectRitual imperfectRitual, EntityPlayer player) { - if (imperfectRitual != null && ImperfectRitualRegistry.ritualEnabled(imperfectRitual)) { + if (imperfectRitual != null && BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(imperfectRitual), true)) { if (!PlayerHelper.isFakePlayer(player) && !world.isRemote) { - NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, imperfectRitual.getActivationCost()); + NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, new SoulTicket(new TextComponentTranslation(imperfectRitual.getUnlocalizedName()), imperfectRitual.getActivationCost())); if (imperfectRitual.onActivate(this, player)) { if (imperfectRitual.isLightShow()) getWorld().addWeatherEffect(new EntityLightningBolt(getWorld(), getPos().getX(), getPos().getY() + 2, getPos().getZ(), true)); diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java index 182b2cf3..68f01766 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java @@ -1,10 +1,10 @@ package WayofTime.bloodmagic.tile; +import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.event.RitualEvent; -import WayofTime.bloodmagic.ritual.RitualRegistry; import WayofTime.bloodmagic.ritual.IMasterRitualStone; import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.core.data.SoulNetwork; @@ -23,7 +23,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.Event; import javax.annotation.Nullable; import java.util.ArrayList; @@ -75,7 +74,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS owner = tag.hasUniqueId("owner") ? tag.getUniqueId("owner") : null; if (owner != null) cachedNetwork = NetworkHelper.getSoulNetwork(owner); - currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL)); + currentRitual = BloodMagic.RITUAL_MANAGER.getRitual(tag.getString(Constants.NBT.CURRENT_RITUAL)); if (currentRitual != null) { NBTTagCompound ritualTag = tag.getCompoundTag(Constants.NBT.CURRENT_RITUAL_TAG); if (!ritualTag.hasNoTags()) { @@ -96,7 +95,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS @Override public NBTTagCompound serialize(NBTTagCompound tag) { - String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual()); + String ritualId = BloodMagic.RITUAL_MANAGER.getId(getCurrentRitual()); if (owner != null) tag.setUniqueId("owner", owner); tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId); @@ -177,8 +176,8 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS @Override public void performRitual(World world, BlockPos pos) { - if (!world.isRemote && getCurrentRitual() != null && RitualRegistry.ritualEnabled(getCurrentRitual())) { - if (RitualHelper.checkValidRitual(getWorld(), getPos(), RitualRegistry.getIdForRitual(currentRitual), getDirection())) { + if (!world.isRemote && getCurrentRitual() != null && BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(currentRitual), false)) { + if (RitualHelper.checkValidRitual(getWorld(), getPos(), currentRitual, getDirection())) { RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(this, getOwner(), getCurrentRitual()); if (MinecraftForge.EVENT_BUS.post(event)) diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java index 15575efb..8f29bfab 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java @@ -4,7 +4,6 @@ import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.ConfigHandler; import WayofTime.bloodmagic.util.BMLog; import WayofTime.bloodmagic.util.Constants; -import WayofTime.bloodmagic.ritual.RitualRegistry; import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.ritual.RitualComponent; import WayofTime.bloodmagic.client.key.KeyBindings; @@ -246,7 +245,7 @@ public class ClientHandler { World world = player.getEntityWorld(); ItemRitualDiviner ritualDiviner = (ItemRitualDiviner) player.inventory.getCurrentItem().getItem(); EnumFacing direction = ritualDiviner.getDirection(player.inventory.getCurrentItem()); - Ritual ritual = RitualRegistry.getRitualForId(ritualDiviner.getCurrentRitual(player.inventory.getCurrentItem())); + Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(ritualDiviner.getCurrentRitual(player.inventory.getCurrentItem())); if (ritual == null) return; diff --git a/src/main/java/WayofTime/bloodmagic/util/helper/RitualHelper.java b/src/main/java/WayofTime/bloodmagic/util/helper/RitualHelper.java index fa6e3963..eedf6f7c 100644 --- a/src/main/java/WayofTime/bloodmagic/util/helper/RitualHelper.java +++ b/src/main/java/WayofTime/bloodmagic/util/helper/RitualHelper.java @@ -1,6 +1,6 @@ package WayofTime.bloodmagic.util.helper; -import WayofTime.bloodmagic.ritual.RitualRegistry; +import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.ritual.EnumRuneType; import WayofTime.bloodmagic.ritual.IRitualStone; import WayofTime.bloodmagic.ritual.Ritual; @@ -22,21 +22,7 @@ public class RitualHelper { static Capability RUNE_CAPABILITY = null; public static boolean canCrystalActivate(Ritual ritual, int crystalLevel) { - return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual); - } - - public static String getNextRitualKey(String currentKey) { - int currentIndex = RitualRegistry.getIds().indexOf(currentKey); - int nextIndex = RitualRegistry.getRituals().listIterator(currentIndex).nextIndex(); - - return RitualRegistry.getIds().get(nextIndex); - } - - public static String getPrevRitualKey(String currentKey) { - int currentIndex = RitualRegistry.getIds().indexOf(currentKey); - int previousIndex = RitualRegistry.getIds().listIterator(currentIndex).previousIndex(); - - return RitualRegistry.getIds().get(previousIndex); + return ritual.getCrystalLevel() <= crystalLevel && BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(ritual), false); } /** @@ -48,31 +34,26 @@ public class RitualHelper { * @return The ID of the valid ritual */ public static String getValidRitual(World world, BlockPos pos) { - for (String key : RitualRegistry.getIds()) { + for (Ritual ritual : BloodMagic.RITUAL_MANAGER.getRituals()) { for (EnumFacing direction : EnumFacing.HORIZONTALS) { - boolean test = checkValidRitual(world, pos, key, direction); - if (test) { - return key; - } + if (checkValidRitual(world, pos, ritual, direction)) + return BloodMagic.RITUAL_MANAGER.getId(ritual); } } return ""; } - public static EnumFacing getDirectionOfRitual(World world, BlockPos pos, String key) { + public static EnumFacing getDirectionOfRitual(World world, BlockPos pos, Ritual ritual) { for (EnumFacing direction : EnumFacing.HORIZONTALS) { - boolean test = checkValidRitual(world, pos, key, direction); - if (test) { + if (checkValidRitual(world, pos, ritual, direction)) return direction; - } } return null; } - public static boolean checkValidRitual(World world, BlockPos pos, String ritualId, EnumFacing direction) { - Ritual ritual = RitualRegistry.getRitualForId(ritualId); + public static boolean checkValidRitual(World world, BlockPos pos, Ritual ritual, EnumFacing direction) { if (ritual == null) { return false; } @@ -82,11 +63,8 @@ public class RitualHelper { for (RitualComponent component : components) { BlockPos newPos = pos.add(component.getOffset(direction)); - if (isRuneType(world, newPos, component.getRuneType())) { - continue; - } else { + if (!isRuneType(world, newPos, component.getRuneType())) return false; - } } return true; diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index e9227fde..bacb10da 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -449,7 +449,7 @@ tooltip.bloodmagic.activation_crystal.weak=Activates low-level rituals tooltip.bloodmagic.activation_crystal.awakened=Activates more powerful rituals tooltip.bloodmagic.activation_crystal.creative=Creative Only - Activates any ritual -tooltip.bloodmagic.diviner.currentRitual=Current Ritual: +tooltip.bloodmagic.diviner.currentRitual=Current Ritual: %s tooltip.bloodmagic.diviner.blankRune=Blank Runes: %d tooltip.bloodmagic.diviner.waterRune=Water Runes: %d tooltip.bloodmagic.diviner.airRune=Air Runes: %d