Joshie comment!

This commit is contained in:
WayofTime 2014-06-02 15:16:36 -04:00
parent 1c0deadfc6
commit ac943e9d38
753 changed files with 8715 additions and 1184 deletions

View file

@ -0,0 +1,79 @@
package WayofTime.alchemicalWizardry.api.alchemy;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
public class AlchemicalPotionCreationHandler
{
public static ArrayList<AlchemyPotionHandlerComponent> registeredPotionEffects = new ArrayList();
public static void addPotion(ItemStack itemStack, int potionID, int tickDuration)
{
registeredPotionEffects.add(new AlchemyPotionHandlerComponent(itemStack, potionID, tickDuration));
}
public static int getPotionIDForStack(ItemStack itemStack)
{
for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects)
{
if (aphc.compareItemStack(itemStack))
{
return aphc.getPotionID();
}
}
return -1;
}
public static int getPotionTickDurationForStack(ItemStack itemStack)
{
{
for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects)
{
if (aphc.compareItemStack(itemStack))
{
return aphc.getTickDuration();
}
}
return -1;
}
}
public static boolean containsRegisteredPotionIngredient(ItemStack[] stackList)
{
for (ItemStack is : stackList)
{
for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects)
{
if (aphc.compareItemStack(is))
{
return true;
}
}
}
return false;
}
public static int getRegisteredPotionIngredientPosition(ItemStack[] stackList)
{
int i = 0;
for (ItemStack is : stackList)
{
for (AlchemyPotionHandlerComponent aphc : registeredPotionEffects)
{
if (aphc.compareItemStack(is))
{
return i;
}
}
i++;
}
return -1;
}
}

View file

@ -0,0 +1,52 @@
package WayofTime.alchemicalWizardry.api.alchemy;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class AlchemyPotionHandlerComponent
{
private ItemStack itemStack;
private int potionID;
private int tickDuration;
public AlchemyPotionHandlerComponent(ItemStack itemStack, int potionID, int tickDuration)
{
this.itemStack = itemStack;
this.potionID = potionID;
this.tickDuration = tickDuration;
}
public boolean compareItemStack(ItemStack comparedStack)
{
if (comparedStack != null && itemStack != null)
{
if (comparedStack.getItem() instanceof ItemBlock)
{
if (itemStack.getItem() instanceof ItemBlock)
{
return comparedStack.getItem().equals(itemStack.getItem()) && comparedStack.getItemDamage() == itemStack.getItemDamage();
}
} else if (!(itemStack.getItem() instanceof ItemBlock))
{
return comparedStack.getItem().equals(itemStack.getItem()) && comparedStack.getItemDamage() == itemStack.getItemDamage();
}
}
return false;
}
public ItemStack getItemStack()
{
return itemStack;
}
public int getPotionID()
{
return this.potionID;
}
public int getTickDuration()
{
return this.tickDuration;
}
}

View file

@ -0,0 +1,76 @@
package WayofTime.alchemicalWizardry.api.alchemy;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
public class AlchemyPotionHelper
{
private int potionID;
private int tickDuration;
private int concentration;
private int durationFactor;
public AlchemyPotionHelper(int potionID, int tickDuration, int concentration, int durationFactor)
{
this.potionID = potionID;
this.tickDuration = tickDuration;
this.concentration = concentration;
this.durationFactor = durationFactor;
}
public void setConcentration(int concentration)
{
this.concentration = concentration;
}
public void setDurationFactor(int durationFactor)
{
this.durationFactor = durationFactor;
}
public int getPotionID()
{
return this.potionID;
}
public int getTickDuration()
{
return this.tickDuration;
}
public int getConcentration()
{
return this.concentration;
}
public int getdurationFactor()
{
return this.durationFactor;
}
public PotionEffect getPotionEffect()
{
if (potionID == Potion.heal.id || potionID == Potion.harm.id)
{
return (new PotionEffect(potionID, 1, concentration));
}
return (new PotionEffect(potionID, (int) (tickDuration * Math.pow(0.5f, concentration) * Math.pow(8.0f / 3.0f, durationFactor)), concentration));
}
public static AlchemyPotionHelper readEffectFromNBT(NBTTagCompound tagCompound)
{
return new AlchemyPotionHelper(tagCompound.getInteger("potionID"), tagCompound.getInteger("tickDuration"), tagCompound.getInteger("concentration"), tagCompound.getInteger("durationFactor"));
}
public static NBTTagCompound setEffectToNBT(AlchemyPotionHelper aph)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setInteger("potionID", aph.getPotionID());
tagCompound.setInteger("tickDuration", aph.getTickDuration());
tagCompound.setInteger("concentration", aph.getConcentration());
tagCompound.setInteger("durationFactor", aph.getdurationFactor());
return tagCompound;
}
}

View file

@ -0,0 +1,143 @@
package WayofTime.alchemicalWizardry.api.alchemy;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class AlchemyRecipe
{
private ItemStack output;
private ItemStack[] recipe;
private int bloodOrbLevel;
private int amountNeeded;
public AlchemyRecipe(ItemStack output, int amountNeeded, ItemStack[] recipe, int bloodOrbLevel)
{
this.output = output;
this.recipe = recipe;
this.amountNeeded = amountNeeded;
this.bloodOrbLevel = bloodOrbLevel;
}
public boolean doesRecipeMatch(ItemStack[] items, int slottedBloodOrbLevel)
{
if (slottedBloodOrbLevel < bloodOrbLevel)
{
return false;
}
ItemStack[] recipe = new ItemStack[5];
if (items.length < 5)
{
return false;
}
if (this.recipe.length != 5)
{
ItemStack[] newRecipe = new ItemStack[5];
for (int i = 0; i < 5; i++)
{
if (i + 1 > this.recipe.length)
{
newRecipe[i] = null;
} else
{
newRecipe[i] = this.recipe[i];
}
}
recipe = newRecipe;
} else
{
recipe = this.recipe;
}
boolean[] checkList = new boolean[5];
for (int i = 0; i < 5; i++)
{
checkList[i] = false;
}
for (int i = 0; i < 5; i++)
{
ItemStack recipeItemStack = recipe[i];
if (recipeItemStack == null)
{
continue;
}
boolean test = false;
for (int j = 0; j < 5; j++)
{
if (checkList[j])
{
continue;
}
ItemStack checkedItemStack = items[j];
if (checkedItemStack == null)
{
continue;
}
boolean quickTest = false;
if (recipeItemStack.getItem() instanceof ItemBlock)
{
if (checkedItemStack.getItem() instanceof ItemBlock)
{
quickTest = true;
}
} else if (!(checkedItemStack.getItem() instanceof ItemBlock))
{
quickTest = true;
}
if (!quickTest)
{
continue;
}
if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage() || OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage()) && checkedItemStack.getItem()==recipeItemStack.getItem())
{
test = true;
checkList[j] = true;
break;
}
}
if (!test)
{
return false;
}
}
return true;
}
public ItemStack getResult()
{
return output.copy();
}
public int getAmountNeeded()
{
return this.amountNeeded;
}
public ItemStack[] getRecipe()
{
return this.recipe;
}
public int getOrbLevel()
{
return this.bloodOrbLevel;
}
}

View file

@ -0,0 +1,85 @@
package WayofTime.alchemicalWizardry.api.alchemy;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
public class AlchemyRecipeRegistry
{
public static List<AlchemyRecipe> recipes = new ArrayList();
public static void registerRecipe(ItemStack output, int amountNeeded, ItemStack[] recipe, int bloodOrbLevel)
{
recipes.add(new AlchemyRecipe(output, amountNeeded, recipe, bloodOrbLevel));
}
public static ItemStack getResult(ItemStack[] recipe, ItemStack bloodOrb)
{
if (bloodOrb == null)
{
return null;
}
if (!(bloodOrb.getItem() instanceof IBloodOrb))
{
return null;
}
int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel();
for (AlchemyRecipe ar : recipes)
{
if (ar.doesRecipeMatch(recipe, bloodOrbLevel))
{
return (ar.getResult());
}
}
return null;
}
public static int getAmountNeeded(ItemStack[] recipe, ItemStack bloodOrb)
{
if (bloodOrb == null)
{
return 0;
}
if (!(bloodOrb.getItem() instanceof IBloodOrb))
{
return 0;
}
int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel();
for (AlchemyRecipe ar : recipes)
{
if (ar.doesRecipeMatch(recipe, bloodOrbLevel))
{
return (ar.getAmountNeeded());
}
}
return 0;
}
public static ItemStack[] getRecipeForItemStack(ItemStack itemStack)
{
for (AlchemyRecipe ar : recipes)
{
ItemStack result = ar.getResult();
if (result != null)
{
if (result.isItemEqual(itemStack))
{
return ar.getRecipe();
}
}
}
return null;
}
}

