Imperfect rituals work mostly now
Just need to figure out an issue with the config
This commit is contained in:
parent
3a0dcae59a
commit
92bf7cc35b
15 changed files with 226 additions and 64 deletions
|
@ -1,15 +1,17 @@
|
|||
package WayofTime.bloodmagic.api.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.BlockStack;
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImperfectRitualRegistry {
|
||||
|
||||
public static final BiMap<ImperfectRitual, Boolean> enabledRituals = HashBiMap.create();
|
||||
private static final BiMap<ImperfectRitual, Boolean> enabledRituals = HashBiMap.create();
|
||||
private static final BiMap<String, ImperfectRitual> registry = HashBiMap.create();
|
||||
|
||||
/**
|
||||
|
@ -27,6 +29,17 @@ public class ImperfectRitualRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public static ImperfectRitual getRitualForBlock(BlockStack blockStack) {
|
||||
for (ImperfectRitual imperfectRitual : getRegistry().values()) {
|
||||
if (imperfectRitual.getRequiredBlock().equals(blockStack)) {
|
||||
System.out.println(imperfectRitual.toString());
|
||||
return imperfectRitual;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ImperfectRitual getRitualForId(String id) {
|
||||
return registry.get(id);
|
||||
}
|
||||
|
@ -44,13 +57,22 @@ public class ImperfectRitualRegistry {
|
|||
}
|
||||
|
||||
public static boolean ritualEnabled(ImperfectRitual imperfectRitual) {
|
||||
return enabledRituals.get(imperfectRitual);
|
||||
try {
|
||||
return enabledRituals.get(imperfectRitual);
|
||||
} catch (NullPointerException e) {
|
||||
BloodMagicAPI.getLogger().error("Invalid Imperfect Ritual was called");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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<String>(registry.keySet());
|
||||
}
|
||||
|
|
|
@ -2,13 +2,14 @@ package WayofTime.bloodmagic.api.registry;
|
|||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RitualRegistry {
|
||||
|
||||
public static final BiMap<Ritual, Boolean> enabledRituals = HashBiMap.create();
|
||||
private static final BiMap<Ritual, Boolean> enabledRituals = HashBiMap.create();
|
||||
private static final BiMap<String, Ritual> registry = HashBiMap.create();
|
||||
|
||||
/**
|
||||
|
@ -43,13 +44,22 @@ public class RitualRegistry {
|
|||
}
|
||||
|
||||
public static boolean ritualEnabled(Ritual ritual) {
|
||||
return enabledRituals.get(ritual);
|
||||
try {
|
||||
return enabledRituals.get(ritual);
|
||||
} catch (NullPointerException e) {
|
||||
BloodMagicAPI.getLogger().error("Invalid Ritual was called");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static BiMap<String, Ritual> getRegistry() {
|
||||
return HashBiMap.create(registry);
|
||||
}
|
||||
|
||||
public static BiMap<Ritual, Boolean> getEnabledMap() {
|
||||
return HashBiMap.create(enabledRituals);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getIds() {
|
||||
return new ArrayList<String>(registry.keySet());
|
||||
}
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IMasterRitualStone extends IImperfectRitualStone {
|
||||
public interface IMasterRitualStone {
|
||||
|
||||
String getOwner();
|
||||
|
||||
boolean activateRitual(ItemStack activationCrystal, EntityPlayer activator);
|
||||
|
||||
void performRitual(World world, BlockPos pos, Ritual ritual);
|
||||
|
||||
void stopRitual();
|
||||
|
||||
void setCooldown(int cooldown);
|
||||
|
||||
int getCooldown();
|
||||
|
@ -18,15 +24,11 @@ public interface IMasterRitualStone extends IImperfectRitualStone {
|
|||
|
||||
EnumFacing getDirection();
|
||||
|
||||
NBTTagCompound getCustomRitualTag();
|
||||
|
||||
void setCustomRitualTag(NBTTagCompound tag);
|
||||
|
||||
boolean areTanksEmpty();
|
||||
|
||||
int getRunningTime();
|
||||
|
||||
LocalRitualStorage getLocalStorage();
|
||||
World getWorld();
|
||||
|
||||
void setLocalStorage(LocalRitualStorage storage);
|
||||
BlockPos getPos();
|
||||
}
|
||||
|
|
|
@ -32,10 +32,6 @@ public abstract class Ritual {
|
|||
|
||||
public abstract ArrayList<RitualComponent> getComponents();
|
||||
|
||||
public LocalRitualStorage getNewLocalStorage() {
|
||||
return new LocalRitualStorage();
|
||||
}
|
||||
|
||||
public void addOffsetRunes(ArrayList<RitualComponent> components, int offset1, int offset2, int y, EnumRuneType rune) {
|
||||
components.add(new RitualComponent(new BlockPos(offset1, y, offset2), rune));
|
||||
components.add(new RitualComponent(new BlockPos(offset2, y, offset1), rune));
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package WayofTime.bloodmagic.api.ritual.imperfect;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IImperfectRitualStone {
|
||||
|
||||
String getOwner();
|
||||
boolean performRitual(World world, BlockPos pos, ImperfectRitual imperfectRitual, EntityPlayer player);
|
||||
|
||||
World getWorld();
|
||||
|
||||
|
|
|
@ -1,19 +1,27 @@
|
|||
package WayofTime.bloodmagic.api.ritual.imperfect;
|
||||
|
||||
import WayofTime.bloodmagic.api.BlockStack;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public abstract class ImperfectRitual {
|
||||
|
||||
private final String name;
|
||||
private final BlockStack requiredBlock;
|
||||
private final int activationCost;
|
||||
private final boolean lightshow;
|
||||
|
||||
public ImperfectRitual(BlockStack requiredBlock, int activationCost) {
|
||||
this(requiredBlock, activationCost, false);
|
||||
public ImperfectRitual(String name, BlockStack requiredBlock, int activationCost) {
|
||||
this(name, requiredBlock, activationCost, false);
|
||||
}
|
||||
|
||||
public abstract boolean onActivate(IImperfectRitualStone imperfectRitualStone, EntityPlayer player);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName() + ":" + getRequiredBlock().toString() + "@" + getActivationCost();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
|
||||
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
||||
import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import sun.misc.Launcher;
|
||||
|
||||
|
@ -28,6 +31,14 @@ public class RitualHelper {
|
|||
return RitualRegistry.getIds().get(previousIndex);
|
||||
}
|
||||
|
||||
public static void checkImperfectRituals(Configuration config, String packageName, String category) {
|
||||
checkRituals(config, packageName, category, ImperfectRitual.class, ImperfectRitualRegistry.getEnabledMap());
|
||||
}
|
||||
|
||||
public static void checkRituals(Configuration config, String packageName, String category) {
|
||||
checkRituals(config, packageName, category, Ritual.class, RitualRegistry.getEnabledMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
||||
* This is used to determine whether your effect is enabled or not.
|
||||
|
@ -35,13 +46,16 @@ public class RitualHelper {
|
|||
* The config option will be created as {@code B:ClassName=true} with a comment of
|
||||
* {@code Enables the ClassName ritual}.
|
||||
*
|
||||
* Use {@link #}
|
||||
*
|
||||
* Should be safe to modify at any point.
|
||||
*
|
||||
* @param config - Your mod's Forge {@link Configuration} object.
|
||||
* @param packageName - The package your Rituals are located in.
|
||||
* @param category - The config category to write to.
|
||||
*/
|
||||
public static void checkRituals(Configuration config, String packageName, String category) {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void checkRituals(Configuration config, String packageName, String category, Class ritualClass, BiMap enabledMap) {
|
||||
String name = packageName;
|
||||
if (!name.startsWith("/"))
|
||||
name = "/" + name;
|
||||
|
@ -60,8 +74,9 @@ public class RitualHelper {
|
|||
try {
|
||||
Object o = Class.forName(packageName + "." + className).newInstance();
|
||||
|
||||
if (o instanceof Ritual)
|
||||
RitualRegistry.enabledRituals.put((Ritual) o, config.get(category, className, true).getBoolean());
|
||||
if (ritualClass.isInstance(o))
|
||||
enabledMap.put(ritualClass.cast(o),
|
||||
config.get(category, className, true).getBoolean());
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue