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

The following examples show how to use net.minecraft.world.World#loadItemData() . These examples are extracted from open source projects. 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
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
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
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
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
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
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
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
/**
 * 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
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
/**
 * 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;
}