View file

@ -0,0 +1,70 @@
package WayofTime.alchemicalWizardry.api.altarRecipeRegistry;
import net.minecraft.item.ItemStack;
public class AltarRecipe
{
public int minTier;
public int liquidRequired;
public boolean canBeFilled; //Tells the system that the item is an orb
public int consumptionRate;
public int drainRate;
public ItemStack requiredItem;
public ItemStack result;
public AltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled)
{
this.result = result;
this.requiredItem = requiredItem;
this.minTier = minTier;
this.liquidRequired = liquidRequired;
this.consumptionRate = consumptionRate;
this.drainRate = drainRate;
this.canBeFilled = canBeFilled;
}
public ItemStack getResult()
{
return this.result;
}
public ItemStack getRequiredItem()
{
return this.requiredItem;
}
public boolean doesRequiredItemMatch(ItemStack comparedStack, int tierCheck)
{
if(comparedStack == null || this.requiredItem == null)
{
return false;
}
return tierCheck>=minTier && this.requiredItem.isItemEqual(comparedStack);
}
public int getMinTier()
{
return this.minTier;
}
public int getLiquidRequired()
{
return this.liquidRequired;
}
public int getConsumptionRate()
{
return this.consumptionRate;
}
public int getDrainRate()
{
return this.drainRate;
}
public boolean getCanBeFilled()
{
return this.canBeFilled;
}
}

View file

@ -0,0 +1,60 @@
package WayofTime.alchemicalWizardry.api.altarRecipeRegistry;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
public class AltarRecipeRegistry
{
public static List<AltarRecipe> altarRecipes = new LinkedList();
public static void registerAltarRecipe(ItemStack result, ItemStack requiredItem, int minTier, int liquidRequired, int consumptionRate, int drainRate, boolean canBeFilled)
{
altarRecipes.add(new AltarRecipe(result, requiredItem, minTier, liquidRequired, consumptionRate, drainRate, canBeFilled));
}
public static void registerAltarOrbRecipe(ItemStack orbStack, int minTier, int consumptionRate)
{
registerAltarRecipe(null, orbStack, minTier, 0, consumptionRate, 0, true);
}
public static boolean isRequiredItemValid(ItemStack testItem, int currentTierAltar)
{
for(AltarRecipe recipe : altarRecipes)
{
if(recipe.doesRequiredItemMatch(testItem, currentTierAltar))
{
return true;
}
}
return false;
}
public static ItemStack getItemForItemAndTier(ItemStack testItem, int currentTierAltar)
{
for(AltarRecipe recipe : altarRecipes)
{
if(recipe.doesRequiredItemMatch(testItem, currentTierAltar))
{
return ItemStack.copyItemStack(recipe.getResult());
}
}
return null;
}
public static AltarRecipe getAltarRecipeForItemAndTier(ItemStack testItem, int currentTierAltar)
{
for(AltarRecipe recipe : altarRecipes)
{
if(recipe.doesRequiredItemMatch(testItem, currentTierAltar))
{
return recipe;
}
}
return null;
}
}

View file

@ -0,0 +1,30 @@
package WayofTime.alchemicalWizardry.api.bindingRegistry;
import net.minecraft.item.ItemStack;
public class BindingRecipe
{
public ItemStack requiredItem;
public ItemStack outputItem;
public BindingRecipe(ItemStack outputItem, ItemStack requiredItem)
{
this.requiredItem = requiredItem;
this.outputItem = outputItem;
}
public boolean doesRequiredItemMatch(ItemStack testStack)
{
if(testStack == null || this.requiredItem == null)
{
return false;
}
return this.requiredItem.isItemEqual(testStack);
}
public ItemStack getResult()
{
return this.outputItem;
}
}

View file

@ -0,0 +1,67 @@
package WayofTime.alchemicalWizardry.api.bindingRegistry;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
public class BindingRegistry
{
public static List<BindingRecipe> bindingRecipes = new LinkedList();
public static void registerRecipe(ItemStack output, ItemStack input)
{
bindingRecipes.add(new BindingRecipe(output, input));
}
public static boolean isRequiredItemValid(ItemStack testItem)
{
for(BindingRecipe recipe : bindingRecipes)
{
if(recipe.doesRequiredItemMatch(testItem))
{
return true;
}
}
return false;
}
public static ItemStack getItemForItemAndTier(ItemStack testItem)
{
for(BindingRecipe recipe : bindingRecipes)
{
if(recipe.doesRequiredItemMatch(testItem))
{
return recipe.getResult().copy();
}
}
return null;
}
public static int getIndexForItem(ItemStack testItem)
{
int i=0;
for(BindingRecipe recipe : bindingRecipes)
{
if(recipe.doesRequiredItemMatch(testItem))
{
return i;
}
i++;
}
return -1;
}
public static ItemStack getOutputForIndex(int index)
{
if(bindingRecipes.size()<=index)
{
return null;
}
return bindingRecipes.get(index).getResult();
}
}

View file

@ -0,0 +1,15 @@
package WayofTime.alchemicalWizardry.api.items.interfaces;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface ArmourUpgrade
{
//Called when the armour ticks
public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack);
public boolean isUpgrade();
public int getEnergyForTenSeconds();
}

View file

@ -0,0 +1,5 @@
package WayofTime.alchemicalWizardry.api.items.interfaces;
public interface IBindable
{
}

View file

@ -0,0 +1,8 @@
package WayofTime.alchemicalWizardry.api.items.interfaces;
public interface IBloodOrb
{
public int getMaxEssence();
public int getOrbLevel();
}

View file

@ -0,0 +1,6 @@
package WayofTime.alchemicalWizardry.api.items.interfaces;
public interface IHolding
{
}

View file

@ -0,0 +1,30 @@
package WayofTime.alchemicalWizardry.api.rituals;
import net.minecraft.world.World;
public interface IMasterRitualStone
{
public void performRitual(World world, int x, int y, int z, String ritualID);
public String getOwner();
public void setCooldown(int newCooldown);
public int getCooldown();
public void setVar1(int newVar1);
public int getVar1();
public void setActive(boolean active);
public int getDirection();
public World getWorld();
public int getXCoord();
public int getYCoord();
public int getZCoord();
}

View file

@ -0,0 +1,6 @@
package WayofTime.alchemicalWizardry.api.rituals;
public interface IRitualStone
{
}

View file

