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

The following examples show how to use net.minecraft.world.World#setItemData() . 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: ItemEmptyWirelessMap.java    From WirelessRedstone with 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
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 11
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;
}