Improved the API and internal workings

Update things

Fix some more things

Update once more

Refactoring and removing unnecessary null checks

Woops

Fix

Nother fix

Moar fix

Fix imports

Update ItemBindable.java
This commit is contained in:
Arcaratus 2016-04-11 19:57:23 -04:00
parent 0a2dfb4fd4
commit 3e50dd4117
28 changed files with 389 additions and 340 deletions

View file

@ -0,0 +1,15 @@
package WayofTime.bloodmagic.api.iface;
import net.minecraft.item.ItemStack;
/**
* Interface used for any item that can store LP in itself
*/
public interface IItemLPContainer
{
int getCapacity();
void setStoredLP(ItemStack stack, int lp);
int getStoredLP(ItemStack stack);
}

View file

@ -5,5 +5,5 @@ import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
public interface IMultiWillTool
{
public EnumDemonWillType getCurrentType(ItemStack stack);
EnumDemonWillType getCurrentType(ItemStack stack);
}

View file

@ -6,7 +6,7 @@ import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
public interface ISentientSwordEffectProvider
{
public boolean applyOnHitEffect(EnumDemonWillType type, ItemStack swordStack, ItemStack providerStack, EntityLivingBase attacker, EntityLivingBase target);
boolean applyOnHitEffect(EnumDemonWillType type, ItemStack swordStack, ItemStack providerStack, EntityLivingBase attacker, EntityLivingBase target);
public boolean providesEffectForWill(EnumDemonWillType type);
boolean providesEffectForWill(EnumDemonWillType type);
}

View file