@ -0,0 +1,43 @@
package WayofTime.alchemicalWizardry.api.rituals;
public class RitualComponent
{
private int x;
private int y;
private int z;
private int stoneType;
public static final int BLANK = 0;
public static final int WATER = 1;
public static final int FIRE = 2;
public static final int EARTH = 3;
public static final int AIR = 4;
public static final int DUSK = 5;
public RitualComponent(int x, int y, int z, int stoneType)
{
this.x = x;
this.y = y;
this.z = z;
this.stoneType = stoneType;
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
public int getZ()
{
return this.z;
}
public int getStoneType()
{
return this.stoneType;
}
}

View file

@ -0,0 +1,17 @@
package WayofTime.alchemicalWizardry.api.rituals;
import java.util.List;
public abstract class RitualEffect
{
public abstract void performEffect(IMasterRitualStone ritualStone);
public abstract int getCostPerRefresh();
public int getInitialCooldown()
{
return 0;
}
public abstract List<RitualComponent> getRitualComponentList();
}

View file

@ -0,0 +1,333 @@
package WayofTime.alchemicalWizardry.api.rituals;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import scala.reflect.internal.Trees.This;
import net.minecraft.block.Block;
import net.minecraft.world.World;
public class Rituals
{
private int crystalLevel;
private int actCost;
private RitualEffect effect;
private String name;
public static Map<String,Rituals> ritualMap = new HashMap();
@Deprecated
public static List<Rituals> ritualList = new LinkedList();
public static List<String> keyList = new LinkedList();
public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name)
{
this.crystalLevel = crystalLevel;
this.actCost = actCost;
this.effect = effect;
this.name = name;
keyList.add(name);
ritualMap.put(name, this);
}
/**
* Static method to register a ritual to the Ritual Registry
* @param key Unique identification key - must be different from all others to properly register
* @param crystalLevel Crystal level required to activate
* @param actCost LP amount required to activate
* @param effect The effect that will be ticked
* @param name The name of the ritual
* @return Returns true if properly registered, or false if the key is already used
*/
public static boolean registerRitual(String key, int crystalLevel, int actCost, RitualEffect effect, String name)
{
if(ritualMap.containsKey(key))
{
return false;
}
else
{
Rituals ritual = new Rituals(crystalLevel, actCost, effect, name);
ritual.removeRitualFromList();
ritualMap.put(key, ritual);
keyList.add(key);
return true;
}
}
public void removeRitualFromList()
{
if(ritualMap.containsValue(this))
{
ritualMap.remove(ritualMap.remove(this.name));
}
if(keyList.contains(this.name))
{
keyList.remove(this.name);
}
}
public static String checkValidRitual(World world, int x, int y, int z)
{
for(String key : ritualMap.keySet())
{
if(checkRitualIsValid(world,x,y,z,key))
{
return key;
}
}
return "";
}
public static boolean canCrystalActivate(String ritualID, int crystalLevel)
{
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null)
{
return ritual.getCrystalLevel() <= crystalLevel;
}
}
return false;
}
public static boolean checkRitualIsValid(World world, int x, int y, int z, String ritualID)
{
int direction = Rituals.getDirectionOfRitual(world, x, y, z, ritualID);
if (direction != -1)
{
return true;
}
return false;
}
/**
* 1 - NORTH
* 2 - EAST
* 3 - SOUTH
* 4 - WEST
*/
public static boolean checkDirectionOfRitualValid(World world, int x, int y, int z, String ritualID, int direction)
{
List<RitualComponent> ritual = Rituals.getRitualList(ritualID);
if (ritual == null)
{
return false;
}
Block test = null;
switch (direction)
{
case 1:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x + rc.getX(), y + rc.getY(), z + rc.getZ());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x + rc.getX(), y + rc.getY(), z + rc.getZ()) != rc.getStoneType())
{
return false;
}
}
return true;
case 2:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x - rc.getZ(), y + rc.getY(), z + rc.getX());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x - rc.getZ(), y + rc.getY(), z + rc.getX()) != rc.getStoneType())
{
return false;
}
}
return true;
case 3:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x - rc.getX(), y + rc.getY(), z - rc.getZ());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x - rc.getX(), y + rc.getY(), z - rc.getZ()) != rc.getStoneType())
{
return false;
}
}
return true;
case 4:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x + rc.getZ(), y + rc.getY(), z - rc.getX());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x + rc.getZ(), y + rc.getY(), z - rc.getX()) != rc.getStoneType())
{
return false;
}
}
return true;
}
return false;
}
public static int getDirectionOfRitual(World world, int x, int y, int z, String ritualID)
{
for (int i = 1; i <= 4; i++)
{
if (Rituals.checkDirectionOfRitualValid(world, x, y, z, ritualID, i))
{
return i;
}
}
return -1;
}
public static int getCostForActivation(String ritualID)
{
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null)
{
return ritual.actCost;
}
}
return 0;
}
public static int getInitialCooldown(String ritualID)
{
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null && ritual.effect != null)
{
return ritual.effect.getInitialCooldown();
}
}
return 0;
}
public static List<RitualComponent> getRitualList(String ritualID)
{
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null)
{
return ritual.obtainComponents();
}else
{
return null;
}
}else
{
return null;
}
}
private List<RitualComponent> obtainComponents()
{
return this.effect.getRitualComponentList();
}
private int getCrystalLevel()
{
return this.crystalLevel;
}
public static void performEffect(IMasterRitualStone ritualStone, String ritualID)
{
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null && ritual.effect != null)
{
ritual.effect.performEffect(ritualStone);
}
}
}
public static int getNumberOfRituals()
{
return ritualMap.size();
}
public String getRitualName()
{
return this.name;
}
public static String getNameOfRitual(String id)
{
if(ritualMap.containsKey(id))
{
Rituals ritual = ritualMap.get(id);
if(ritual != null)
{
return ritual.getRitualName();
}
}
return "";
}
public static String getNextRitualKey(String key)
{
boolean hasSpotted = false;
String firstKey = "";
for(String str : keyList)
{
if(firstKey.equals(""))
{
firstKey = str;
}
if(hasSpotted)
{
return str;
}
if(str.equals(key))
{
hasSpotted = true;
}
}
return firstKey;
}
}

