Added AddToNetworkEvent
This commit is contained in:
parent
369ca6440f
commit
8ac6cc76d8
|
@ -0,0 +1,38 @@
|
|||
package WayofTime.alchemicalWizardry.api.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
@Cancelable
|
||||
public class AddToNetworkEvent extends Event
|
||||
{
|
||||
public String ownerNetwork;
|
||||
public int addedAmount;
|
||||
public int maximum;
|
||||
|
||||
/**
|
||||
* This event is called whenever the network is added to. If cancelled, no LP will be drained from the source. If result is set to Result.DENY,
|
||||
* the LP will still be drained but the soul network will not be added to.
|
||||
*
|
||||
* @param ownerNetwork Key used for the soul network
|
||||
* @param addedAmount Amount added
|
||||
* @param maximum Ceiling that the network can add to
|
||||
*/
|
||||
public AddToNetworkEvent(String ownerNetwork, int addedAmount, int maximum)
|
||||
{
|
||||
super();
|
||||
this.ownerNetwork = ownerNetwork;
|
||||
this.addedAmount = addedAmount;
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
public String getOwnerNetwork()
|
||||
{
|
||||
return this.ownerNetwork;
|
||||
}
|
||||
|
||||
public int getAddedAmount()
|
||||
{
|
||||
return this.addedAmount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package WayofTime.alchemicalWizardry.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class PlayerAddToNetworkEvent extends AddToNetworkEvent
|
||||
{
|
||||
public final EntityPlayer player;
|
||||
public ItemStack itemStack;
|
||||
public PlayerAddToNetworkEvent(EntityPlayer player, ItemStack itemStack, String ownerNetwork, int addedAmount, int maximum)
|
||||
{
|
||||
super(ownerNetwork, addedAmount, maximum);
|
||||
this.player = player;
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import WayofTime.alchemicalWizardry.api.event.AddToNetworkEvent;
|
||||
import WayofTime.alchemicalWizardry.api.event.ItemBindEvent;
|
||||
import WayofTime.alchemicalWizardry.api.event.ItemDrainNetworkEvent;
|
||||
|
||||
|
@ -207,29 +208,39 @@ public class SoulNetworkHandler
|
|||
*/
|
||||
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum)
|
||||
{
|
||||
AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MinecraftServer.getServer() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, ownerName);
|
||||
LifeEssenceNetwork data = (LifeEssenceNetwork) world.loadItemData(LifeEssenceNetwork.class, event.ownerNetwork);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
data = new LifeEssenceNetwork(ownerName);
|
||||
world.setItemData(ownerName, data);
|
||||
data = new LifeEssenceNetwork(event.ownerNetwork);
|
||||
world.setItemData(event.ownerNetwork, data);
|
||||
}
|
||||
|
||||
int currEss = data.currentEssence;
|
||||
|
||||
if (currEss >= maximum)
|
||||
if (currEss >= event.maximum)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int newEss = Math.min(maximum, currEss + addedEssence);
|
||||
data.currentEssence = newEss;
|
||||
int newEss = Math.min(event.maximum, currEss + event.addedAmount);
|
||||
if(event.getResult() != Event.Result.DENY)
|
||||
{
|
||||
data.currentEssence = newEss;
|
||||
}
|
||||
|
||||
return newEss - currEss;
|
||||
}
|
||||
|
|
|
@ -110,17 +110,11 @@ public class SigilOfTheFastMiner extends EnergyItems implements ArmourUpgrade
|
|||
NBTTagCompound tag = par1ItemStack.stackTagCompound;
|
||||
tag.setBoolean("isActive", !(tag.getBoolean("isActive")));
|
||||
|
||||
if (tag.getBoolean("isActive"))
|
||||
if (tag.getBoolean("isActive") && EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
||||
{
|
||||
par1ItemStack.setItemDamage(1);
|
||||
tag.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 200);
|
||||
par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 2, 1, true));
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
if (!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
||||
{
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
par1ItemStack.setItemDamage(par1ItemStack.getMaxDamage());
|
||||
|
@ -155,6 +149,7 @@ public class SigilOfTheFastMiner extends EnergyItems implements ArmourUpgrade
|
|||
{
|
||||
if (!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
||||
{
|
||||
par1ItemStack.stackTagCompound.setBoolean("isActive", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,17 +109,11 @@ public class SigilOfWind extends EnergyItems implements ArmourUpgrade
|
|||
NBTTagCompound tag = par1ItemStack.stackTagCompound;
|
||||
tag.setBoolean("isActive", !(tag.getBoolean("isActive")));
|
||||
|
||||
if (tag.getBoolean("isActive"))
|
||||
if (tag.getBoolean("isActive") && EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
||||
{
|
||||
par1ItemStack.setItemDamage(1);
|
||||
tag.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 200);
|
||||
par3EntityPlayer.addPotionEffect(new PotionEffect(AlchemicalWizardry.customPotionProjProt.id, 2, 1));
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
if (!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
||||
{
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
par1ItemStack.setItemDamage(par1ItemStack.getMaxDamage());
|
||||
|
@ -154,6 +148,7 @@ public class SigilOfWind extends EnergyItems implements ArmourUpgrade
|
|||
{
|
||||
if (!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
||||
{
|
||||
par1ItemStack.stackTagCompound.setBoolean("isActive", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue