Java Code Examples for net.minecraft.world.World#loadItemData()

The following examples show how to use net.minecraft.world.World#loadItemData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoulNetworkHandler.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
public static int syphonFromNetwork(String ownerName, int damageToBeDone)
{
    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;
}
 
Example 2
Source File: SoulNetworkHandler.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
public static boolean canSyphonFromOnlyNetwork(String ownerName, int damageToBeDone)
{
    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;
}
 
Example 3
Source File: SoulNetworkHandler.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: SoulNetworkHandler.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 5
Source File: SoulNetworkHandler.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: SoulNetworkHandler.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: SoulNetworkHandler.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 8
Source File: SoulNetworkHandler.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: SoulNetworkHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: SoulNetworkHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}