View file

@ -0,0 +1,26 @@
package WayofTime.alchemicalWizardry.api.soulNetwork;
import net.minecraft.nbt.NBTTagCompound;
public class LifeEssenceNetwork extends net.minecraft.world.WorldSavedData
{
public int currentEssence;
public LifeEssenceNetwork(String par1Str)
{
super(par1Str);
currentEssence = 0;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
currentEssence = nbttagcompound.getInteger("currentEssence");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
{
nbttagcompound.setInteger("currentEssence", currentEssence);
}
}

View file

@ -0,0 +1,228 @@
package WayofTime.alchemicalWizardry.api.soulNetwork;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
public class SoulNetworkHandler
{
public static int syphonFromNetwork(ItemStack ist, int damageToBeDone)
{
if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals("")))
{
String ownerName = ist.getTagCompound().getString("ownerName");
if (MinecraftServer.getServer() == null)
{
return 0;
}
World world = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName);
if (data == null)
{
data = new LifeEssenceNetwork(ownerName);
world.setItemData(ownerName, data);
}
if (data.currentEssence >= damageToBeDone)
{
data.currentEssence -= damageToBeDone;
data.markDirty();
return damageToBeDone;
}
}
return 0;
}
/**
* Master method used to syphon from the player's network, and will damage them accordingly if they do not have enough LP.
* Does not drain on the client side.
*
* @param ist Owned itemStack
* @param player Player using the item
* @param damageToBeDone
* @return True if server-sided, false if client-sided
*/
public static boolean syphonAndDamageFromNetwork(ItemStack ist, EntityPlayer player, int damageToBeDone)
{
if(player.worldObj.isRemote)
{
return false;
}
int amount = SoulNetworkHandler.syphonFromNetwork(ist, damageToBeDone);
hurtPlayer(player, damageToBeDone-amount);
return true;
}
public static boolean canSyphonFromOnlyNetwork(ItemStack ist, int damageToBeDone)
{
if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals("")))
{
String ownerName = ist.getTagCompound().getString("ownerName");
if (MinecraftServer.getServer() == null)
{
return false;
}
World world = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName);
if (data == null)
{
data = new LifeEssenceNetwork(ownerName);
world.setItemData(ownerName, data);
}
return data.currentEssence >= damageToBeDone;
}
return false;
}
public static int getCurrentEssence(String ownerName)
{
if (MinecraftServer.getServer() == null)
{
return 0;
}
World world = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName);
if (data == null)
{
data = new LifeEssenceNetwork(ownerName);
world.setItemData(ownerName, data);
}
return data.currentEssence;
}
public static void setCurrentEssence(String ownerName, int essence)
{
if (MinecraftServer.getServer() == null)
{
return;
}
World world = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName);
if (data == null)
{
data = new LifeEssenceNetwork(ownerName);
world.setItemData(ownerName, data);
}
data.currentEssence = essence;
data.markDirty();
}
/**
* A method to add to an owner's network up to a maximum value.
*
* @param ownerName
* @param addedEssence
* @param maximum
* @return amount added to the network
*/
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum)
{
if (MinecraftServer.getServer() == null)
{
return 0;
}
World world = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName);
if (data == null)
{
data = new LifeEssenceNetwork(ownerName);
world.setItemData(ownerName, data);
}
int currEss = data.currentEssence;
if(currEss>=maximum)
{
return 0;
}
int newEss = Math.min(maximum, currEss+addedEssence);
data.currentEssence = newEss;
return newEss-currEss;
}
public static void hurtPlayer(EntityPlayer user, int energySyphoned)
{
if (energySyphoned < 100 && energySyphoned > 0)
{
if (!user.capabilities.isCreativeMode)
{
user.setHealth((user.getHealth() - 1));
if (user.getHealth() <= 0.0005f)
{
user.onDeath(DamageSource.generic);
}
}
} else if (energySyphoned >= 100)
{
if (!user.capabilities.isCreativeMode)
{
for (int i = 0; i < ((energySyphoned + 99) / 100); i++)
{
user.setHealth((user.getHealth() - 1));
if (user.getHealth() <= 0.0005f)
{
user.onDeath(DamageSource.generic);
break;
}
}
}
}
}
public static void checkAndSetItemOwner(ItemStack item, EntityPlayer player)
{
if (item.stackTagCompound == null)
{
item.setTagCompound(new NBTTagCompound());
}
if (item.stackTagCompound.getString("ownerName").equals(""))
{
item.stackTagCompound.setString("ownerName", SoulNetworkHandler.getUsername(player));
}
}
public static void checkAndSetItemOwner(ItemStack item, String ownerName)
{
if (item.stackTagCompound == null)
{
item.setTagCompound(new NBTTagCompound());
}
if (item.stackTagCompound.getString("ownerName").equals(""))
{
item.stackTagCompound.setString("ownerName", ownerName);
}
}
public static String getUsername(EntityPlayer player)
{
return player.getDisplayName();
}
}

