Some more ritual work + imperfect rituals
This commit is contained in:
parent
3a7e0a3a8c
commit
afad5b0fd0
|
@ -15,6 +15,10 @@ public class NBTHolder {
|
||||||
public static final String NBT_COORDZ = "zCoord";
|
public static final String NBT_COORDZ = "zCoord";
|
||||||
public static final String NBT_MAXORB = "maxOrb";
|
public static final String NBT_MAXORB = "maxOrb";
|
||||||
public static final String NBT_CURRENTESSENCE = "currentEssence";
|
public static final String NBT_CURRENTESSENCE = "currentEssence";
|
||||||
|
public static final String NBT_CURRENTRITUAL = "currentRitual";
|
||||||
|
public static final String NBT_RUNNING = "isRunning";
|
||||||
|
public static final String NBT_RUNTIME = "runtime";
|
||||||
|
public static final String NBT_REAGENTTANK = "reagentTanks";
|
||||||
|
|
||||||
public static ItemStack checkNBT(ItemStack stack) {
|
public static ItemStack checkNBT(ItemStack stack) {
|
||||||
if (stack.getTagCompound() == null)
|
if (stack.getTagCompound() == null)
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package WayofTime.alchemicalWizardry.api.event;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.IMasterRitualStone;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.Ritual;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.imperfect.IImperfectRitualStone;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.imperfect.ImperfectRitual;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
|
public class RitualEvent extends Event {
|
||||||
|
|
||||||
|
public final IMasterRitualStone mrs;
|
||||||
|
public final String ownerName;
|
||||||
|
public final Ritual ritual;
|
||||||
|
|
||||||
|
private RitualEvent(IMasterRitualStone mrs, String ownerName, Ritual ritual) {
|
||||||
|
this.mrs = mrs;
|
||||||
|
this.ownerName = ownerName;
|
||||||
|
this.ritual = ritual;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is called when a ritual is activated. If cancelled, it will not activate.
|
||||||
|
*
|
||||||
|
* {@link WayofTime.alchemicalWizardry.api.util.helper.RitualHelper#activate(IMasterRitualStone, Ritual, EntityPlayer)}
|
||||||
|
*/
|
||||||
|
@Cancelable
|
||||||
|
public static class RitualActivatedEvent extends RitualEvent {
|
||||||
|
public final EntityPlayer player;
|
||||||
|
public final ItemStack crystalStack;
|
||||||
|
public int crystalTier;
|
||||||
|
|
||||||
|
public RitualActivatedEvent(IMasterRitualStone mrs, String owner, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) {
|
||||||
|
super(mrs, owner, ritual);
|
||||||
|
|
||||||
|
this.player = player;
|
||||||
|
this.crystalStack = activationCrystal;
|
||||||
|
this.crystalTier = crystalTier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is called when a Ritual effect is performed. If cancelled, the effect will not happen.
|
||||||
|
*
|
||||||
|
* {@link WayofTime.alchemicalWizardry.api.util.helper.RitualHelper#perform(IMasterRitualStone, Ritual)}
|
||||||
|
*/
|
||||||
|
@Cancelable
|
||||||
|
public static class RitualRunEvent extends RitualEvent {
|
||||||
|
|
||||||
|
public RitualRunEvent(IMasterRitualStone mrs, String owner, Ritual ritual) {
|
||||||
|
super(mrs, owner, ritual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is called when a Ritual is stopped by a {@link Ritual.BreakType}.
|
||||||
|
*
|
||||||
|
* {@link WayofTime.alchemicalWizardry.api.util.helper.RitualHelper#stop(IMasterRitualStone, Ritual, Ritual.BreakType)}
|
||||||
|
*/
|
||||||
|
public static class RitualStopEvent extends RitualEvent {
|
||||||
|
|
||||||
|
public final Ritual.BreakType method;
|
||||||
|
|
||||||
|
public RitualStopEvent(IMasterRitualStone mrs, String owner, Ritual ritual, Ritual.BreakType method) {
|
||||||
|
super(mrs, owner, ritual);
|
||||||
|
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cancelable
|
||||||
|
public static class ImperfectRitualActivatedEvent extends Event {
|
||||||
|
|
||||||
|
public final IImperfectRitualStone ims;
|
||||||
|
public final String ownerName;
|
||||||
|
public final ImperfectRitual imperfectRitual;
|
||||||
|
|
||||||
|
public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, String ownerName, ImperfectRitual imperfectRitual) {
|
||||||
|
this.ims = ims;
|
||||||
|
this.ownerName = ownerName;
|
||||||
|
this.imperfectRitual = imperfectRitual;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package WayofTime.alchemicalWizardry.api.registry;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.AlchemicalWizardryAPI;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.imperfect.ImperfectRitual;
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ImperfectRitualRegistry {
|
||||||
|
|
||||||
|
public static final BiMap<ImperfectRitual, Boolean> enabledRituals = HashBiMap.create();
|
||||||
|
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) {
|
||||||
|
if (imperfectRitual != null) {
|
||||||
|
if (registry.containsKey(id))
|
||||||
|
AlchemicalWizardryAPI.getLogger().error("Duplicate imperfect ritual id: " + id);
|
||||||
|
else
|
||||||
|
registry.put(id, imperfectRitual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
return enabledRituals.get(imperfectRitual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BiMap<String, ImperfectRitual> getRegistry() {
|
||||||
|
return HashBiMap.create(registry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> getIds() {
|
||||||
|
return new ArrayList<String>(registry.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<ImperfectRitual> getRituals() {
|
||||||
|
return new ArrayList<ImperfectRitual>(registry.values());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package WayofTime.alchemicalWizardry.api.registry;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.AlchemicalWizardryAPI;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.Ritual;
|
||||||
|
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<String, Ritual> registry = HashBiMap.create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
if (ritual != null) {
|
||||||
|
if (registry.containsKey(id))
|
||||||
|
AlchemicalWizardryAPI.getLogger().error("Duplicate ritual id: " + id);
|
||||||
|
else
|
||||||
|
registry.put(id, ritual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ritual getRitualForId(String id) {
|
||||||
|
return registry.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
return enabledRituals.get(ritual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BiMap<String, Ritual> getRegistry() {
|
||||||
|
return HashBiMap.create(registry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> getIds() {
|
||||||
|
return new ArrayList<String>(registry.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Ritual> getRituals() {
|
||||||
|
return new ArrayList<Ritual>(registry.values());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,15 @@
|
||||||
package WayofTime.alchemicalWizardry.api.ritual;
|
package WayofTime.alchemicalWizardry.api.ritual;
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.api.ritual.LocalRitualStorage;
|
import WayofTime.alchemicalWizardry.api.ritual.imperfect.IImperfectRitualStone;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public interface IMasterRitualStone {
|
public interface IMasterRitualStone extends IImperfectRitualStone {
|
||||||
|
|
||||||
void performRitual(World world, BlockPos pos, String ritualID);
|
void performRitual(World world, BlockPos pos, String ritualID);
|
||||||
|
|
||||||
String getOwner();
|
|
||||||
|
|
||||||
void setCooldown(int cooldown);
|
void setCooldown(int cooldown);
|
||||||
|
|
||||||
int getCooldown();
|
int getCooldown();
|
||||||
|
@ -20,10 +18,6 @@ public interface IMasterRitualStone {
|
||||||
|
|
||||||
EnumFacing getDirection();
|
EnumFacing getDirection();
|
||||||
|
|
||||||
World getWorld();
|
|
||||||
|
|
||||||
BlockPos getPos();
|
|
||||||
|
|
||||||
NBTTagCompound getCustomRitualTag();
|
NBTTagCompound getCustomRitualTag();
|
||||||
|
|
||||||
void setCustomRitualTag(NBTTagCompound tag);
|
void setCustomRitualTag(NBTTagCompound tag);
|
||||||
|
|
|
@ -3,39 +3,62 @@ package WayofTime.alchemicalWizardry.api.ritual;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class Ritual {
|
public abstract class Ritual {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int crystalLevel;
|
private final int crystalLevel;
|
||||||
private final int activationCost;
|
private final int activationCost;
|
||||||
private final RitualEffect ritualEffect;
|
|
||||||
private final RitualRenderer renderer;
|
private final RitualRenderer renderer;
|
||||||
|
|
||||||
public Ritual(String name, int crystalLevel, int activationCost, RitualEffect ritualEffect) {
|
public final ArrayList<RitualComponent> ritualComponents = new ArrayList<RitualComponent>();
|
||||||
this(name, crystalLevel, activationCost, ritualEffect, null);
|
|
||||||
|
public Ritual(String name, int crystalLevel, int activationCost) {
|
||||||
|
this(name, crystalLevel, activationCost, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<RitualComponent> getComponents() {
|
public abstract boolean startRitual(IMasterRitualStone masterRitualStone, EntityPlayer player);
|
||||||
return this.getRitualEffect().getComponents();
|
|
||||||
|
public abstract void performEffect(IMasterRitualStone masterRitualStone);
|
||||||
|
|
||||||
|
public abstract void onRitualBroken(IMasterRitualStone masterRitualStone, Ritual.BreakType breakType);
|
||||||
|
|
||||||
|
public abstract int getRefreshCost();
|
||||||
|
|
||||||
|
public abstract ArrayList<RitualComponent> getComponents();
|
||||||
|
|
||||||
|
public LocalRitualStorage getNewLocalStorage() {
|
||||||
|
return new LocalRitualStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performEffect(IMasterRitualStone masterRitualStone) {
|
public void addOffsetRunes(ArrayList<RitualComponent> components, int offset1, int offset2, int y, EnumRuneType rune) {
|
||||||
if (ritualEffect != null && RitualRegistry.ritualEnabled(this))
|
components.add(new RitualComponent(new BlockPos(offset1, y, offset2), rune));
|
||||||
ritualEffect.performEffect(masterRitualStone);
|
components.add(new RitualComponent(new BlockPos(offset2, y, offset1), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(offset1, y, -offset2), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(-offset2, y, offset1), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(-offset1, y, offset2), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(offset2, y, -offset1), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(-offset1, y, -offset2), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(-offset2, y, -offset1), rune));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startRitual(IMasterRitualStone masterRitualStone, EntityPlayer player) {
|
public void addCornerRunes(ArrayList<RitualComponent> components, int offset, int y, EnumRuneType rune) {
|
||||||
return ritualEffect != null && RitualRegistry.ritualEnabled(this) && ritualEffect.startRitual(masterRitualStone, player);
|
components.add(new RitualComponent(new BlockPos(offset, y, offset), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(offset, y, -offset), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(-offset, y, -offset), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(-offset, y, offset), rune));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBreak(IMasterRitualStone masterRitualStone, BreakType breakType) {
|
public void addParallelRunes(ArrayList<RitualComponent> components, int offset, int y, EnumRuneType rune) {
|
||||||
if (ritualEffect != null && RitualRegistry.ritualEnabled(this))
|
components.add(new RitualComponent(new BlockPos(offset, y, 0), rune));
|
||||||
ritualEffect.onRitualBroken(masterRitualStone, breakType);
|
components.add(new RitualComponent(new BlockPos(-offset, y, 0), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(0, y, -offset), rune));
|
||||||
|
components.add(new RitualComponent(new BlockPos(0, y, offset), rune));
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BreakType {
|
public enum BreakType {
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
package WayofTime.alchemicalWizardry.api.ritual;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.util.BlockPos;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
// TODO - Return after Reagents are done
|
|
||||||
public abstract class RitualEffect {
|
|
||||||
|
|
||||||
public boolean startRitual(IMasterRitualStone masterRitualStone, EntityPlayer player) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRitualBroken(IMasterRitualStone masterRitualStone, Ritual.BreakType breakType) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalRitualStorage getNewLocalStorage() {
|
|
||||||
return new LocalRitualStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addOffsetRunes(ArrayList<RitualComponent> ritualList, int offset1, int offset2, int y, EnumRuneType rune) {
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset1, y, offset2), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset2, y, offset1), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset1, y, -offset2), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset2, y, offset1), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset1, y, offset2), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset2, y, -offset1), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset1, y, -offset2), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset2, y, -offset1), rune));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addCornerRunes(ArrayList<RitualComponent> ritualList, int offset, int y, EnumRuneType rune) {
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset, y, offset), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset, y, -offset), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset, y, -offset), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset, y, offset), rune));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addParallelRunes(ArrayList<RitualComponent> ritualList, int offset, int y, EnumRuneType rune) {
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(offset, y, 0), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(-offset, y, 0), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(0, y, -offset), rune));
|
|
||||||
ritualList.add(new RitualComponent(new BlockPos(0, y, offset), rune));
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void performEffect(IMasterRitualStone masterRitualStone);
|
|
||||||
|
|
||||||
public abstract int getRefreshCost();
|
|
||||||
|
|
||||||
public abstract ArrayList<RitualComponent> getComponents();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
package WayofTime.alchemicalWizardry.api.ritual;
|
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import com.google.common.collect.HashBiMap;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import sun.misc.Launcher;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class RitualRegistry {
|
|
||||||
|
|
||||||
public static final Map<RitualEffect, Boolean> enabledRituals = new HashMap<RitualEffect, Boolean>();
|
|
||||||
private static BiMap<String, Ritual> registry = HashBiMap.create();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
if (ritual != null) {
|
|
||||||
if (registry.containsKey(id))
|
|
||||||
AlchemicalWizardry.instance.getLogger().error("Duplicate ritual id: " + id);
|
|
||||||
else
|
|
||||||
registry.put(id, ritual);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Ritual getRitualForId(String id) {
|
|
||||||
return registry.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
return enabledRituals.get(ritual.getRitualEffect());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<String> getIds() {
|
|
||||||
return new ArrayList<String>(registry.keySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<Ritual> getRituals() {
|
|
||||||
return new ArrayList<Ritual>(registry.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
|
||||||
* This is used to determine whether your effect is enabled or not.
|
|
||||||
*
|
|
||||||
* The config option will be created as {@code B:ClassName=true} with a comment of
|
|
||||||
* {@code Enables the ClassName ritual}.
|
|
||||||
*
|
|
||||||
* 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) {
|
|
||||||
String name = packageName;
|
|
||||||
if (!name.startsWith("/"))
|
|
||||||
name = "/" + name;
|
|
||||||
|
|
||||||
name = name.replace('.', '/');
|
|
||||||
URL url = Launcher.class.getResource(name);
|
|
||||||
File directory = new File(url.getFile());
|
|
||||||
|
|
||||||
if (directory.exists()) {
|
|
||||||
String[] files = directory.list();
|
|
||||||
|
|
||||||
for (String file : files) {
|
|
||||||
if (file.endsWith(".class")) {
|
|
||||||
String className = file.substring(0, file.length() - 6);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Object o = Class.forName(packageName + "." + className).newInstance();
|
|
||||||
|
|
||||||
if (o instanceof RitualEffect)
|
|
||||||
RitualRegistry.enabledRituals.put((RitualEffect) o, config.get(category, className, true).getBoolean());
|
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package WayofTime.alchemicalWizardry.api.ritual.imperfect;
|
||||||
|
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public interface IImperfectRitualStone {
|
||||||
|
|
||||||
|
String getOwner();
|
||||||
|
|
||||||
|
World getWorld();
|
||||||
|
|
||||||
|
BlockPos getPos();
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package WayofTime.alchemicalWizardry.api.ritual.imperfect;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.BlockStack;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public abstract class ImperfectRitual {
|
||||||
|
|
||||||
|
private final BlockStack requiredBlock;
|
||||||
|
private final int activationCost;
|
||||||
|
private final boolean lightshow;
|
||||||
|
|
||||||
|
public ImperfectRitual(BlockStack requiredBlock, int activationCost) {
|
||||||
|
this(requiredBlock, activationCost, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean onActivate(IImperfectRitualStone imperfectRitualStone, EntityPlayer player);
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
package WayofTime.alchemicalWizardry.api.util.helper;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.event.RitualEvent;
|
||||||
|
import WayofTime.alchemicalWizardry.api.registry.RitualRegistry;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.IMasterRitualStone;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.Ritual;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.imperfect.IImperfectRitualStone;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.imperfect.ImperfectRitual;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
import sun.misc.Launcher;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class RitualHelper {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean activate(IMasterRitualStone masterRitualStone, Ritual ritual, EntityPlayer player) {
|
||||||
|
String owner = masterRitualStone.getOwner();
|
||||||
|
|
||||||
|
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(masterRitualStone, owner, ritual, player, player.getHeldItem(), player.getHeldItem().getItemDamage());
|
||||||
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return RitualRegistry.ritualEnabled(ritual) && ritual.startRitual(masterRitualStone, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void perform(IMasterRitualStone masterRitualStone, Ritual ritual) {
|
||||||
|
String owner = masterRitualStone.getOwner();
|
||||||
|
|
||||||
|
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(masterRitualStone, owner, ritual);
|
||||||
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (RitualRegistry.ritualEnabled(ritual))
|
||||||
|
ritual.performEffect(masterRitualStone);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stop(IMasterRitualStone masterRitualStone, Ritual ritual, Ritual.BreakType breakType) {
|
||||||
|
String owner = masterRitualStone.getOwner();
|
||||||
|
|
||||||
|
RitualEvent.RitualStopEvent event = new RitualEvent.RitualStopEvent(masterRitualStone, owner, ritual, breakType);
|
||||||
|
MinecraftForge.EVENT_BUS.post(event);
|
||||||
|
|
||||||
|
ritual.onRitualBroken(masterRitualStone, breakType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
||||||
|
* This is used to determine whether your effect is enabled or not.
|
||||||
|
*
|
||||||
|
* The config option will be created as {@code B:ClassName=true} with a comment of
|
||||||
|
* {@code Enables the ClassName ritual}.
|
||||||
|
*
|
||||||
|
* 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) {
|
||||||
|
String name = packageName;
|
||||||
|
if (!name.startsWith("/"))
|
||||||
|
name = "/" + name;
|
||||||
|
|
||||||
|
name = name.replace('.', '/');
|
||||||
|
URL url = Launcher.class.getResource(name);
|
||||||
|
File directory = new File(url.getFile());
|
||||||
|
|
||||||
|
if (directory.exists()) {
|
||||||
|
String[] files = directory.list();
|
||||||
|
|
||||||
|
for (String file : files) {
|
||||||
|
if (file.endsWith(".class")) {
|
||||||
|
String className = file.substring(0, file.length() - 6);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object o = Class.forName(packageName + "." + className).newInstance();
|
||||||
|
|
||||||
|
if (o instanceof Ritual)
|
||||||
|
RitualRegistry.enabledRituals.put((Ritual) o, config.get(category, className, true).getBoolean());
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Imperfect {
|
||||||
|
|
||||||
|
public static boolean activate(IImperfectRitualStone imperfectRitualStone, ImperfectRitual imperfectRitual, EntityPlayer player) {
|
||||||
|
String owner = imperfectRitualStone.getOwner();
|
||||||
|
|
||||||
|
RitualEvent.ImperfectRitualActivatedEvent event = new RitualEvent.ImperfectRitualActivatedEvent(imperfectRitualStone, owner, imperfectRitual);
|
||||||
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
return imperfectRitual.onActivate(imperfectRitualStone, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package WayofTime.alchemicalWizardry.block;
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.PropertyInteger;
|
import net.minecraft.block.properties.PropertyInteger;
|
||||||
import net.minecraft.block.state.BlockState;
|
import net.minecraft.block.state.BlockState;
|
||||||
|
@ -10,6 +11,7 @@ import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -18,7 +20,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockRitualController extends Block {
|
public class BlockRitualController extends BlockContainer {
|
||||||
|
|
||||||
public static final String[] names = { "master", "imperfect" };
|
public static final String[] names = { "master", "imperfect" };
|
||||||
public static final PropertyInteger META = PropertyInteger.create("meta", 0, names.length - 1);
|
public static final PropertyInteger META = PropertyInteger.create("meta", 0, names.length - 1);
|
||||||
|
@ -65,4 +67,9 @@ public class BlockRitualController extends Block {
|
||||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||||
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createNewTileEntity(World world, int meta) {
|
||||||
|
return meta == 0 ? null : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
package WayofTime.alchemicalWizardry.tile;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.NBTHolder;
|
||||||
|
import WayofTime.alchemicalWizardry.api.registry.RitualRegistry;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.IMasterRitualStone;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.LocalRitualStorage;
|
||||||
|
import WayofTime.alchemicalWizardry.api.ritual.Ritual;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.server.gui.IUpdatePlayerListBox;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class TileMasterRitualStone extends TileEntity implements IMasterRitualStone, IUpdatePlayerListBox {
|
||||||
|
|
||||||
|
private String owner;
|
||||||
|
private boolean active;
|
||||||
|
private int activeTime;
|
||||||
|
private int cooldown;
|
||||||
|
private Ritual currentRitual;
|
||||||
|
private EnumFacing direction;
|
||||||
|
|
||||||
|
public LocalRitualStorage storage;
|
||||||
|
public NBTTagCompound customTag;
|
||||||
|
|
||||||
|
public TileMasterRitualStone() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readClientNBT(NBTTagCompound tag) {
|
||||||
|
currentRitual = RitualRegistry.getRitualForId(tag.getString(NBTHolder.NBT_CURRENTRITUAL));
|
||||||
|
active = tag.getBoolean(NBTHolder.NBT_RUNNING);
|
||||||
|
activeTime = tag.getInteger(NBTHolder.NBT_RUNTIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeClientNBT(NBTTagCompound tag) {
|
||||||
|
tag.setString(NBTHolder.NBT_CURRENTRITUAL, RitualRegistry.getIdForRitual(currentRitual));
|
||||||
|
tag.setBoolean(NBTHolder.NBT_RUNNING, active);
|
||||||
|
tag.setInteger(NBTHolder.NBT_RUNTIME, activeTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performRitual(World world, BlockPos pos, String ritualID) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCooldown(int cooldown) {
|
||||||
|
this.cooldown = cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCooldown() {
|
||||||
|
return cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumFacing getDirection() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBTTagCompound getCustomRitualTag() {
|
||||||
|
return customTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCustomRitualTag(NBTTagCompound tag) {
|
||||||
|
this.customTag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areTanksEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRunningTime() {
|
||||||
|
return activeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalRitualStorage getLocalStorage() {
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLocalStorage(LocalRitualStorage storage) {
|
||||||
|
this.storage = storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getWorld() {
|
||||||
|
return super.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockPos getPos() {
|
||||||
|
return super.getPos();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue