Fixed the Soul Network and made sure the majority of the items worked on it.

This commit is contained in:
WayofTime 2015-12-31 20:10:57 -05:00
parent 241c0b8dda
commit 6fb409f20f
19 changed files with 99 additions and 80 deletions

View file

@ -90,6 +90,7 @@ public class SoulNetwork extends WorldSavedData
*/
public int syphon(int syphon)
{
System.out.println("Being syphoned");
if (getCurrentEssence() >= syphon)
{
setCurrentEssence(getCurrentEssence() - syphon);
@ -101,37 +102,40 @@ public class SoulNetwork extends WorldSavedData
}
/**
* If the player exists on the server, syphon the given amount of LP from
* the player's LP network and damage for any remaining LP required.
* Syphons from the network of the owner. If not enough LP is found, it will
* instead take away from the user's health.
*
* Always returns false on the client side.
*
* @return - Whether the action should be performed.
*/
public boolean syphonAndDamage(int toSyphon)
public boolean syphonAndDamage(EntityPlayer user, int toSyphon)
{
if (getPlayer() != null)
BloodMagicAPI.getLogger().debug("The operation has requested a drain of " + toSyphon + " LP.");
if (user != null)
{
if (getPlayer().worldObj.isRemote)
if (user.worldObj.isRemote)
return false;
if (!Strings.isNullOrEmpty(mapName))
{
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, mapName, getPlayer().getHeldItem(), toSyphon);
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, mapName, null, toSyphon);
if (MinecraftForge.EVENT_BUS.post(event))
return false;
int drainAmount = syphon(event.syphon);
if (drainAmount == 0 || event.shouldDamage)
hurtPlayer(event.syphon);
if (drainAmount <= 0 || event.shouldDamage)
hurtPlayer(user, event.syphon);
return event.getResult() != Event.Result.DENY;
}
System.out.println("I got here?!?");
int amount = syphon(toSyphon);
hurtPlayer(toSyphon - amount);
hurtPlayer(user, toSyphon - amount);
return true;
}
@ -139,27 +143,26 @@ public class SoulNetwork extends WorldSavedData
return false;
}
public void hurtPlayer(float syphon)
public void hurtPlayer(EntityPlayer user, float syphon)
{
System.out.println("Called");
if (getPlayer() != null)
if (user != null)
{
if (syphon < 100 && syphon > 0)
{
if (!getPlayer().capabilities.isCreativeMode)
if (!user.capabilities.isCreativeMode)
{
getPlayer().hurtResistantTime = 0;
getPlayer().attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
user.hurtResistantTime = 0;
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
}
} else if (syphon >= 100)
{
if (!getPlayer().capabilities.isCreativeMode)
if (!user.capabilities.isCreativeMode)
{
for (int i = 0; i < ((syphon + 99) / 100); i++)
{
getPlayer().hurtResistantTime = 0;
getPlayer().attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
user.hurtResistantTime = 0;
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
}
}
}

View file

@ -5,11 +5,14 @@ import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.event.AddToNetworkEvent;
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
import WayofTime.bloodmagic.api.network.SoulNetwork;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
@ -25,13 +28,12 @@ public class NetworkHelper
*
* @param name
* - The username of the SoulNetwork owner
* @param world
* - The world
*
* @return - The SoulNetwork for the given name.
*/
public static SoulNetwork getSoulNetwork(String name, World world)
public static SoulNetwork getSoulNetwork(String name)
{
World world = DimensionManager.getWorld(0);
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, name);
if (network == null)
@ -46,17 +48,17 @@ public class NetworkHelper
/**
* @see NetworkHelper#getSoulNetwork(String, World)
*/
public static SoulNetwork getSoulNetwork(UUID uuid, World world)
public static SoulNetwork getSoulNetwork(UUID uuid)
{
return getSoulNetwork(PlayerHelper.getUsernameFromUUID(uuid), world);
return getSoulNetwork(PlayerHelper.getUsernameFromUUID(uuid));
}
/**
* @see NetworkHelper#getSoulNetwork(String, World)
*/
public static SoulNetwork getSoulNetwork(EntityPlayer player, World world)
public static SoulNetwork getSoulNetwork(EntityPlayer player)
{
return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player), world);
return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player));
}
/**
@ -82,20 +84,23 @@ public class NetworkHelper
*
* @param soulNetwork
* - SoulNetwork to syphon from
* @param user
* - User of the item.
* @param toSyphon
* - Amount of LP to syphon
*
* @return - Whether the action should be performed.
*/
public static boolean syphonAndDamage(SoulNetwork soulNetwork, int toSyphon)
public static boolean syphonAndDamage(SoulNetwork soulNetwork, EntityPlayer user, int toSyphon)
{
if (soulNetwork.getPlayer() == null)
{
soulNetwork.syphon(toSyphon);
return true;
}
return soulNetwork.syphonAndDamage(toSyphon);
// if (soulNetwork.getPlayer() == null)
// {
// soulNetwork.syphon(toSyphon);
// return true;
// }
return soulNetwork.syphonAndDamage(user, toSyphon);
}
/**
@ -103,22 +108,21 @@ public class NetworkHelper
*
* @param stack
* - ItemStack in the Container.
* @param world
* - The world the Container is in
* @param toSyphon
* - Amount of LP to syphon
*
* @return - If the syphon was successful.
*/
public static boolean syphonFromContainer(ItemStack stack, World world, int toSyphon)
public static boolean syphonFromContainer(ItemStack stack, int toSyphon) //TODO: Change to a String, int?
{
System.out.println("Test");
stack = NBTHelper.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerName))
return false;
SoulNetwork network = getSoulNetwork(ownerName, world);
SoulNetwork network = getSoulNetwork(ownerName);
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, toSyphon);