View file

@ -0,0 +1,21 @@
package WayofTime.alchemicalWizardry.api.summoningRegistry;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.world.World;
public abstract class SummoningHelper
{
protected int id;
public SummoningHelper(int id)
{
this.id = id;
}
public abstract EntityLivingBase getEntity(World worldObj);
public int getSummoningHelperID()
{
return id;
}
}

View file

@ -0,0 +1,70 @@
package WayofTime.alchemicalWizardry.api.summoningRegistry;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class SummoningRegistry
{
public static List<SummoningRegistryComponent> summoningList = new ArrayList();
public static void registerSummon(SummoningHelper s, ItemStack[] ring1, ItemStack[] ring2, ItemStack[] ring3, int amountUsed, int bloodOrbLevel)
{
summoningList.add(new SummoningRegistryComponent(s, ring1, ring2, ring3, amountUsed, bloodOrbLevel));
}
public static boolean isRecipeValid(int bloodOrbLevel, ItemStack[] test1, ItemStack[] test2, ItemStack[] test3)
{
for (SummoningRegistryComponent src : summoningList)
{
if (src.getBloodOrbLevel() <= bloodOrbLevel && src.compareRing(1, test1) && src.compareRing(2, test2) && src.compareRing(3, test3))
{
return true;
}
}
return false;
}
public static SummoningRegistryComponent getRegistryComponent(int bloodOrbLevel, ItemStack[] test1, ItemStack[] test2, ItemStack[] test3)
{
for (SummoningRegistryComponent src : summoningList)
{
if (src.getBloodOrbLevel() <= bloodOrbLevel && src.compareRing(1, test1) && src.compareRing(2, test2) && src.compareRing(3, test3))
{
return src;
}
}
return null;
}
public static EntityLivingBase getEntity(World worldObj, int bloodOrbLevel, ItemStack[] test1, ItemStack[] test2, ItemStack[] test3)
{
for (SummoningRegistryComponent src : summoningList)
{
if (src.getBloodOrbLevel() <= bloodOrbLevel && src.compareRing(1, test1) && src.compareRing(2, test2) && src.compareRing(3, test3))
{
return src.getEntity(worldObj);
}
}
return null;
}
public static EntityLivingBase getEntityWithID(World worldObj, int id)
{
for (SummoningRegistryComponent src : summoningList)
{
if (src.getSummoningHelperID() == id)
{
return src.getEntity(worldObj);
}
}
return null;
}
}

