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;
|
2016-01-06 07:13:56 -05:00
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
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;
|
2016-01-06 07:13:56 -05:00
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraft.util.DamageSource;
|
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
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2016-01-01 10:52:42 -08:00
|
|
|
* @see #insertItemToTile(TileInventory, EntityPlayer, int)
|
2016-01-02 17:56:37 -05:00
|
|
|
*
|
2015-12-30 15:34:40 -05:00
|
|
|
* @param tile
|
2016-01-02 17:56:37 -05:00
|
|
|
* - The {@link TileInventory} to input the item to
|
2015-12-30 15:34:40 -05:00
|
|
|
* @param player
|
2016-01-02 17:56:37 -05:00
|
|
|
* - The player to take the item from.
|
|
|
|
*
|
|
|
|
* @return {@code true} if the ItemStack is inserted, {@code false}
|
|
|
|
* otherwise
|
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
|
|
|
|
2016-01-01 10:52:42 -08:00
|
|
|
/**
|
|
|
|
* Used for inserting an ItemStack with a stacksize of 1 to a tile's
|
|
|
|
* inventory at slot 0
|
2016-01-02 17:56:37 -05:00
|
|
|
*
|
2016-01-01 10:52:42 -08:00
|
|
|
* EG: Block Altar
|
2016-01-02 17:56:37 -05:00
|
|
|
*
|
2016-01-01 10:52:42 -08:00
|
|
|
* @param tile
|
2016-01-02 17:56:37 -05:00
|
|
|
* - The {@link TileInventory} to input the item to
|
2016-01-01 10:52:42 -08:00
|
|
|
* @param player
|
2016-01-02 17:56:37 -05:00
|
|
|
* - The player to take the item from.
|
2016-01-01 10:52:42 -08:00
|
|
|
* @param slot
|
2016-01-02 17:56:37 -05:00
|
|
|
* - The slot to attempt to insert to
|
|
|
|
*
|
|
|
|
* @return {@code true} if the ItemStack is inserted, {@code false}
|
|
|
|
* otherwise
|
2016-01-01 10:52:42 -08:00
|
|
|
*/
|
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
|
|
|
|
2016-01-01 10:52:42 -08:00
|
|
|
/**
|
|
|
|
* Gets a default block for each type of {@link EnumAltarComponent}
|
2016-01-02 17:56:37 -05:00
|
|
|
*
|
2016-01-01 10:52:42 -08:00
|
|
|
* @param component
|
2016-01-02 17:56:37 -05:00
|
|
|
* - The Component to provide a block for.
|
|
|
|
*
|
2016-01-01 10:52:42 -08:00
|
|
|
* @return The default Block for the EnumAltarComponent
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
}
|
2016-01-06 07:13:56 -05:00
|
|
|
|
|
|
|
public static float getModifiedDamage(EntityLivingBase attackedEntity, DamageSource source, float amount)
|
|
|
|
{
|
|
|
|
if (!attackedEntity.isEntityInvulnerable(source))
|
|
|
|
{
|
|
|
|
if (amount <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
amount = net.minecraftforge.common.ISpecialArmor.ArmorProperties.applyArmor(attackedEntity, attackedEntity.getInventory(), source, amount);
|
|
|
|
if (amount <= 0)
|
|
|
|
return 0;
|
|
|
|
amount = applyPotionDamageCalculations(attackedEntity, source, amount);
|
|
|
|
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float applyPotionDamageCalculations(EntityLivingBase attackedEntity, DamageSource source, float damage)
|
|
|
|
{
|
|
|
|
if (source.isDamageAbsolute())
|
|
|
|
{
|
|
|
|
return damage;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (attackedEntity.isPotionActive(Potion.resistance) && source != DamageSource.outOfWorld)
|
|
|
|
{
|
|
|
|
int i = (attackedEntity.getActivePotionEffect(Potion.resistance).getAmplifier() + 1) * 5;
|
|
|
|
int j = 25 - i;
|
|
|
|
float f = damage * (float) j;
|
|
|
|
damage = f / 25.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (damage <= 0.0F)
|
|
|
|
{
|
|
|
|
return 0.0F;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
int k = EnchantmentHelper.getEnchantmentModifierDamage(attackedEntity.getInventory(), source);
|
|
|
|
|
|
|
|
if (k > 20)
|
|
|
|
{
|
|
|
|
k = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k > 0 && k <= 20)
|
|
|
|
{
|
|
|
|
int l = 25 - k;
|
|
|
|
float f1 = damage * (float) l;
|
|
|
|
damage = f1 / 25.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|