Files
TinkersConstruct/src/main/java/tconstruct/util/TEventHandler.java
T

662 lines
26 KiB
Java
Raw Normal View History

package tconstruct.util;
2013-12-14 14:11:41 +11:00
import tconstruct.util.player.ArmorExtended;
2014-01-09 04:08:38 -05:00
import mantle.blocks.BlockUtils;
2014-01-16 01:36:18 -05:00
import mantle.world.WorldHelper;
2013-12-14 14:11:41 +11:00
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
2013-11-04 00:33:39 +01:00
import java.util.Random;
2013-11-19 20:57:52 -08:00
2013-12-31 20:24:06 -05:00
import cpw.mods.fml.common.eventhandler.Event.Result;
2014-01-01 08:47:10 -05:00
import cpw.mods.fml.common.eventhandler.Event;
2013-12-31 20:24:06 -05:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
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;
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;
import net.minecraft.entity.passive.EntityChicken;
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.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
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;
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;
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;
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;
import tconstruct.library.crafting.ToolBuilder;
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-12-06 11:37:06 -08:00
import tconstruct.modifiers.tools.ModAttack;
2013-10-01 19:44:04 -07:00
import tconstruct.util.config.PHConstruct;
2013-07-31 13:08:18 -07:00
import tconstruct.util.player.TPlayerStats;
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)
{
NBTTagCompound toolTag = event.toolTag.getCompoundTag("InfiTool");
2013-11-29 23:16:32 -05:00
if (PHConstruct.denyMattock && event.tool == TRepo.mattock)
{
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)
{
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)
{
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)
{
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-11-29 23:16:32 -05:00
if (event.pattern.getItem() == TRepo.woodPattern && event.pattern.getItemDamage() == 23)
{
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)
{
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)
{
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-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();
}
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)
{
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-08-01 20:54:56 -07:00
if (block.isLeaves(null, 0, 0, 0))
return true;
}
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;
//Cutlass
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));
}
}
}
/* Drops */
2013-12-31 20:24:06 -05:00
@SubscribeEvent
2013-11-04 00:33:39 +01:00
public void onLivingDrop (LivingDropsEvent event)
{
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-11-29 23:16:32 -05:00
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 1);
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;
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);
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;
event.drops.add(entityitem);
}
//if (event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot"))
//{
if (!event.entityLiving.isChild())
{
2013-08-21 15:46:14 -07: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(Item.leather, 1));
}
2013-08-21 15:46:14 -07:00
}*/
2013-08-21 15:46:14 -07:00
if (event.entityLiving.getClass() == EntityChicken.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)
{
2013-12-31 20:24:06 -05:00
addDrops(event, new ItemStack(Items.feather, 1));
}
}
}
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)
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()));
}
}
}
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));
}
}
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)
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-11-29 23:16:32 -05:00
/*if (stack.getItem() == TRepo.breakerBlade && random.nextInt(100) < 10) //Swap out for real beheading
{
addDrops(event, new ItemStack(Item.skull.itemID, 1, 2));
}*/
}
}
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)
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));
}
}
}
}
}
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-12-31 20:24:06 -05:00
o.setEntityItemStack(new ItemStack(Items.gold_ingot, 1));
}
}
}
else
{
2013-12-31 20:24:06 -05:00
addDrops(event, new ItemStack(Items.ghast_tear, 1));
}
}
//}
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);
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);
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)
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);
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);
addDrops(event, dropStack);
}
}
}
2013-11-19 20:57:52 -08:00
GameRules rules = player.worldObj.getGameRules(); //Player is null if this crashes
if (rules == null || !rules.getGameRuleBooleanValue("keepInventory"))
{
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-12-31 20:24:06 -05:00
@SubscribeEvent
2013-11-04 00:33:39 +01:00
public void onLivingDeath (LivingDeathEvent event)
{
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-11-04 00:33:39 +01:00
void addDrops (LivingDropsEvent event, ItemStack dropStack)
{
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;
event.drops.add(entityitem);
}
/*@ForgeSubscribe
public void onLivingSpawn (EntityJoinWorldEvent event)
{
if (event.entity instanceof EntityXPOrb)
{
TConstruct.logger.info("Entity: " + event.entity);
}
}*/
2013-12-31 20:24:06 -05:00
@SubscribeEvent
2013-11-04 00:33:39 +01:00
public void onLivingSpawn (LivingSpawnEvent.SpecialSpawn event)
{
2013-11-04 00:33:39 +01:00
EntityLivingBase living = event.entityLiving;
if (living.getClass() == EntitySpider.class && random.nextInt(100) == 0)
{
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
EntityXPOrb orb = new EntityXPOrb(living.worldObj, living.posX, living.posY, living.posZ, random.nextInt(20) + 20);
orb.mountEntity(creeper);
}
}
2013-11-04 00:33:39 +01:00
public static void spawnEntityLiving (double x, double y, double z, EntityLiving entity, World world)
{
if (!world.isRemote)
{
entity.setPosition(x, y, z);
2014-01-07 15:07:07 -05:00
entity.onSpawnWithEgg((IEntityLivingData) null);
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);
}
}
}
/* 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-12-11 23:47:07 -05:00
2013-11-25 15:36:32 -05:00
if (evt.Name == "crystalQuartz")
{
2013-12-12 03:08:05 -08:00
TRepo.modAttack.addStackToMatchList(evt.Ore, 2);
}
else if (evt.Name == "crystalCerusQuartz")
{
2013-12-12 03:08:05 -08:00
TRepo.modAttack.addStackToMatchList(evt.Ore, 24);
}
}
2013-12-31 20:24:06 -05:00
@SubscribeEvent
2013-11-04 00:33:39 +01:00
public void bucketFill (FillBucketEvent evt)
{
2014-01-16 01:36:18 -05:00
if (evt.current.getItem() == Items.bucket && evt.target.typeOfHit == MovingObjectType.ENTITY)
{
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++)
{
2014-01-07 15:07:07 -05:00
if (bID == TRepo.fluidBlocks[id])
{
if (evt.entityPlayer.capabilities.isCreativeMode)
{
2014-01-16 01:36:18 -05:00
WorldHelper.setBlockToAir(evt.world,hitX, hitY, hitZ);
}
else
{
2013-11-29 23:16:32 -05:00
if (TRepo.fluidBlocks[id] instanceof LiquidMetalFinite)
{
2014-01-16 01:36:18 -05:00
WorldHelper.setBlockToAir(evt.world, hitX, hitY, hitZ);
/*int quanta = 0;
2013-08-16 13:51:33 -07:00
for (int posX = -1; posX <= 1; posX++)
{
2013-08-16 13:51:33 -07:00
for (int posZ = -1; posZ <= 1; posZ++)
{
2013-08-16 13:51:33 -07:00
int localID = evt.world.getBlockId(hitX + posX, hitY, hitZ + posZ);
if (localID == bID)
{
quanta += evt.world.getBlockMetadata(hitX + posX, hitY, hitZ + posZ) + 1;
}
}
}
2013-08-16 13:51:33 -07:00
if (quanta >= 8)
{
2013-08-16 13:51:33 -07:00
while (quanta > 0)
{
2013-08-16 13:51:33 -07:00
for (int posX = -1; posX <= 1; posX++)
{
2013-08-16 13:51:33 -07:00
for (int posZ = -1; posZ <= 1; posZ++)
{
2013-08-16 13:51:33 -07:00
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
}
evt.setResult(Result.ALLOW);
2013-11-29 23:16:32 -05:00
evt.result = new ItemStack(TRepo.buckets, 1, id);
}
}
}
}
}
2013-12-31 20:24:06 -05:00
@SubscribeEvent
2013-12-14 14:11:41 +11:00
public void livingUpdate (LivingUpdateEvent event)
{
if(event.entityLiving instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer) event.entityLiving;
2014-01-07 15:07:07 -05:00
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getDisplayName());
2013-12-14 14:11:41 +11:00
if(stats != null){
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);
2014-01-16 03:57:21 -05:00
armor.getStackInSlot(i).getItem().onArmorTick(player.worldObj, player, armor.getStackInSlot(i));
2013-12-14 14:11:41 +11: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-11-04 00:33:39 +01:00
}