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

The following examples show how to use net.minecraft.world.World#setItemData() . 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 want to check out the right sidebar which shows the related API usage.
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
Source Project: WirelessRedstone   File: ItemEmptyWirelessMap.java    License: MIT License 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
{
    ItemStack itemstack1 = new ItemStack(WirelessRedstoneAddons.wirelessMap, 1, p_77659_2_.getUniqueDataId("map"));
    String s = "map_" + itemstack1.getItemDamage();
    MapData mapdata = new MapData(s);
    p_77659_2_.setItemData(s, mapdata);
    mapdata.scale = 0;
    int i = 128 * (1 << mapdata.scale);
    mapdata.xCenter = (int)(Math.round(p_77659_3_.posX / (double)i) * (long)i);
    mapdata.zCenter = (int)(Math.round(p_77659_3_.posZ / (double)i) * (long)i);
    mapdata.dimension = p_77659_2_.provider.dimensionId;
    mapdata.markDirty();
    --p_77659_1_.stackSize;

    if (p_77659_1_.stackSize <= 0)
    {
        return itemstack1;
    }
    else
    {
        if (!p_77659_3_.inventory.addItemStackToInventory(itemstack1.copy()))
        {
            p_77659_3_.dropPlayerItemWithRandomChoice(itemstack1, false);
        }

        return p_77659_1_;
    }
}
 
Example 10
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 11
/**
 * 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;
}