Files
TinkersConstruct/src/main/java/tconstruct/tools/modifiers/TActiveOmniMod.java
T

145 lines
5.4 KiB
Java
Raw Normal View History

2014-06-04 21:44:48 -08:00
package tconstruct.tools.modifiers;
import java.util.Random;
2014-01-16 01:36:18 -05:00
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
2014-02-05 10:28:54 -05:00
import tconstruct.library.ActiveToolMod;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
2014-06-04 21:44:48 -08:00
import tconstruct.tools.TinkerTools;
2014-02-05 10:28:54 -05:00
import tconstruct.util.config.PHConstruct;
2014-06-04 21:44:48 -08:00
import tconstruct.world.TinkerWorld;
public class TActiveOmniMod extends ActiveToolMod
{
Random random = new Random();
/* Updating */
@Override
public void updateTool (ToolCore tool, ItemStack stack, World world, Entity entity)
{
if (!world.isRemote && entity instanceof EntityLivingBase && !((EntityLivingBase) entity).isSwingInProgress && stack.getTagCompound() != null)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey("Moss"))
{
int chance = tags.getInteger("Moss");
int check = world.canBlockSeeTheSky((int) entity.posX, (int) entity.posY, (int) entity.posZ) ? 350 : 1150;
if (random.nextInt(check) < chance)
{
AbilityHelper.healTool(stack, 1, (EntityLivingBase) entity, true);
}
}
}
}
/* Harvesting */
@Override
public boolean beforeBlockBreak (ToolCore tool, ItemStack stack, int x, int y, int z, EntityLivingBase entity)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
baconator(tool, stack, entity, tags);
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode)
return false;
2014-06-04 21:44:48 -08:00
TinkerTools.modLapis.midStreamModify(stack, tool);
return false;
}
/* Attacking */
@Override
public int baseAttackDamage (int earlyModDamage, int damage, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
2014-06-04 21:44:48 -08:00
TinkerTools.modLapis.midStreamModify(stack, tool);
baconator(tool, stack, player, tags);
return 0;
}
private void baconator (ToolCore tool, ItemStack stack, EntityLivingBase entity, NBTTagCompound tags)
{
int bacon = 0;
bacon += tags.getInteger("Head") == 18 ? 1 : 0;
bacon += tags.getInteger("Handle") == 18 ? 1 : 0;
bacon += tags.getInteger("Accessory") == 18 ? 1 : 0;
bacon += tags.getInteger("Extra") == 18 ? 1 : 0;
int chance = tool.getPartAmount() * 100;
if (random.nextInt(chance) < bacon)
{
if (entity instanceof EntityPlayer)
2014-06-04 21:44:48 -08:00
AbilityHelper.spawnItemAtPlayer((EntityPlayer) entity, new ItemStack(TinkerWorld.strangeFood, 1, 2));
else
2014-06-04 21:44:48 -08:00
AbilityHelper.spawnItemAtEntity(entity, new ItemStack(TinkerWorld.strangeFood, 1, 2), 0);
}
}
@Override
public int attackDamage (int modDamage, int currentDamage, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
int bonus = 0;
if (entity instanceof EntityLivingBase)
{
EnumCreatureAttribute attribute = ((EntityLivingBase) entity).getCreatureAttribute();
if (attribute == EnumCreatureAttribute.UNDEAD)
{
2014-06-04 21:44:48 -08:00
if (tool == TinkerTools.hammer)
{
int level = 2;
bonus += random.nextInt(level * 2 + 1) + level * 2;
}
if (toolTags.hasKey("ModSmite"))
{
int[] array = toolTags.getIntArray("ModSmite");
int base = array[0] / 18;
bonus += 1 + base + random.nextInt(base + 1);
}
}
if (attribute == EnumCreatureAttribute.ARTHROPOD)
{
if (toolTags.hasKey("ModAntiSpider"))
{
int[] array = toolTags.getIntArray("ModAntiSpider");
int base = array[0] / 2;
bonus += 1 + base + random.nextInt(base + 1);
}
}
}
return bonus;
}
@Override
public float knockback (float modKnockback, float currentKnockback, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
float bonus = 0f;
if (toolTags.hasKey("Knockback"))
{
float level = toolTags.getFloat("Knockback");
bonus += level;
}
return bonus;
}
2014-02-17 00:31:43 -05:00
@Override
public boolean doesCriticalHit (ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
2014-06-04 21:44:48 -08:00
if (tool == TinkerTools.cutlass && random.nextInt(10) == 0)
return true;
return false;
}
}