2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.util;
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2015-12-02 16:02:18 -08:00
|
|
|
import net.minecraft.block.Block;
|
2015-11-12 13:05:23 -08:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-12-02 16:02:18 -08:00
|
|
|
import net.minecraft.init.Blocks;
|
2015-11-12 13:05:23 -08:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-12-23 20:19:06 -05:00
|
|
|
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
|
|
|
|
import WayofTime.bloodmagic.registry.ModBlocks;
|
|
|
|
import WayofTime.bloodmagic.tile.TileInventory;
|
2015-11-12 13:05:23 -08:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class Utils
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public static boolean isInteger(String integer)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
Integer.parseInt(integer);
|
2015-12-30 15:34:40 -05:00
|
|
|
} catch (NumberFormatException e)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
return false;
|
2015-12-30 15:34:40 -05:00
|
|
|
} catch (NullPointerException e)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// only got here if we didn't return false
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-12 13:05:23 -08:00
|
|
|
|
|
|
|
/**
|
2015-12-30 15:34:40 -05:00
|
|
|
* Used for inserting an ItemStack with a stacksize of 1 to a tile's
|
|
|
|
* inventory at slot 0. Returns {@code true} if the ItemStack is inserted,
|
|
|
|
* {@code false} otherwise
|
|
|
|
*
|
2015-11-12 13:05:23 -08:00
|
|
|
* EG: Block Altar
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
|
|
|
* @param tile
|
|
|
|
* - The {@link TileInventory} to input the item to
|
|
|
|
* @param player
|
|
|
|
* - The player to take the item from.
|
2015-11-12 13:05:23 -08:00
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player)
|
|
|
|
{
|
2015-12-23 20:19:06 -05:00
|
|
|
return insertItemToTile(tile, player, 0);
|
|
|
|
}
|
2015-12-30 15:34:40 -05:00
|
|
|
|
|
|
|
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player, int slot)
|
|
|
|
{
|
|
|
|
if (tile.getStackInSlot(slot) == null && player.getHeldItem() != null)
|
|
|
|
{
|
2015-11-12 13:05:23 -08:00
|
|
|
ItemStack input = player.getHeldItem().copy();
|
|
|
|
input.stackSize = 1;
|
|
|
|
player.getHeldItem().stackSize--;
|
2015-12-23 20:19:06 -05:00
|
|
|
tile.setInventorySlotContents(slot, input);
|
2015-11-27 20:15:19 -05:00
|
|
|
return true;
|
2015-12-30 15:34:40 -05:00
|
|
|
} else if (tile.getStackInSlot(slot) != null && player.getHeldItem() == null)
|
|
|
|
{
|
|
|
|
if (!tile.getWorld().isRemote)
|
|
|
|
{
|
2015-12-23 20:19:06 -05:00
|
|
|
EntityItem invItem = new EntityItem(tile.getWorld(), player.posX, player.posY + 0.25, player.posZ, tile.getStackInSlot(slot));
|
2015-11-12 13:05:23 -08:00
|
|
|
tile.getWorld().spawnEntityInWorld(invItem);
|
|
|
|
}
|
|
|
|
tile.clear();
|
2015-11-27 20:15:19 -05:00
|
|
|
return false;
|
2015-11-12 13:05:23 -08:00
|
|
|
}
|
2015-11-27 20:15:19 -05:00
|
|
|
|
|
|
|
return false;
|
2015-11-12 13:05:23 -08:00
|
|
|
}
|
2015-12-02 16:02:18 -08:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public static Block getBlockForComponent(EnumAltarComponent component)
|
|
|
|
{
|
|
|
|
switch (component)
|
|
|
|
{
|
|
|
|
case GLOWSTONE:
|
|
|
|
return Blocks.glowstone;
|
|
|
|
case BLOODSTONE:
|
|
|
|
return ModBlocks.bloodStoneBrick;
|
|
|
|
case BEACON:
|
|
|
|
return Blocks.beacon;
|
|
|
|
case BLOODRUNE:
|
|
|
|
return ModBlocks.bloodRune;
|
|
|
|
case CRYSTAL:
|
|
|
|
return ModBlocks.crystal;
|
|
|
|
case NOTAIR:
|
|
|
|
return Blocks.stonebrick;
|
|
|
|
default:
|
|
|
|
return Blocks.air;
|
2015-12-02 16:02:18 -08:00
|
|
|
}
|
|
|
|
}
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|