Begin rituals + some refactoring
This commit is contained in:
parent
07b1f36594
commit
3a7e0a3a8c
|
@ -2,9 +2,9 @@ package WayofTime.alchemicalWizardry.altar;
|
|||
|
||||
import WayofTime.alchemicalWizardry.api.BlockStack;
|
||||
import WayofTime.alchemicalWizardry.api.altar.AltarComponent;
|
||||
import WayofTime.alchemicalWizardry.api.iface.IAltarComponent;
|
||||
import WayofTime.alchemicalWizardry.api.enumeration.EnumAltarComponent;
|
||||
import WayofTime.alchemicalWizardry.api.enumeration.EnumAltarTier;
|
||||
import WayofTime.alchemicalWizardry.api.altar.IAltarComponent;
|
||||
import WayofTime.alchemicalWizardry.api.altar.EnumAltarComponent;
|
||||
import WayofTime.alchemicalWizardry.api.altar.EnumAltarTier;
|
||||
import net.minecraft.block.BlockBeacon;
|
||||
import net.minecraft.block.BlockGlowstone;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package WayofTime.alchemicalWizardry.api.enumeration;
|
||||
package WayofTime.alchemicalWizardry.api.altar;
|
||||
|
||||
public enum EnumAltarComponent {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package WayofTime.alchemicalWizardry.api.enumeration;
|
||||
package WayofTime.alchemicalWizardry.api.altar;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.BlockStack;
|
||||
import WayofTime.alchemicalWizardry.api.altar.AltarComponent;
|
|
@ -0,0 +1,6 @@
|
|||
package WayofTime.alchemicalWizardry.api.altar;
|
||||
|
||||
public interface IAltarComponent {
|
||||
|
||||
EnumAltarComponent getType(int meta);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package WayofTime.alchemicalWizardry.api.iface;
|
||||
package WayofTime.alchemicalWizardry.api.altar;
|
||||
|
||||
public interface IBloodAltar {
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package WayofTime.alchemicalWizardry.api.iface;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.enumeration.EnumAltarComponent;
|
||||
|
||||
public interface IAltarComponent {
|
||||
|
||||
EnumAltarComponent getType(int meta);
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package WayofTime.alchemicalWizardry.api.enumeration;
|
||||
package WayofTime.alchemicalWizardry.api.ritual;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum EnumStoneType implements IStringSerializable {
|
||||
public enum EnumRuneType implements IStringSerializable {
|
||||
|
||||
BLANK,
|
||||
WATER,
|
||||
|
@ -24,7 +24,7 @@ public enum EnumStoneType implements IStringSerializable {
|
|||
return this.toString();
|
||||
}
|
||||
|
||||
public static EnumStoneType byMetadata(int meta) {
|
||||
public static EnumRuneType byMetadata(int meta) {
|
||||
if (meta < 0 || meta >= values().length)
|
||||
meta = 0;
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package WayofTime.alchemicalWizardry.api.ritual;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.ritual.LocalRitualStorage;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IMasterRitualStone {
|
||||
|
||||
void performRitual(World world, BlockPos pos, String ritualID);
|
||||
|
||||
String getOwner();
|
||||
|
||||
void setCooldown(int cooldown);
|
||||
|
||||
int getCooldown();
|
||||
|
||||
void setActive(boolean active);
|
||||
|
||||
EnumFacing getDirection();
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getPos();
|
||||
|
||||
NBTTagCompound getCustomRitualTag();
|
||||
|
||||
void setCustomRitualTag(NBTTagCompound tag);
|
||||
|
||||
boolean areTanksEmpty();
|
||||
|
||||
int getRunningTime();
|
||||
|
||||
LocalRitualStorage getLocalStorage();
|
||||
|
||||
void setLocalStorage(LocalRitualStorage storage);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package WayofTime.alchemicalWizardry.api.ritual;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IRitualStone {
|
||||
|
||||
boolean isRuneType(World world, BlockPos pos, int meta, EnumRuneType runeType);
|
||||
|
||||
interface Tile {
|
||||
boolean isRuneType(EnumRuneType runeType);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package WayofTime.alchemicalWizardry.api.ritual;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.NBTHolder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
/**
|
||||
* This class is used to pass ritual-specific data into the RitualEffect from the containing Master Ritual Stone. This is basically used as auxiliary storage,
|
||||
* for when simply storing to NBT becomes... difficult.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class LocalRitualStorage {
|
||||
|
||||
private BlockPos pos;
|
||||
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
tagCompound.setInteger(NBTHolder.NBT_COORDX, pos.getX());
|
||||
tagCompound.setInteger(NBTHolder.NBT_COORDY, pos.getY());
|
||||
tagCompound.setInteger(NBTHolder.NBT_COORDZ, pos.getZ());
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
this.pos = new BlockPos(tagCompound.getInteger(NBTHolder.NBT_COORDX), tagCompound.getInteger(NBTHolder.NBT_COORDY), tagCompound.getInteger(NBTHolder.NBT_COORDZ));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package WayofTime.alchemicalWizardry.api.ritual;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class Ritual {
|
||||
|
||||
private final String name;
|
||||
private final int crystalLevel;
|
||||
private final int activationCost;
|
||||
private final RitualEffect ritualEffect;
|
||||
private final RitualRenderer renderer;
|
||||
|
||||
public Ritual(String name, int crystalLevel, int activationCost, RitualEffect ritualEffect) {
|
||||
this(name, crystalLevel, activationCost, ritualEffect, null);
|
||||
}
|
||||
|
||||
public ArrayList<RitualComponent> getComponents() {
|
||||
return this.getRitualEffect().getComponents();
|
||||
}
|
||||
|
||||
public void performEffect(IMasterRitualStone masterRitualStone) {
|
||||
if (ritualEffect != null && RitualRegistry.ritualEnabled(this))
|
||||
ritualEffect.performEffect(masterRitualStone);
|
||||
}
|
||||
|
||||
public boolean startRitual(IMasterRitualStone masterRitualStone, EntityPlayer player) {
|
||||
return ritualEffect != null && RitualRegistry.ritualEnabled(this) && ritualEffect.startRitual(masterRitualStone, player);
|
||||
}
|
||||
|
||||
public void onBreak(IMasterRitualStone masterRitualStone, BreakType breakType) {
|
||||
if (ritualEffect != null && RitualRegistry.ritualEnabled(this))
|
||||
ritualEffect.onRitualBroken(masterRitualStone, breakType);
|
||||
}
|
||||
|
||||
public enum BreakType {
|
||||
REDSTONE,
|
||||
BREAK_MRS,
|
||||
BREAK_STONE,
|
||||
ACTIVATE,
|
||||
DEACTIVATE,
|
||||
EXPLOSION,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package WayofTime.alchemicalWizardry.api.ritual;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class RitualComponent {
|
||||
|
||||
private final BlockPos offset;
|
||||
private final EnumRuneType runeType;
|
||||
|
||||
public int getX(EnumFacing direction) {
|
||||
switch (direction) {
|
||||
case EAST:
|
||||
return -this.getOffset().getZ();
|
||||
case SOUTH:
|
||||
return -this.getOffset().getX();
|
||||
case WEST:
|
||||
return this.getOffset().getZ();
|
||||
default:
|
||||
return this.getOffset().getX();
|
||||
}
|
||||
}
|
||||
|
||||
public int getZ(EnumFacing direction) {
|
||||
switch (direction) {
|
||||
case EAST:
|
||||
return this.getOffset().getX();
|
||||
case SOUTH:
|
||||
return -this.getOffset().getZ();
|
||||
case WEST:
|
||||
return -this.getOffset().getX();
|
||||
default:
|
||||
return this.getOffset().getZ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
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();
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
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;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class RitualRenderer {
|
||||
|
||||
public abstract void renderAt(IMasterRitualStone masterRitualStone, double x, double y, double z);
|
||||
|
||||
protected void bindTexture(ResourceLocation resourceLocation) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation);
|
||||
}
|
||||
}
|
|
@ -18,12 +18,12 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockRitualHome extends Block {
|
||||
public class BlockRitualController extends Block {
|
||||
|
||||
public static final String[] names = { "master", "imperfect" };
|
||||
public static final PropertyInteger META = PropertyInteger.create("meta", 0, names.length - 1);
|
||||
|
||||
public BlockRitualHome() {
|
||||
public BlockRitualController() {
|
||||
super(Material.rock);
|
||||
|
||||
setUnlocalizedName(AlchemicalWizardry.MODID + ".stone.ritual.");
|
|
@ -1,6 +1,6 @@
|
|||
package WayofTime.alchemicalWizardry.item.block;
|
||||
|
||||
import WayofTime.alchemicalWizardry.block.BlockRitualHome;
|
||||
import WayofTime.alchemicalWizardry.block.BlockRitualController;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -15,7 +15,7 @@ public class ItemBlockRitualHome extends ItemBlock {
|
|||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
return super.getUnlocalizedName(stack) + BlockRitualHome.names[stack.getItemDamage()];
|
||||
return super.getUnlocalizedName(stack) + BlockRitualController.names[stack.getItemDamage()];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package WayofTime.alchemicalWizardry.item.sigil;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.iface.IBloodAltar;
|
||||
import WayofTime.alchemicalWizardry.api.altar.IBloodAltar;
|
||||
import WayofTime.alchemicalWizardry.api.util.helper.BindableHelper;
|
||||
import WayofTime.alchemicalWizardry.api.util.helper.NetworkHelper;
|
||||
import WayofTime.alchemicalWizardry.util.ChatUtil;
|
||||
|
|
|
@ -4,14 +4,11 @@ import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
|||
import WayofTime.alchemicalWizardry.ConfigHandler;
|
||||
import WayofTime.alchemicalWizardry.block.BlockAltar;
|
||||
import WayofTime.alchemicalWizardry.block.BlockLifeEssence;
|
||||
import WayofTime.alchemicalWizardry.block.BlockRitualHome;
|
||||
import WayofTime.alchemicalWizardry.block.BlockRitualController;
|
||||
import WayofTime.alchemicalWizardry.item.block.ItemBlockRitualHome;
|
||||
import WayofTime.alchemicalWizardry.util.helper.InventoryRenderHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
|
@ -31,7 +28,7 @@ public class ModBlocks {
|
|||
lifeEssence = registerBlock(new BlockLifeEssence());
|
||||
|
||||
altar = registerBlock(new BlockAltar());
|
||||
ritualStone = registerBlock(new BlockRitualHome(), ItemBlockRitualHome.class);
|
||||
ritualStone = registerBlock(new BlockRitualController(), ItemBlockRitualHome.class);
|
||||
|
||||
initTiles();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"forge_marker": 1,
|
||||
"defaults": {
|
||||
"textures": {
|
||||
"all": "alchemicalwizardry:blocks/MasterRitualStone"
|
||||
},
|
||||
"model": "cube_all",
|
||||
"uvlock": true
|
||||
},
|
||||
"variants": {
|
||||
"meta": {
|
||||
"0": {
|
||||
"textures": {
|
||||
"all": "alchemicalwizardry:blocks/MasterRitualStone"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"textures": {
|
||||
"all": "alchemicalwizardry:blocks/ImperfectRitualStone"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"variants": {
|
||||
"meta=0": { "model": "alchemicalwizardry:BlockRitualHome0" },
|
||||
"meta=1": { "model": "alchemicalwizardry:BlockRitualHome1" }
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"parent": "alchemicalwizardry:block/BlockRitualHome0",
|
||||
"parent": "alchemicalwizardry:block/BlockRitualController0",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"parent": "alchemicalwizardry:block/BlockRitualHome1",
|
||||
"parent": "alchemicalwizardry:block/BlockRitualController1",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ 10, -45, 170 ],
|
Loading…
Reference in a new issue