Rework of ritual registration

Moves to annotation based registration. Configs are handled for automatically
This commit is contained in:
Nicholas Ignoffo 2018-06-28 21:56:25 -07:00
parent e3d65a9e3a
commit 42c69eb557
54 changed files with 321 additions and 569 deletions

View file

@ -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<Pair<IBloodMagicPlugin, BloodMagicPlugin>> 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) {

View file

@ -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." })

View file

@ -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<EnumRitualController> 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<EnumRitualController> 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<EnumRitualController> 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());
}

View file

@ -26,6 +26,7 @@ public class GuiBloodMagicConfig extends GuiConfig {
List<IConfigElement> 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"));

View file

@ -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));
}
}

View file

@ -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<RitualComponent> 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<String> idList = RitualRegistry.getOrderedIds();
List<Ritual> 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<String> 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) {

View file

@ -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);

View file

@ -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 {

View file

@ -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<String, Ritual> rituals;
private final Map<Ritual, String> ritualsReverse;
private final List<Ritual> sortedRituals;
private final Map<String, ImperfectRitual> imperfectRituals;
private final Map<ImperfectRitual, String> 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<ASMDataTable.ASMData> 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<? extends Ritual> 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<ASMDataTable.ASMData> 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<? extends ImperfectRitual> 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<RitualComponent> 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<Ritual> getRituals() {
return rituals.values();
}
public Collection<ImperfectRitual> getImperfectRituals() {
return imperfectRituals.values();
}
public List<Ritual> 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);
}
}
}

View file

@ -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<? extends Function<Class<? extends Ritual>, Ritual>> factory() default DefaultRitualFactory.class;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Imperfect {
String value();
Class<? extends Function<Class<? extends ImperfectRitual>, ImperfectRitual>> factory() default DefaultImperfectRitualFactory.class;
}
class DefaultRitualFactory implements Function<Class<? extends Ritual>, Ritual> {
@Override
public Ritual apply(Class<? extends Ritual> aClass) {
try {
return aClass.newInstance();
} catch (Exception e) {
return null;
}
}
}
class DefaultImperfectRitualFactory implements Function<Class<? extends ImperfectRitual>, ImperfectRitual> {
@Override
public ImperfectRitual apply(Class<? extends ImperfectRitual> aClass) {
try {
return aClass.newInstance();
} catch (Exception e) {
return null;
}
}
}
}

View file

@ -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<Ritual, Boolean> enabledRituals = new HashMap<>();
private static final BiMap<String, Ritual> registry = HashBiMap.create();
private static final List<String> lookupList = new ArrayList<>();
/**
* Ordered list for actions that depend on the order that the rituals were
* registered in
*/
private static final ArrayList<String> 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<String, Ritual> getRegistry() {
return HashBiMap.create(registry);
}
public static Map<Ritual, Boolean> getEnabledMap() {
return new HashMap<>(enabledRituals);
}
public static ArrayList<String> getIds() {
return new ArrayList<>(lookupList);
}
public static ArrayList<String> getOrderedIds() {
return orderedIdList;
}
public static ArrayList<Ritual> 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<RitualComponent> first = Lists.newArrayList();
ritual1.gatherComponents(first::add);
List<RitualComponent> second = Lists.newArrayList();
ritual2.gatherComponents(second::add);
return first.size() > second.size() ? -1 : 0; // Put earlier if bigger
});
}
}

View file

@ -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 {

View file

@ -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<ImperfectRitual, Boolean> enabledRituals = new HashMap<>();
private static final BiMap<String, ImperfectRitual> 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<String, ImperfectRitual> getRegistry() {
return HashBiMap.create(registry);
}
public static BiMap<ImperfectRitual, Boolean> getEnabledMap() {
return HashBiMap.create(enabledRituals);
}
public static ArrayList<String> getIds() {
return new ArrayList<>(registry.keySet());
}
public static ArrayList<ImperfectRitual> getRituals() {
return new ArrayList<>(registry.values());
}
}

View file

@ -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<AltarComponent> altarComponentsIterator = new ArrayList<>(AltarTier.SIX.getAltarComponents()).iterator();
private boolean cycleDone = false;

View file

@ -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;

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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()

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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;

View file

@ -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;

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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));

View file

@ -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))

View file

@ -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;

View file

@ -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<IRitualStone.Tile> 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;

View file

@ -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