@ -1,6 +1,8 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IActivatable;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
@ -18,30 +20,27 @@ import net.minecraft.world.World;
*/
public class ItemSigilToggleable extends ItemSigil implements IActivatable
{
private boolean toggleable;
public ItemSigilToggleable(int lpUsed)
{
super(lpUsed);
setToggleable();
}
public void setToggleable()
{
this.toggleable = true;
}
@Override
public boolean getActivated(ItemStack stack)
{
return stack.getItemDamage() > 0;
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
@Override
public ItemStack setActivatedState(ItemStack stack, boolean activated)
{
if (this.toggleable)
stack.setItemDamage(activated ? 1 : 0);
if (stack != null)
{
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
return stack;
}
return stack;
return null;
}
@Override

View file

@ -86,7 +86,7 @@ public class BindableHelper
* Deprecated.
*
* Now handled automatically with
* {@link WayofTime.bloodmagic.util.handler.EventHandler#interactEvent(PlayerInteractEvent)}
* {@link WayofTime.bloodmagic.util.handler.EventHandler#onInteract(PlayerInteractEvent.RightClickItem)}}
*
* @param stack
* - The ItemStack to bind
@ -105,7 +105,7 @@ public class BindableHelper
* Deprecated.
*
* Now handled automatically with
* {@link WayofTime.bloodmagic.util.handler.EventHandler#interactEvent(PlayerInteractEvent)}
* {@link WayofTime.bloodmagic.util.handler.EventHandler#onInteract(PlayerInteractEvent.RightClickItem)}}
*
* @param stack
* - The ItemStack to bind
@ -145,7 +145,7 @@ public class BindableHelper
* Deprecated.
*
* Now handled automatically with
* {@link WayofTime.bloodmagic.util.handler.EventHandler#interactEvent(PlayerInteractEvent)}
* {@link WayofTime.bloodmagic.util.handler.EventHandler#onInteract(PlayerInteractEvent.RightClickItem)}}
*
* @param stack
* - ItemStack to check

View file

@ -0,0 +1,152 @@
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import WayofTime.bloodmagic.api.iface.IItemLPContainer;
import WayofTime.bloodmagic.api.iface.IUpgradeTrainer;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourHandler;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.item.ItemUpgradeTome;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemHelper
{
// IItemLPContainer
public static class LPContainer
{
/**
* Attempts to fill an altar with the contained LP
*
* @param altar
* - The altar in question
* @param itemStack
* - The {@link IItemLPContainer} ItemStack filling the altar
* @param world
* - The world
* @param altarPos
* - The position of the altar
*
* @return Whether or not the altar was filled (or at least attempted)
*/
public static boolean tryAndFillAltar(IBloodAltar altar, ItemStack itemStack, World world, BlockPos altarPos)
{
if (itemStack.getItem() instanceof IItemLPContainer)
{
if (!altar.isActive())
{
IItemLPContainer fillable = (IItemLPContainer) itemStack.getItem();
int amount = fillable.getStoredLP(itemStack);
if (amount > 0)
{
int filledAmount = altar.fillMainTank(amount);
amount -= filledAmount;
fillable.setStoredLP(itemStack, amount);
world.notifyBlockUpdate(altarPos, world.getBlockState(altarPos), world.getBlockState(altarPos), 3);
return true;
}
}
}
return false;
}
/**
* Adds the given LP into the {@link IItemLPContainer}'s storage
*
* @param stack
* - The item in question
* @param toAdd
* - How much LP should be added to the item
* @param maxCapacity
* - The item's maximum holding capacity
*
* @return Whether or not LP was added to the item
*/
public static boolean addLPToItem(ItemStack stack, int toAdd, int maxCapacity)
{
if (stack.getItem() instanceof IItemLPContainer)
{
IItemLPContainer fillable = (IItemLPContainer) stack.getItem();
stack = NBTHelper.checkNBT(stack);
if (toAdd < 0)
toAdd = 0;
if (toAdd > maxCapacity)
toAdd = maxCapacity;
fillable.setStoredLP(stack, Math.min(fillable.getStoredLP(stack) + toAdd, maxCapacity));
return true;
}
return false;
}
}
public static class LivingUpgrades
{
public static LivingArmourUpgrade getUpgrade(ItemStack stack)
{
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer)
{
String key = getKey(stack);
int level = getLevel(stack);
return LivingArmourHandler.generateUpgradeFromKey(key, level);
}
return null;
}
public static void setKey(ItemStack stack, String key)
{
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer)
{
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
tag.setString("key", key);
}
}
public static String getKey(ItemStack stack)
{
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer)
{
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
return tag.getString("key");
}
return "";
}
public static void setLevel(ItemStack stack, int level)
{
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer)
{
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
tag.setInteger("level", level);
}
}
public static int getLevel(ItemStack stack)
{
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer)
{
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
return tag.getInteger("level");
}
return 0;
}
}
}

View file

@ -25,25 +25,25 @@ public class NetworkHelper
/**
* Gets the SoulNetwork for the player.
*
* @param name
* - The name of the SoulNetwork owner - this is UUID.toString().
* @param uuid
* - The UUID of the SoulNetwork owner - this is UUID.toString().
*
* @return - The SoulNetwork for the given name.
*/
public static SoulNetwork getSoulNetwork(String name)
public static SoulNetwork getSoulNetwork(String uuid)
{
World world = DimensionManager.getWorld(0);
if (world == null || world.getMapStorage() == null) //Hack-ish way to fix the lava crystal.
{
return new SoulNetwork(name);
return new SoulNetwork(uuid);
}
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, name);
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, uuid);
if (network == null)
{
network = new SoulNetwork(name);
world.getMapStorage().setData(name, network);
network = new SoulNetwork(uuid);
world.getMapStorage().setData(uuid, network);
}
return network;

View file

@ -1,16 +1,12 @@
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.Constants;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.UsernameCache;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.FMLCommonHandler;
@ -73,6 +69,14 @@ public class PlayerHelper
return stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
}
/**
* Checks whether or not the given player is an "actual" player
*
* @param player
* - The player in question
*
* @return If the player is fake or not
*/
public static boolean isFakePlayer(EntityPlayer player)
{
return player != null && (player instanceof FakePlayer || knownFakePlayers.contains(player.getClass().getCanonicalName()));

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import WayofTime.bloodmagic.registry.ModPotions;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
@ -42,6 +43,14 @@ public class PlayerSacrificeHelper
return true;
}
/**
* Sacrifices a player's health while the player is under the influence of incense
*
* @param player
* - The player sacrificing
*
* @return Whether or not the health sacrificing succeeded
*/
public static boolean sacrificePlayerHealth(EntityPlayer player)
{
if (player.isPotionActive(soulFrayId))
@ -79,17 +88,24 @@ public class PlayerSacrificeHelper
return 1 + amount * scalingOfSacrifice;
}
public static boolean findAndFillAltar(World world, EntityPlayer player, int amount)
/**
* Finds the nearest {@link IBloodAltar} and attempts to fill it
*
* @param world
* - The world
* @param sacrificingEntity
* - The entity having the sacrifice done on (can be {@link EntityPlayer} for self-sacrifice)
* @param amount
* - The amount of which the altar should be filled
*
* @return Whether the altar is found and (attempted) filled
*/
public static boolean findAndFillAltar(World world, EntityLivingBase sacrificingEntity, int amount)
{
int posX = (int) Math.round(player.posX - 0.5f);
int posY = (int) player.posY;
int posZ = (int) Math.round(player.posZ - 0.5f);
IBloodAltar altarEntity = getAltar(world, new BlockPos(posX, posY, posZ));
IBloodAltar altarEntity = getAltar(world, sacrificingEntity.getPosition());
if (altarEntity == null)
{
return false;
}
altarEntity.sacrificialDaggerCall(amount, false);
altarEntity.startCycle();
@ -97,6 +113,16 @@ public class PlayerSacrificeHelper
return true;
}
/**
* Gets the nearest {@link IBloodAltar}
*
* @param world
* - The world
* @param blockPos
* - The position of where the check should be in (in a 2 block radius from this)
*
* @return The nearest altar, if no altar is found, then this will return null
*/
public static IBloodAltar getAltar(World world, BlockPos blockPos)
{
TileEntity tileEntity;
@ -107,7 +133,7 @@ public class PlayerSacrificeHelper
{
for (int k = -2; k <= 1; k++)
{
tileEntity = world.getTileEntity(new BlockPos(i + blockPos.getX(), k + blockPos.getY(), j + blockPos.getZ()));
tileEntity = world.getTileEntity(blockPos.add(i, j, k));
if (tileEntity instanceof IBloodAltar)
{