2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.util;
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
import java.util.Random;
|
2013-11-19 20:57:52 -08:00
|
|
|
|
2014-02-05 10:28:54 -05:00
|
|
|
import mantle.blocks.BlockUtils;
|
|
|
|
|
import mantle.world.WorldHelper;
|
2013-08-01 20:54:56 -07:00
|
|
|
import net.minecraft.block.Block;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityLiving;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2014-01-07 15:07:07 -05:00
|
|
|
import net.minecraft.entity.IEntityLivingData;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.boss.EntityWither;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
|
import net.minecraft.entity.item.EntityXPOrb;
|
|
|
|
|
import net.minecraft.entity.monster.EntityCreeper;
|
|
|
|
|
import net.minecraft.entity.monster.EntityGhast;
|
|
|
|
|
import net.minecraft.entity.monster.EntitySkeleton;
|
|
|
|
|
import net.minecraft.entity.monster.EntitySpider;
|
|
|
|
|
import net.minecraft.entity.monster.EntityZombie;
|
|
|
|
|
import net.minecraft.entity.monster.IMob;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.passive.EntityChicken;
|
2014-02-21 09:25:00 -05:00
|
|
|
import net.minecraft.entity.passive.EntityCow;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-31 20:24:06 -05:00
|
|
|
import net.minecraft.init.Blocks;
|
2013-12-31 16:37:46 -05:00
|
|
|
import net.minecraft.init.Items;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraft.item.ItemFood;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.item.crafting.FurnaceRecipes;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
2014-01-01 08:47:10 -05:00
|
|
|
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraft.world.GameRules;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.world.World;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
2014-02-21 09:25:00 -05:00
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
2013-11-19 20:57:52 -08:00
|
|
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.player.BonemealEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
2013-11-04 00:33:39 +01:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
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;
|
2013-11-18 18:11:22 +11:00
|
|
|
import tconstruct.achievements.TAchievements;
|
2013-11-19 20:57:52 -08:00
|
|
|
import tconstruct.blocks.LiquidMetalFinite;
|
|
|
|
|
import tconstruct.blocks.TankAirBlock;
|
2013-11-29 23:16:32 -05:00
|
|
|
import tconstruct.common.TRepo;
|
2013-11-18 18:11:22 +11:00
|
|
|
import tconstruct.items.tools.FryingPan;
|
2013-07-31 13:08:18 -07:00
|
|
|
import tconstruct.library.TConstructRegistry;
|
2013-11-19 20:57:52 -08:00
|
|
|
import tconstruct.library.event.PartBuilderEvent;
|
|
|
|
|
import tconstruct.library.event.ToolCraftEvent;
|
|
|
|
|
import tconstruct.library.tools.ArrowMaterial;
|
|
|
|
|
import tconstruct.library.tools.BowMaterial;
|
|
|
|
|
import tconstruct.library.tools.BowstringMaterial;
|
|
|
|
|
import tconstruct.library.tools.FletchingMaterial;
|
|
|
|
|
import tconstruct.library.tools.ToolCore;
|
|
|
|
|
import tconstruct.library.tools.Weapon;
|
2013-10-01 19:44:04 -07:00
|
|
|
import tconstruct.util.config.PHConstruct;
|
2014-02-21 09:25:00 -05:00
|
|
|
import tconstruct.util.player.ArmorExtended;
|
2013-07-31 13:08:18 -07:00
|
|
|
import tconstruct.util.player.TPlayerStats;
|
2014-02-05 10:28:54 -05:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event.Result;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
public class TEventHandler
|
|
|
|
|
{
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
|
|
|
|
|
/* Crafting */
|
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");
|
2013-11-29 23:16:32 -05:00
|
|
|
if (PHConstruct.denyMattock && event.tool == TRepo.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int thaum = 0;
|
|
|
|
|
if (toolTag.getInteger("Head") == 31)
|
|
|
|
|
thaum++;
|
|
|
|
|
if (toolTag.getInteger("Handle") == 31)
|
|
|
|
|
thaum++;
|
|
|
|
|
if (toolTag.getInteger("Accessory") == 31)
|
|
|
|
|
thaum++;
|
|
|
|
|
if (toolTag.getInteger("Extra") == 31)
|
|
|
|
|
thaum++;
|
|
|
|
|
|
|
|
|
|
if ((thaum >= 3) || (!toolTag.hasKey("Accessory") && thaum >= 2))
|
|
|
|
|
{
|
|
|
|
|
int modifiers = toolTag.getInteger("Modifiers");
|
|
|
|
|
modifiers += 2;
|
|
|
|
|
toolTag.setInteger("Modifiers", modifiers);
|
|
|
|
|
}
|
|
|
|
|
else if (thaum >= 1)
|
|
|
|
|
{
|
|
|
|
|
int modifiers = toolTag.getInteger("Modifiers");
|
|
|
|
|
modifiers += 1;
|
|
|
|
|
toolTag.setInteger("Modifiers", modifiers);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 23:16:32 -05:00
|
|
|
if (event.tool == TRepo.shortbow)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
BowMaterial top = TConstructRegistry.getBowMaterial(toolTag.getInteger("Head"));
|
|
|
|
|
BowMaterial bottom = TConstructRegistry.getBowMaterial(toolTag.getInteger("Accessory"));
|
|
|
|
|
BowstringMaterial string = (BowstringMaterial) TConstructRegistry.getCustomMaterial(toolTag.getInteger("Handle"), BowstringMaterial.class);
|
|
|
|
|
|
|
|
|
|
if (top != null && bottom != null && string != null)
|
|
|
|
|
{
|
|
|
|
|
if (toolTag.getInteger("Handle") == 1)
|
|
|
|
|
{
|
|
|
|
|
int modifiers = toolTag.getInteger("Modifiers");
|
|
|
|
|
modifiers += 1;
|
|
|
|
|
toolTag.setInteger("Modifiers", modifiers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int durability = (int) ((top.durability + bottom.durability) / 2 * string.durabilityModifier);
|
|
|
|
|
toolTag.setInteger("TotalDurability", durability);
|
|
|
|
|
toolTag.setInteger("BaseDurability", durability);
|
|
|
|
|
|
|
|
|
|
int drawSpeed = (int) ((top.drawspeed + bottom.drawspeed) / 2 * string.drawspeedModifier);
|
|
|
|
|
toolTag.setInteger("DrawSpeed", drawSpeed);
|
|
|
|
|
toolTag.setInteger("BaseDrawSpeed", drawSpeed);
|
|
|
|
|
|
|
|
|
|
float flightSpeed = (top.flightSpeedMax + bottom.flightSpeedMax) / 2f * string.flightSpeedModifier;
|
|
|
|
|
toolTag.setFloat("FlightSpeed", flightSpeed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 23:16:32 -05:00
|
|
|
if (event.tool == TRepo.arrow)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
ArrowMaterial head = TConstructRegistry.getArrowMaterial(toolTag.getInteger("Head"));
|
|
|
|
|
ArrowMaterial shaft = TConstructRegistry.getArrowMaterial(toolTag.getInteger("Handle"));
|
|
|
|
|
FletchingMaterial fletching = (FletchingMaterial) TConstructRegistry.getCustomMaterial(toolTag.getInteger("Accessory"), FletchingMaterial.class);
|
|
|
|
|
|
|
|
|
|
if (head != null && shaft != null && fletching != null)
|
|
|
|
|
{
|
|
|
|
|
float mass = head.mass / 5f + shaft.mass + fletching.mass;
|
|
|
|
|
float shatter = (head.breakChance + shaft.breakChance + fletching.breakChance) / 4f;
|
|
|
|
|
float accuracy = (head.accuracy + shaft.accuracy + fletching.accuracy) / 3;
|
|
|
|
|
|
|
|
|
|
ItemStack arrow = new ItemStack(event.tool, 4);
|
|
|
|
|
toolTag.setInteger("TotalDurability", 0);
|
|
|
|
|
toolTag.setFloat("Mass", mass);
|
|
|
|
|
toolTag.setFloat("BreakChance", shatter);
|
|
|
|
|
toolTag.setFloat("Accuracy", accuracy);
|
|
|
|
|
toolTag.setInteger("Unbreaking", 10);
|
|
|
|
|
arrow.setTagCompound(event.toolTag);
|
|
|
|
|
event.overrideResult(arrow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
if (event.pattern.getItem() == TRepo.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 });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 23:16:32 -05:00
|
|
|
if (event.pattern.getItem() == TRepo.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
|
|
|
{
|
2013-08-01 20:54:56 -07:00
|
|
|
if (matchesLeaves(stack))
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
FletchingMaterial leaves = (FletchingMaterial) TConstructRegistry.getCustomMaterial(new ItemStack(Blocks.leaves), FletchingMaterial.class);
|
2013-08-01 20:54:56 -07:00
|
|
|
return leaves.craftingItem.copy();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
FletchingMaterial mat = (FletchingMaterial) TConstructRegistry.getCustomMaterial(stack, FletchingMaterial.class);
|
|
|
|
|
if (mat != null)
|
|
|
|
|
return mat.craftingItem.copy();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
public static boolean matchesLeaves (ItemStack stack)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-09 04:08:38 -05:00
|
|
|
Block block = BlockUtils.getBlockFromItem(stack.getItem());
|
2013-08-01 20:54:56 -07:00
|
|
|
if (block != null)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-08-01 20:54:56 -07:00
|
|
|
if (block.isLeaves(null, 0, 0, 0))
|
|
|
|
|
return true;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2013-08-01 20:54:56 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-08-01 18:45:05 -07:00
|
|
|
|
2013-08-16 13:51:33 -07:00
|
|
|
/* Damage */
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void onHurt (LivingHurtEvent event)
|
2013-08-16 13:51:33 -07:00
|
|
|
{
|
|
|
|
|
if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
2014-02-16 14:23:50 -05:00
|
|
|
// Cutlass
|
2013-08-16 13:51:33 -07:00
|
|
|
ItemStack stack = player.getCurrentEquippedItem();
|
2013-11-29 23:16:32 -05:00
|
|
|
if (stack != null && stack.getItem() == TRepo.cutlass && player.isUsingItem())
|
2013-08-16 13:51:33 -07:00
|
|
|
{
|
|
|
|
|
player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 3 * 20, 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
/* Drops */
|
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-11-19 20:57:52 -08:00
|
|
|
if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof FryingPan)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < event.drops.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
ItemStack is = event.drops.get(i).getEntityItem();
|
2014-02-05 08:28:53 -05:00
|
|
|
if (FurnaceRecipes.smelting().getSmeltingResult(is) != null && FurnaceRecipes.smelting().getSmeltingResult(is).getItem() instanceof ItemFood)
|
2013-11-19 20:57:52 -08:00
|
|
|
{
|
|
|
|
|
NBTTagCompound stackCompound = is.getTagCompound();
|
|
|
|
|
if (stackCompound == null)
|
|
|
|
|
{
|
|
|
|
|
stackCompound = new NBTTagCompound();
|
|
|
|
|
}
|
|
|
|
|
stackCompound.setBoolean("frypanKill", true);
|
|
|
|
|
is.setTagCompound(stackCompound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 23:47:07 -05:00
|
|
|
if (random.nextInt(500) == 0 && event.entityLiving instanceof IMob)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 1);
|
2013-07-26 21:18:53 -07:00
|
|
|
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
|
2014-02-05 08:28:53 -05:00
|
|
|
entityitem.delayBeforeCanPickup = 10;
|
2013-07-26 21:18:53 -07:00
|
|
|
event.drops.add(entityitem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.entityLiving instanceof EntityWither && random.nextInt(5) == 0)
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 1);
|
2013-07-26 21:18:53 -07:00
|
|
|
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
|
2014-02-05 08:28:53 -05:00
|
|
|
entityitem.delayBeforeCanPickup = 10;
|
2013-07-26 21:18:53 -07:00
|
|
|
event.drops.add(entityitem);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-21 09:25:00 -05:00
|
|
|
if (!event.entityLiving.isChild() && event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-21 09:25:00 -05:00
|
|
|
|
|
|
|
|
if (event.entityLiving.getClass() == EntityCow.class)
|
|
|
|
|
{
|
|
|
|
|
int amount = random.nextInt(3) + random.nextInt(1 +
|
|
|
|
|
event.lootingLevel) + random.nextInt(3) + random.nextInt(1 +
|
|
|
|
|
event.lootingLevel) + 1;
|
|
|
|
|
|
|
|
|
|
for (int iter = 0; iter < amount; ++iter)
|
|
|
|
|
{
|
|
|
|
|
addDrops(event, new ItemStack(Items.leather, 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-08-21 15:46:14 -07:00
|
|
|
if (event.entityLiving.getClass() == EntityChicken.class)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
int amount = random.nextInt(3) + random.nextInt(1 + event.lootingLevel) + random.nextInt(3) + random.nextInt(1 + event.lootingLevel) + 1;
|
|
|
|
|
|
|
|
|
|
for (int iter = 0; iter < amount; ++iter)
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
addDrops(event, new ItemStack(Items.feather, 1));
|
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");
|
2013-11-29 23:16:32 -05:00
|
|
|
if (stack.getItem() == TRepo.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
|
|
|
|
if (beheading > 0 && random.nextInt(100) < beheading * 10)
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
addDrops(event, new ItemStack(Items.skull, 1, enemy.getSkeletonType()));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (enemy.getSkeletonType() == 1 && random.nextInt(Math.max(1, 5 - event.lootingLevel)) == 0)
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
addDrops(event, new ItemStack(TRepo.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");
|
2013-11-29 23:16:32 -05:00
|
|
|
if (stack.getItem() == TRepo.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
|
|
|
|
if (beheading > 0 && random.nextInt(100) < beheading * 10)
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
addDrops(event, new ItemStack(Items.skull, 1, 2));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-21 09:25:00 -05:00
|
|
|
|
|
|
|
|
if (stack.getItem() == TRepo.cleaver &&
|
|
|
|
|
random.nextInt(100) < 10) //Swap out for real beheading
|
|
|
|
|
{
|
|
|
|
|
addDrops(event, new ItemStack(Items.skull, 1, 2));
|
|
|
|
|
}
|
|
|
|
|
|
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");
|
2013-11-29 23:16:32 -05:00
|
|
|
if (stack.getItem() == TRepo.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
|
|
|
|
if (beheading > 0 && random.nextInt(100) < beheading * 5)
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
addDrops(event, new ItemStack(Items.skull, 1, 4));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.entityLiving.getClass() == EntityGhast.class)
|
|
|
|
|
{
|
|
|
|
|
if (PHConstruct.uhcGhastDrops)
|
|
|
|
|
{
|
|
|
|
|
for (EntityItem o : event.drops)
|
|
|
|
|
{
|
2014-01-07 15:07:07 -05:00
|
|
|
if (o.getEntityItem().getItem() == Items.ghast_tear)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
o.setEntityItemStack(new ItemStack(Items.gold_ingot, 1));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
addDrops(event, new ItemStack(Items.ghast_tear, 1));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-16 14:23:50 -05:00
|
|
|
// }
|
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);
|
2013-07-26 21:18:53 -07:00
|
|
|
addDrops(event, dropStack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
2013-11-29 23:16:32 -05:00
|
|
|
if (stack.getItem() == TRepo.cleaver)
|
2013-07-26 21:18:53 -07:00
|
|
|
beheading += 2;
|
|
|
|
|
if (beheading > 0 && random.nextInt(100) < beheading * 50)
|
|
|
|
|
{
|
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);
|
2013-07-26 21:18:53 -07:00
|
|
|
addDrops(event, dropStack);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
GameRules rules = player.worldObj.getGameRules(); // Player is null
|
|
|
|
|
// if this
|
|
|
|
|
// crashes
|
2013-11-19 20:57:52 -08:00
|
|
|
if (rules == null || !rules.getGameRuleBooleanValue("keepInventory"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-07 15:07:07 -05:00
|
|
|
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getDisplayName());
|
2013-09-08 23:09:32 +01:00
|
|
|
if (stats != null)
|
|
|
|
|
{
|
|
|
|
|
stats.armor.dropItems();
|
|
|
|
|
stats.knapsack.dropItems();
|
|
|
|
|
}
|
2013-09-05 12:59:58 -07:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void onLivingDeath (LivingDeathEvent event)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-11-19 20:57:52 -08:00
|
|
|
Entity cause = event.source.getSourceOfDamage();
|
|
|
|
|
if (cause != null && cause instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer murderer = (EntityPlayer) cause;
|
2013-11-19 21:57:09 -08:00
|
|
|
ItemStack stack = murderer.getHeldItem();
|
|
|
|
|
if (stack != null && stack.getItem() instanceof Weapon)
|
2013-11-19 20:57:52 -08:00
|
|
|
{
|
|
|
|
|
murderer.addStat(TAchievements.achievements.get("tconstruct.enemySlayer"), 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
void addDrops (LivingDropsEvent event, ItemStack dropStack)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
|
2014-02-05 08:28:53 -05:00
|
|
|
entityitem.delayBeforeCanPickup = 10;
|
2013-07-26 21:18:53 -07:00
|
|
|
event.drops.add(entityitem);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
/*
|
|
|
|
|
* @ForgeSubscribe public void onLivingSpawn (EntityJoinWorldEvent event) {
|
|
|
|
|
* if (event.entity instanceof EntityXPOrb) {
|
|
|
|
|
* TConstruct.logger.info("Entity: " + event.entity); } }
|
|
|
|
|
*/
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void onLivingSpawn (LivingSpawnEvent.SpecialSpawn event)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-11-04 00:33:39 +01:00
|
|
|
EntityLivingBase living = event.entityLiving;
|
2013-09-05 12:39:18 -07:00
|
|
|
if (living.getClass() == EntitySpider.class && random.nextInt(100) == 0)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-09-05 12:39:18 -07:00
|
|
|
EntityCreeper creeper = new EntityCreeper(living.worldObj);
|
|
|
|
|
spawnEntityLiving(living.posX, living.posY + 1, living.posZ, creeper, living.worldObj);
|
|
|
|
|
if (living.riddenByEntity != null)
|
|
|
|
|
creeper.mountEntity(living.riddenByEntity);
|
|
|
|
|
else
|
|
|
|
|
creeper.mountEntity(living);
|
2013-09-05 12:59:58 -07:00
|
|
|
|
2013-09-05 12:39:18 -07:00
|
|
|
EntityXPOrb orb = new EntityXPOrb(living.worldObj, living.posX, living.posY, living.posZ, random.nextInt(20) + 20);
|
|
|
|
|
orb.mountEntity(creeper);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:33:39 +01:00
|
|
|
public static void spawnEntityLiving (double x, double y, double z, EntityLiving entity, World world)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-09-05 12:39:18 -07:00
|
|
|
if (!world.isRemote)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
entity.setPosition(x, y, z);
|
2014-01-07 15:07:07 -05:00
|
|
|
entity.onSpawnWithEgg((IEntityLivingData) null);
|
2013-07-26 21:18:53 -07:00
|
|
|
world.spawnEntityInWorld(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-11 10:33:07 -07:00
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
/* Bonemeal */
|
2013-08-11 10:33:07 -07:00
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void bonemealEvent (BonemealEvent event)
|
2013-08-11 10:33:07 -07:00
|
|
|
{
|
|
|
|
|
if (!event.world.isRemote)
|
|
|
|
|
{
|
2014-01-07 15:07:07 -05:00
|
|
|
if (event.block == TRepo.slimeSapling)
|
2013-08-11 10:33:07 -07:00
|
|
|
{
|
2014-01-16 01:36:18 -05:00
|
|
|
if (TRepo.slimeSapling.boneFertilize(event.world, event.x, event.y, event.z, event.world.rand, event.entityPlayer))
|
2013-08-11 10:33:07 -07:00
|
|
|
event.setResult(Event.Result.ALLOW);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
/* Ore Dictionary */
|
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
|
|
|
|
2013-11-25 15:36:32 -05:00
|
|
|
if (evt.Name == "crystalQuartz")
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-12 03:08:05 -08:00
|
|
|
TRepo.modAttack.addStackToMatchList(evt.Ore, 2);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (evt.Name == "crystalCerusQuartz")
|
|
|
|
|
{
|
2013-12-12 03:08:05 -08:00
|
|
|
TRepo.modAttack.addStackToMatchList(evt.Ore, 24);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void bucketFill (FillBucketEvent evt)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-16 01:36:18 -05:00
|
|
|
if (evt.current.getItem() == Items.bucket && evt.target.typeOfHit == MovingObjectType.ENTITY)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
int hitX = evt.target.blockX;
|
|
|
|
|
int hitY = evt.target.blockY;
|
|
|
|
|
int hitZ = evt.target.blockZ;
|
|
|
|
|
|
|
|
|
|
if (evt.entityPlayer != null && !evt.entityPlayer.canPlayerEdit(hitX, hitY, hitZ, evt.target.sideHit, evt.current))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
Block bID = evt.world.getBlock(hitX, hitY, hitZ);
|
2013-11-29 23:16:32 -05:00
|
|
|
for (int id = 0; id < TRepo.fluidBlocks.length; id++)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-07 15:07:07 -05:00
|
|
|
if (bID == TRepo.fluidBlocks[id])
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (evt.entityPlayer.capabilities.isCreativeMode)
|
|
|
|
|
{
|
2014-02-05 09:11:06 -05:00
|
|
|
WorldHelper.setBlockToAir(evt.world, hitX, hitY, hitZ);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-11-29 23:16:32 -05:00
|
|
|
if (TRepo.fluidBlocks[id] instanceof LiquidMetalFinite)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-16 01:36:18 -05:00
|
|
|
WorldHelper.setBlockToAir(evt.world, hitX, hitY, hitZ);
|
2014-02-16 14:23:50 -05:00
|
|
|
/*
|
|
|
|
|
* int quanta = 0; for (int posX = -1; posX <= 1;
|
|
|
|
|
* posX++) { for (int posZ = -1; posZ <= 1; posZ++)
|
|
|
|
|
* { int localID = evt.world.getBlockId(hitX + posX,
|
|
|
|
|
* hitY, hitZ + posZ); if (localID == bID) { quanta
|
|
|
|
|
* += evt.world.getBlockMetadata(hitX + posX, hitY,
|
|
|
|
|
* hitZ + posZ) + 1; } } }
|
|
|
|
|
*
|
|
|
|
|
* if (quanta >= 8) { while (quanta > 0) { for (int
|
|
|
|
|
* posX = -1; posX <= 1; posX++) { for (int posZ =
|
|
|
|
|
* -1; posZ <= 1; posZ++) { int localID =
|
|
|
|
|
* evt.world.getBlockId(hitX + posX, hitY, hitZ +
|
|
|
|
|
* posZ); if (localID == bID) { quanta -= 1; int
|
|
|
|
|
* meta = evt.world.getBlockMetadata(hitX + posX,
|
|
|
|
|
* hitY, hitZ + posZ); if (meta > 0)
|
|
|
|
|
* evt.world.setBlockMetadataWithNotify(hitX + posX,
|
|
|
|
|
* hitY, hitZ + posZ, meta - 1, 3); else
|
|
|
|
|
* evt.world.setBlockToAir(hitX + posX, hitY, hitZ +
|
|
|
|
|
* posZ); } } } } }
|
|
|
|
|
*/
|
2013-08-16 13:51:33 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-01-16 01:36:18 -05:00
|
|
|
WorldHelper.setBlockToAir(evt.world, hitX, hitY, hitZ);
|
2013-08-16 13:51:33 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
evt.setResult(Result.ALLOW);
|
2013-11-29 23:16:32 -05:00
|
|
|
evt.result = new ItemStack(TRepo.buckets, 1, id);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-05 09:11:06 -05:00
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// TODO 1.7 Fix this -- for ticking stuffs in extra armor slots
|
2014-02-21 09:25:00 -05:00
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void livingUpdate (LivingUpdateEvent event)
|
|
|
|
|
{ if (event.entityLiving instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
|
|
|
|
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getDisplayName());
|
|
|
|
|
|
2014-02-22 14:17:26 -08:00
|
|
|
if (stats != null && stats.armor != null)
|
2014-02-21 09:25:00 -05:00
|
|
|
{
|
|
|
|
|
ArmorExtended armor = stats.armor;
|
|
|
|
|
for (int i = 0; i < armor.getSizeInventory(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (armor.getStackInSlot(i) != null)
|
|
|
|
|
{
|
|
|
|
|
armor.getStackInSlot(i).getItem().onUpdate(armor.getStackInSlot(i),
|
|
|
|
|
player.worldObj, player, i, false);
|
|
|
|
|
armor.getStackInSlot(i).getItem().onArmorTick(player.worldObj, player,
|
|
|
|
|
armor.getStackInSlot(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
|
|
|
|
|
// Player interact event - prevent breaking of tank air blocks in creative
|
2013-12-31 20:24:06 -05:00
|
|
|
@SubscribeEvent
|
2013-11-04 00:33:39 +01:00
|
|
|
public void playerInteract (PlayerInteractEvent event)
|
|
|
|
|
{
|
|
|
|
|
if (event.action == Action.LEFT_CLICK_BLOCK)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
Block block = event.entity.worldObj.getBlock(event.x, event.y, event.z);
|
2013-11-04 00:33:39 +01:00
|
|
|
if (block instanceof TankAirBlock)
|
|
|
|
|
{
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-08 21:27:03 +11:00
|
|
|
}
|
2013-11-04 00:33:39 +01:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|