View file

@ -0,0 +1,231 @@
package WayofTime.alchemicalWizardry.api.summoningRegistry;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
public class SummoningRegistryComponent
{
public ItemStack[] ring1 = new ItemStack[6];
public ItemStack[] ring2 = new ItemStack[6];
public ItemStack[] ring3 = new ItemStack[6];
public SummoningHelper summoningHelper;
public int summoningCost;
public int bloodOrbLevel;
public SummoningRegistryComponent(SummoningHelper s, ItemStack[] newRing1, ItemStack[] newRing2, ItemStack[] newRing3, int amount, int bloodOrbLevel)
{
this.summoningHelper = s;
this.ring1 = newRing1;
this.ring2 = newRing2;
this.ring3 = newRing3;
this.summoningCost = amount;
this.bloodOrbLevel = bloodOrbLevel;
if (this.ring1.length != 6)
{
ItemStack[] newRecipe = new ItemStack[6];
for (int i = 0; i < 6; i++)
{
if (i + 1 > this.ring1.length)
{
newRecipe[i] = null;
} else
{
newRecipe[i] = this.ring1[i];
}
}
this.ring1 = newRecipe;
}
if (this.ring2.length != 6)
{
ItemStack[] newRecipe = new ItemStack[6];
for (int i = 0; i < 6; i++)
{
if (i + 1 > this.ring2.length)
{
newRecipe[i] = null;
} else
{
newRecipe[i] = this.ring2[i];
}
}
this.ring2 = newRecipe;
}
if (this.ring3.length != 6)
{
ItemStack[] newRecipe = new ItemStack[6];
for (int i = 0; i < 6; i++)
{
if (i + 1 > this.ring3.length)
{
newRecipe[i] = null;
} else
{
newRecipe[i] = this.ring3[i];
}
}
this.ring3 = newRecipe;
}
}
public boolean compareRing(int ring, ItemStack[] checkedRingRecipe)
{
ItemStack[] recipe;
if (checkedRingRecipe.length < 6)
{
return false;
}
switch (ring)
{
case 1:
recipe = ring1;
break;
case 2:
recipe = ring2;
break;
case 3:
recipe = ring3;
break;
default:
recipe = ring1;
}
if (recipe.length != 6)
{
ItemStack[] newRecipe = new ItemStack[6];
for (int i = 0; i < 6; i++)
{
if (i + 1 > recipe.length)
{
newRecipe[i] = null;
} else
{
newRecipe[i] = recipe[i];
}
}
recipe = newRecipe;
}
boolean[] checkList = new boolean[6];
for (int i = 0; i < 6; i++)
{
checkList[i] = false;
}
for (int i = 0; i < 6; i++)
{
ItemStack recipeItemStack = recipe[i];
if (recipeItemStack == null)
{
continue;
}
boolean test = false;
for (int j = 0; j < 6; j++)
{
if (checkList[j])
{
continue;
}
ItemStack checkedItemStack = checkedRingRecipe[j];
if (checkedItemStack == null)
{
continue;
}
boolean quickTest = false;
if (recipeItemStack.getItem() instanceof ItemBlock)
{
if (checkedItemStack.getItem() instanceof ItemBlock)
{
quickTest = true;
}
} else if (!(checkedItemStack.getItem() instanceof ItemBlock))
{
quickTest = true;
}
if (!quickTest)
{
continue;
}
if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage() || OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage()) && checkedItemStack.getItem() == recipeItemStack.getItem())
{
test = true;
checkList[j] = true;
break;
}
}
if (!test)
{
return false;
}
}
return true;
}
public int getSummoningCost()
{
return summoningCost;
}
public EntityLivingBase getEntity(World world)
{
return this.summoningHelper.getEntity(world);
}
public int getBloodOrbLevel()
{
return this.bloodOrbLevel;
}
public ItemStack[] getRingRecipeForRing(int ring)
{
switch (ring)
{
case 1:
return ring1;
case 2:
return ring2;
case 3:
return ring3;
default:
return null;
}
}
public int getSummoningHelperID()
{
return this.summoningHelper.getSummoningHelperID();
}
}