2014-06-06 19:46:05 -08:00
|
|
|
package tconstruct.tools;
|
2013-11-19 20:57:52 -08:00
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event.Result;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.*;
|
2014-10-10 11:36:25 +02:00
|
|
|
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
2014-09-09 18:30:15 +10:00
|
|
|
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import net.minecraft.entity.*;
|
2014-10-07 22:43:06 +02:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.entity.monster.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-04-02 20:38:48 -04:00
|
|
|
import net.minecraft.entity.projectile.EntityArrow;
|
2013-12-31 16:37:46 -05:00
|
|
|
import net.minecraft.init.Items;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.item.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-11-26 22:37:08 +01:00
|
|
|
import net.minecraft.network.play.server.S14PacketEntity;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.util.*;
|
2014-10-08 22:26:54 +02:00
|
|
|
import net.minecraft.world.EnumDifficulty;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraftforge.event.entity.living.*;
|
2014-10-07 22:43:06 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraftforge.oredict.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
|
2013-07-31 13:08:18 -07:00
|
|
|
import tconstruct.TConstruct;
|
2014-07-06 22:59:44 -08:00
|
|
|
import tconstruct.armor.player.TPlayerStats;
|
2013-07-31 13:08:18 -07:00
|
|
|
import tconstruct.library.TConstructRegistry;
|
2014-12-07 20:47:33 +01:00
|
|
|
import tconstruct.library.entity.ProjectileBase;
|
2014-08-15 13:04:03 +02:00
|
|
|
import tconstruct.library.event.*;
|
2014-08-23 11:28:56 +02:00
|
|
|
import tconstruct.library.tools.*;
|
2014-06-06 19:46:05 -08:00
|
|
|
import tconstruct.util.ItemHelper;
|
2013-10-01 19:44:04 -07:00
|
|
|
import tconstruct.util.config.PHConstruct;
|
2014-11-26 22:37:08 +01:00
|
|
|
import tconstruct.util.network.MovementUpdatePacket;
|
2014-08-15 13:04:03 +02:00
|
|
|
|
2014-06-06 19:46:05 -08:00
|
|
|
public class TinkerToolEvents
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onCrafting (ItemCraftedEvent event)
|
|
|
|
|
{
|
|
|
|
|
Item item = event.crafting.getItem();
|
|
|
|
|
if (!event.player.worldObj.isRemote)
|
|
|
|
|
{
|
|
|
|
|
if (item == Item.getItemFromBlock(TinkerTools.toolStationWood))
|
|
|
|
|
{
|
2014-12-21 17:46:36 +01:00
|
|
|
if (!PHConstruct.beginnerBook)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 19:46:05 -08:00
|
|
|
TPlayerStats stats = TPlayerStats.get(event.player);
|
|
|
|
|
if (!stats.materialManual)
|
|
|
|
|
{
|
|
|
|
|
stats.materialManual = true;
|
|
|
|
|
AbilityHelper.spawnItemAtPlayer(event.player, new ItemStack(TinkerTools.manualBook, 1, 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-16 23:13:55 +01:00
|
|
|
|
|
|
|
|
// slab pattern chest
|
|
|
|
|
if(item == Item.getItemFromBlock(TinkerTools.craftingSlabWood) && event.crafting.getItemDamage() == 4) {
|
|
|
|
|
// copy over NBT
|
|
|
|
|
for(int i = 0; i < event.craftMatrix.getSizeInventory(); i++) {
|
|
|
|
|
ItemStack stack = event.craftMatrix.getStackInSlot(i);
|
|
|
|
|
if(stack == null)
|
|
|
|
|
continue;
|
|
|
|
|
// regular pattern chest
|
|
|
|
|
if(stack.getItem() == Item.getItemFromBlock(TinkerTools.toolStationWood) && stack.getItemDamage() == 5)
|
|
|
|
|
{
|
|
|
|
|
event.crafting.setTagCompound(stack.getTagCompound());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-06 19:46:05 -08:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-15 13:04:03 +02:00
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2014-09-09 18:30:15 +10:00
|
|
|
public void buildTool (ToolBuildEvent event)
|
2014-08-15 13:04:03 +02:00
|
|
|
{
|
|
|
|
|
// check if the handle is a bone
|
2014-09-09 18:30:15 +10:00
|
|
|
if (event.handleStack.getItem() == Items.bone)
|
|
|
|
|
{
|
2014-08-15 13:04:03 +02:00
|
|
|
event.handleStack = new ItemStack(TinkerTools.toolRod, 1, 5); // bone tool rod
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if the handle is a stick
|
|
|
|
|
List<ItemStack> sticks = OreDictionary.getOres("stickWood");
|
2014-09-09 18:30:15 +10:00
|
|
|
for (ItemStack stick : sticks)
|
|
|
|
|
if (OreDictionary.itemMatches(stick, event.handleStack, false))
|
|
|
|
|
{
|
2014-08-15 13:04:03 +02:00
|
|
|
event.handleStack = new ItemStack(TinkerTools.toolRod, 1, 0); // wooden tool rod
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void craftTool (ToolCraftEvent.NormalTool event)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
NBTTagCompound toolTag = event.toolTag.getCompoundTag("InfiTool");
|
2014-06-04 21:44:48 -08:00
|
|
|
if (PHConstruct.denyMattock && event.tool == TinkerTools.mattock)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
int head = toolTag.getInteger("Head");
|
|
|
|
|
int handle = toolTag.getInteger("Handle");
|
|
|
|
|
int accessory = toolTag.getInteger("Accessory");
|
|
|
|
|
|
|
|
|
|
if (!allowCrafting(head, handle, accessory))
|
|
|
|
|
{
|
|
|
|
|
event.setResult(Result.DENY);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 11:23:50 +02:00
|
|
|
// bonus modifiers
|
|
|
|
|
handlePaper(toolTag, event.tool);
|
|
|
|
|
handleThaumium(toolTag, event.tool);
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-06-04 21:44:48 -08:00
|
|
|
if (event.tool == TinkerTools.battlesign)
|
2014-04-02 20:38:48 -04:00
|
|
|
{
|
|
|
|
|
int modifiers = toolTag.getInteger("Modifiers");
|
|
|
|
|
modifiers += 1;
|
|
|
|
|
toolTag.setInteger("Modifiers", modifiers);
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
private void handlePaper (NBTTagCompound toolTag, ToolCore tool)
|
2014-09-03 11:23:50 +02:00
|
|
|
{
|
|
|
|
|
int modifiers = toolTag.getInteger("Modifiers");
|
|
|
|
|
if (toolTag.getInteger("Head") == TinkerTools.MaterialID.Paper)
|
|
|
|
|
modifiers++;
|
|
|
|
|
if (toolTag.getInteger("Handle") == TinkerTools.MaterialID.Paper)
|
|
|
|
|
modifiers++;
|
|
|
|
|
if (toolTag.getInteger("Accessory") == TinkerTools.MaterialID.Paper)
|
|
|
|
|
modifiers++;
|
|
|
|
|
if (toolTag.getInteger("Extra") == TinkerTools.MaterialID.Paper)
|
|
|
|
|
modifiers++;
|
|
|
|
|
|
|
|
|
|
// 2 part tools gain 2 modifiers for the head
|
2014-09-09 18:30:15 +10:00
|
|
|
if (tool.getPartAmount() == 2 && toolTag.getInteger("Head") == TinkerTools.MaterialID.Paper)
|
2014-09-03 11:23:50 +02:00
|
|
|
modifiers++;
|
|
|
|
|
|
|
|
|
|
toolTag.setInteger("Modifiers", modifiers);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
private void handleThaumium (NBTTagCompound toolTag, ToolCore tool)
|
2014-09-03 11:23:50 +02:00
|
|
|
{
|
|
|
|
|
// count thaumic parts
|
|
|
|
|
int thaum = 0;
|
|
|
|
|
if (toolTag.getInteger("Head") == TinkerTools.MaterialID.Thaumium)
|
|
|
|
|
thaum++;
|
|
|
|
|
if (toolTag.getInteger("Handle") == TinkerTools.MaterialID.Thaumium)
|
|
|
|
|
thaum++;
|
|
|
|
|
if (toolTag.getInteger("Accessory") == TinkerTools.MaterialID.Thaumium)
|
|
|
|
|
thaum++;
|
|
|
|
|
if (toolTag.getInteger("Extra") == TinkerTools.MaterialID.Thaumium)
|
|
|
|
|
thaum++;
|
|
|
|
|
|
|
|
|
|
// each part gives 0.5 modifiers, rounded up
|
2014-09-09 18:30:15 +10:00
|
|
|
int bonusModifiers = (int) Math.ceil((double) thaum / 2d);
|
2014-09-03 11:23:50 +02:00
|
|
|
|
|
|
|
|
// 2-part tools get 1 modifier per part
|
2014-09-09 18:30:15 +10:00
|
|
|
if (tool.getPartAmount() == 2)
|
2014-09-03 11:23:50 +02:00
|
|
|
bonusModifiers = thaum;
|
|
|
|
|
|
|
|
|
|
int modifiers = toolTag.getInteger("Modifiers");
|
|
|
|
|
modifiers += bonusModifiers;
|
|
|
|
|
toolTag.setInteger("Modifiers", modifiers);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
private boolean allowCrafting (int head, int handle, int accessory)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
int[] nonMetals = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 17 };
|
|
|
|
|
for (int i = 0; i < nonMetals.length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (head == nonMetals[i] || handle == nonMetals[i] || accessory == nonMetals[i])
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void craftPart (PartBuilderEvent.NormalPart event)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-12-26 11:03:28 +01:00
|
|
|
// bowstring
|
2014-06-04 21:44:48 -08:00
|
|
|
if (event.pattern.getItem() == TinkerTools.woodPattern && event.pattern.getItemDamage() == 23)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
ItemStack result = craftBowString(event.material);
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
event.overrideResult(new ItemStack[] { result, null });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-26 11:03:28 +01:00
|
|
|
// fletching
|
2014-06-04 21:44:48 -08:00
|
|
|
if (event.pattern.getItem() == TinkerTools.woodPattern && event.pattern.getItemDamage() == 24)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
ItemStack result = craftFletching(event.material);
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
event.overrideResult(new ItemStack[] { result, null });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
public static ItemStack craftBowString (ItemStack stack)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (stack.stackSize < 3)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
BowstringMaterial mat = (BowstringMaterial) TConstructRegistry.getCustomMaterial(stack, BowstringMaterial.class);
|
|
|
|
|
if (mat != null)
|
|
|
|
|
return mat.craftingItem.copy();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
public static ItemStack craftFletching (ItemStack stack)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
FletchingMaterial mat = (FletchingMaterial) TConstructRegistry.getCustomMaterial(stack, FletchingMaterial.class);
|
2014-08-23 11:28:56 +02:00
|
|
|
// maybe it's a leaf fletchling
|
2014-09-09 18:30:15 +10:00
|
|
|
if (mat == null)
|
2014-08-23 11:28:56 +02:00
|
|
|
mat = (FletchingMaterial) TConstructRegistry.getCustomMaterial(stack, FletchlingLeafMaterial.class);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (mat != null)
|
|
|
|
|
return mat.craftingItem.copy();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-02 20:38:48 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onAttack (LivingAttackEvent event)
|
|
|
|
|
{
|
|
|
|
|
//System.out.println("Damage: "+event.ammount);
|
|
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
|
|
|
|
//Cutlass
|
|
|
|
|
ItemStack stack = player.getCurrentEquippedItem();
|
2014-11-30 14:34:28 +01:00
|
|
|
if (stack != null && stack.getItem() == TinkerTools.battlesign)
|
2013-08-16 13:51:33 -07:00
|
|
|
{
|
2014-11-30 14:34:28 +01:00
|
|
|
// broken battlesign?
|
|
|
|
|
if(!stack.hasTagCompound() || stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Broken"))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-04-02 20:38:48 -04:00
|
|
|
DamageSource source = event.source;
|
|
|
|
|
if (!source.isUnblockable() && !source.isMagicDamage() && !source.isExplosion())
|
|
|
|
|
{
|
2014-11-26 22:37:08 +01:00
|
|
|
if (source.isProjectile())
|
2014-04-02 20:38:48 -04:00
|
|
|
{
|
2014-11-30 14:20:41 +01:00
|
|
|
Entity projectile = source.getSourceOfDamage();
|
|
|
|
|
Vec3 motion = Vec3.createVectorHelper(projectile.motionX, projectile.motionY, projectile.motionZ);
|
|
|
|
|
Vec3 look = player.getLookVec();
|
|
|
|
|
|
|
|
|
|
// this gives a factor of how much we're looking at the incoming arrow
|
|
|
|
|
double strength = -look.dotProduct(motion.normalize());
|
|
|
|
|
// we're looking away. oh no.
|
|
|
|
|
if(strength < 0.1)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-11-26 22:37:08 +01:00
|
|
|
// no damage, hooraaay
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
|
|
|
|
|
double speed = projectile.motionX*projectile.motionX + projectile.motionY*projectile.motionY + projectile.motionZ*projectile.motionZ;
|
|
|
|
|
speed = Math.sqrt(speed);
|
|
|
|
|
|
2014-11-30 14:20:41 +01:00
|
|
|
speed = (speed+2)*strength;
|
|
|
|
|
|
|
|
|
|
|
2014-11-26 22:37:08 +01:00
|
|
|
|
|
|
|
|
// now we simply set the look vector with the speed and get our new vector!
|
|
|
|
|
projectile.motionX = look.xCoord * speed;
|
|
|
|
|
projectile.motionY = look.yCoord * speed;
|
|
|
|
|
projectile.motionZ = look.zCoord * speed;
|
|
|
|
|
|
|
|
|
|
projectile.rotationYaw = (float)(Math.atan2(projectile.motionX, projectile.motionZ) * 180.0D / Math.PI);
|
|
|
|
|
projectile.rotationPitch = (float)(Math.atan2(projectile.motionY, speed) * 180.0D / Math.PI);
|
|
|
|
|
|
|
|
|
|
// send the current status to the client
|
|
|
|
|
TConstruct.packetPipeline.sendToAll(new MovementUpdatePacket(projectile));
|
|
|
|
|
|
|
|
|
|
if(projectile instanceof EntityArrow) {
|
|
|
|
|
((EntityArrow) projectile).shootingEntity = player;
|
|
|
|
|
|
|
|
|
|
// the inverse is done when the event is cancelled in arrows etc.
|
|
|
|
|
// we reverse it so it has no effect. yay
|
|
|
|
|
projectile.motionX /= -0.10000000149011612D;
|
|
|
|
|
projectile.motionY /= -0.10000000149011612D;
|
|
|
|
|
projectile.motionZ /= -0.10000000149011612D;
|
|
|
|
|
// projectile.rotationYaw -= 180.0F;
|
|
|
|
|
// projectile.prevRotationYaw -= 180.0F;
|
|
|
|
|
|
|
|
|
|
// not needed at the client since it gets the absolute values sent
|
2014-12-07 20:47:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// tinker projectiles don't check for stuff hit to prevent weird behaviour.
|
|
|
|
|
// we have to de-defuse them so the reflected projectiles can hit stuff again
|
|
|
|
|
if(projectile instanceof ProjectileBase)
|
|
|
|
|
((ProjectileBase) projectile).defused = false;
|
2014-04-02 20:38:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Entity attacker = source.getEntity();
|
2014-09-09 18:30:15 +10:00
|
|
|
if (attacker != null)
|
2014-05-27 22:57:30 -04:00
|
|
|
{
|
|
|
|
|
attacker.attackEntityFrom(DamageSource.causeThornsDamage(player), event.ammount);
|
|
|
|
|
}
|
2014-04-02 20:38:48 -04:00
|
|
|
}
|
2014-11-30 14:34:28 +01:00
|
|
|
|
|
|
|
|
// durability--
|
|
|
|
|
AbilityHelper.damageTool(stack, (int)Math.ceil(event.ammount/2f), player, false);
|
2014-04-02 20:38:48 -04:00
|
|
|
}
|
2013-08-16 13:51:33 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void onLivingDrop (LivingDropsEvent event)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-11-19 20:57:52 -08:00
|
|
|
if (event.entityLiving == null)
|
|
|
|
|
return;
|
2013-12-11 23:47:07 -05:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
if (event.recentlyHit)
|
|
|
|
|
{
|
|
|
|
|
if (event.entityLiving.getClass() == EntitySkeleton.class)
|
|
|
|
|
{
|
|
|
|
|
EntitySkeleton enemy = (EntitySkeleton) event.entityLiving;
|
|
|
|
|
|
|
|
|
|
if (event.source.damageType.equals("player"))
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
ItemStack stack = player.getCurrentEquippedItem();
|
|
|
|
|
if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore)
|
|
|
|
|
{
|
|
|
|
|
int beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading");
|
2014-06-04 21:44:48 -08:00
|
|
|
if (stack.getItem() == TinkerTools.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
2014-06-06 19:46:05 -08:00
|
|
|
if (beheading > 0 && TConstruct.random.nextInt(100) < beheading * 10)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, new ItemStack(Items.skull, 1, enemy.getSkeletonType()));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-06 19:46:05 -08:00
|
|
|
if (enemy.getSkeletonType() == 1 && TConstruct.random.nextInt(Math.max(1, 5 - event.lootingLevel)) == 0)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, new ItemStack(TinkerTools.materials, 1, 8));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.entityLiving.getClass() == EntityZombie.class)
|
|
|
|
|
{
|
|
|
|
|
EntityZombie enemy = (EntityZombie) event.entityLiving;
|
|
|
|
|
|
|
|
|
|
if (event.source.damageType.equals("player"))
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
ItemStack stack = player.getCurrentEquippedItem();
|
|
|
|
|
|
|
|
|
|
if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore)
|
|
|
|
|
{
|
|
|
|
|
int beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading");
|
2014-06-04 21:44:48 -08:00
|
|
|
if (stack != null && stack.hasTagCompound() && stack.getItem() == TinkerTools.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
2014-06-06 19:46:05 -08:00
|
|
|
if (beheading > 0 && TConstruct.random.nextInt(100) < beheading * 10)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, new ItemStack(Items.skull, 1, 2));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-25 19:48:18 -05:00
|
|
|
|
2014-06-06 19:46:05 -08:00
|
|
|
if (stack != null && stack.hasTagCompound() && stack.getItem() == TinkerTools.cleaver && TConstruct.random.nextInt(100) < 10)
|
2014-02-25 19:48:18 -05:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, new ItemStack(Items.skull, 1, 2));
|
2014-02-25 19:48:18 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.entityLiving.getClass() == EntityCreeper.class)
|
|
|
|
|
{
|
|
|
|
|
EntityCreeper enemy = (EntityCreeper) event.entityLiving;
|
|
|
|
|
|
|
|
|
|
if (event.source.damageType.equals("player"))
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
ItemStack stack = player.getCurrentEquippedItem();
|
|
|
|
|
if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore)
|
|
|
|
|
{
|
|
|
|
|
int beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading");
|
2014-06-04 21:44:48 -08:00
|
|
|
if (stack.getItem() == TinkerTools.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
2014-06-06 19:46:05 -08:00
|
|
|
if (beheading > 0 && TConstruct.random.nextInt(100) < beheading * 5)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, new ItemStack(Items.skull, 1, 4));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
|
|
|
|
|
|
|
|
|
if (PHConstruct.dropPlayerHeads)
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
ItemStack dropStack = new ItemStack(Items.skull, 1, 3);
|
2013-07-26 21:18:53 -07:00
|
|
|
NBTTagCompound nametag = new NBTTagCompound();
|
2014-01-07 15:07:07 -05:00
|
|
|
nametag.setString("SkullOwner", player.getDisplayName());
|
2014-02-04 21:21:50 -05:00
|
|
|
dropStack.setTagCompound(nametag);
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, dropStack);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (event.source.damageType.equals("player"))
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer source = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
ItemStack stack = source.getCurrentEquippedItem();
|
|
|
|
|
if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore)
|
|
|
|
|
{
|
|
|
|
|
int beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading");
|
2014-06-04 21:44:48 -08:00
|
|
|
if (stack.getItem() == TinkerTools.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
2014-06-06 19:46:05 -08:00
|
|
|
if (beheading > 0 && TConstruct.random.nextInt(100) < beheading * 50)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
ItemStack dropStack = new ItemStack(Items.skull, 1, 3);
|
2013-07-26 21:18:53 -07:00
|
|
|
NBTTagCompound nametag = new NBTTagCompound();
|
2014-01-07 15:07:07 -05:00
|
|
|
nametag.setString("SkullOwner", player.getDisplayName());
|
2014-02-04 21:21:50 -05:00
|
|
|
dropStack.setTagCompound(nametag);
|
2014-06-06 19:46:05 -08:00
|
|
|
ItemHelper.addDrops(event, dropStack);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void registerOre (OreRegisterEvent evt)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-11 23:47:07 -05:00
|
|
|
|
2014-07-31 18:09:19 +02:00
|
|
|
if (evt.Name.equals("crystalQuartz"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
TinkerTools.modAttack.addStackToMatchList(evt.Ore, 2);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-31 18:09:19 +02:00
|
|
|
else if (evt.Name.equals("crystalCertusQuartz"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
TinkerTools.modAttack.addStackToMatchList(evt.Ore, 24);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-10-07 22:43:06 +02:00
|
|
|
|
|
|
|
|
|
2014-10-08 22:26:54 +02:00
|
|
|
|
2014-10-07 22:43:06 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void damageToolsOnDeath (PlayerDropsEvent event)
|
|
|
|
|
{
|
2014-10-08 20:12:22 +02:00
|
|
|
if(!PHConstruct.deathPenality)
|
|
|
|
|
return;
|
2014-10-08 22:26:54 +02:00
|
|
|
|
|
|
|
|
EnumDifficulty difficulty = event.entityPlayer.worldObj.difficultySetting;
|
|
|
|
|
// easy and peaceful don't punish
|
|
|
|
|
if(difficulty == EnumDifficulty.PEACEFUL || difficulty == EnumDifficulty.EASY)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int punishment = 20; // normal has 5%
|
|
|
|
|
if(difficulty == EnumDifficulty.HARD)
|
|
|
|
|
punishment = 10; // hard has 10%
|
|
|
|
|
|
2014-10-10 11:36:25 +02:00
|
|
|
// check if we have to reduce it
|
|
|
|
|
// did the player live long enough to receive derp-protection?
|
|
|
|
|
// (yes, you receive protection every time you log in. we're that nice.)
|
|
|
|
|
int derp = 1;
|
|
|
|
|
if(event.entityPlayer.ticksExisted < 60*5*20 ) {
|
|
|
|
|
derp = TPlayerStats.get(event.entityPlayer).derpLevel;
|
|
|
|
|
if(derp <= 0) derp = 1;
|
|
|
|
|
punishment *= derp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean damaged = false;
|
2014-10-07 22:43:06 +02:00
|
|
|
for(EntityItem drop : event.drops)
|
|
|
|
|
{
|
|
|
|
|
// we're only interested in tools
|
|
|
|
|
if(!(drop.getEntityItem().getItem() instanceof ToolCore) || !drop.getEntityItem().hasTagCompound())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// damage tools by 10% of their total durability!
|
|
|
|
|
NBTTagCompound tags = drop.getEntityItem().getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
int dur = tags.getInteger("TotalDurability");
|
2014-10-08 22:26:54 +02:00
|
|
|
dur /= punishment;
|
2014-10-07 22:43:06 +02:00
|
|
|
|
|
|
|
|
AbilityHelper.damageTool(drop.getEntityItem(), dur, event.entityPlayer, true);
|
2014-10-10 11:36:25 +02:00
|
|
|
damaged = true;
|
2014-10-07 22:43:06 +02:00
|
|
|
}
|
2014-10-10 11:36:25 +02:00
|
|
|
|
|
|
|
|
if(damaged) {
|
|
|
|
|
derp++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// increase derplevel by 1. Minimal derp level is 1.
|
|
|
|
|
TPlayerStats.get(event.entityPlayer).derpLevel = derp+1;
|
2014-10-07 22:43:06 +02:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|