2013-06-15 11:08:58 +00:00
|
|
|
package biomesoplenty.handlers;
|
2013-05-11 11:19:28 +00:00
|
|
|
|
2013-06-15 08:46:50 +00:00
|
|
|
import net.minecraft.block.Block;
|
2013-07-02 03:57:49 +00:00
|
|
|
import net.minecraft.block.BlockColored;
|
2013-05-11 11:19:28 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityCreature;
|
|
|
|
import net.minecraft.entity.EntityLiving;
|
2013-06-15 08:46:50 +00:00
|
|
|
import net.minecraft.entity.effect.EntityLightningBolt;
|
2013-06-20 08:43:33 +00:00
|
|
|
import net.minecraft.entity.monster.EntityEnderman;
|
2013-05-25 13:01:16 +00:00
|
|
|
import net.minecraft.entity.passive.EntityAnimal;
|
2013-05-11 11:19:28 +00:00
|
|
|
import net.minecraft.entity.passive.EntityChicken;
|
|
|
|
import net.minecraft.entity.passive.EntityCow;
|
|
|
|
import net.minecraft.entity.passive.EntityPig;
|
|
|
|
import net.minecraft.entity.passive.EntitySheep;
|
2013-06-20 08:43:33 +00:00
|
|
|
import net.minecraft.entity.passive.EntityVillager;
|
|
|
|
import net.minecraft.entity.passive.EntityWolf;
|
2013-06-15 08:46:50 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-05-29 22:37:21 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-06-20 08:43:33 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-05-25 13:01:16 +00:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2013-05-29 22:37:21 +00:00
|
|
|
import net.minecraft.util.DamageSource;
|
2013-05-12 22:22:17 +00:00
|
|
|
import net.minecraft.util.MathHelper;
|
2013-06-15 08:46:50 +00:00
|
|
|
import net.minecraft.world.World;
|
2013-05-12 22:22:17 +00:00
|
|
|
import net.minecraftforge.event.Event.Result;
|
2013-05-11 11:19:28 +00:00
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
2013-06-20 08:56:03 +00:00
|
|
|
import net.minecraftforge.event.entity.EntityEvent;
|
2013-05-11 11:19:28 +00:00
|
|
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
2013-05-29 22:37:21 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
2013-05-12 22:22:17 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingSpawnEvent.CheckSpawn;
|
2013-06-20 08:43:33 +00:00
|
|
|
import net.minecraftforge.event.entity.player.EntityInteractEvent;
|
2013-06-20 09:12:29 +00:00
|
|
|
import biomesoplenty.api.Biomes;
|
2013-05-12 22:22:17 +00:00
|
|
|
import biomesoplenty.api.Blocks;
|
2013-05-11 11:19:28 +00:00
|
|
|
import biomesoplenty.api.Items;
|
2013-05-29 22:37:21 +00:00
|
|
|
import biomesoplenty.configuration.BOPConfiguration;
|
2013-06-15 08:46:50 +00:00
|
|
|
import biomesoplenty.entities.ai.EntityAITemptArmour;
|
2013-06-20 09:12:29 +00:00
|
|
|
import biomesoplenty.helpers.AchievementHelper;
|
2013-06-15 11:08:58 +00:00
|
|
|
import biomesoplenty.helpers.TeleporterPromised;
|
2013-06-23 10:10:00 +00:00
|
|
|
import biomesoplenty.world.WorldTypeBOP;
|
2013-06-22 21:39:18 +00:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2013-05-11 11:19:28 +00:00
|
|
|
|
2013-06-15 11:08:58 +00:00
|
|
|
public class EntityEventHandler
|
2013-05-11 11:19:28 +00:00
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void onEntitySpawn(EntityJoinWorldEvent event)
|
|
|
|
{
|
|
|
|
Entity entity = event.entity;
|
|
|
|
|
|
|
|
if (!(entity instanceof EntityLiving))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (entity instanceof EntityChicken) {
|
|
|
|
((EntityLiving)entity).tasks.addTask(3, new EntityAITemptArmour((EntityCreature) entity, 0.25F, Items.flowerBand.get().itemID, 0, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity instanceof EntitySheep) {
|
|
|
|
((EntityLiving)entity).tasks.addTask(3, new EntityAITemptArmour((EntityCreature) entity, 0.25F, Items.flowerBand.get().itemID, 1, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity instanceof EntityPig) {
|
|
|
|
((EntityLiving)entity).tasks.addTask(4, new EntityAITemptArmour((EntityCreature) entity, 0.25F, Items.flowerBand.get().itemID, 2, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entity instanceof EntityCow) {
|
|
|
|
((EntityLiving)entity).tasks.addTask(3, new EntityAITemptArmour((EntityCreature) entity, 0.25F, Items.flowerBand.get().itemID, 3, false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 03:57:49 +00:00
|
|
|
/*@ForgeSubscribe
|
2013-05-31 10:34:02 +00:00
|
|
|
public void canEntitySpawn(CheckSpawn event)
|
|
|
|
{
|
|
|
|
if (event.entityLiving instanceof EntityAnimal)
|
|
|
|
{
|
|
|
|
int i = MathHelper.floor_double(event.entityLiving.posX);
|
|
|
|
int j = MathHelper.floor_double(event.entityLiving.boundingBox.minY);
|
|
|
|
int k = MathHelper.floor_double(event.entityLiving.posZ);
|
|
|
|
|
2013-07-02 03:57:49 +00:00
|
|
|
if (event.entityLiving. <= event.world.getEntitiesWithinAABB(event.entityLiving.getClass(), AxisAlignedBB.getAABBPool().getAABB(i - 16, j - 4, k - 16, i + 17, j + 5, k + 17)).size())
|
2013-05-31 10:34:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.entityLiving.worldObj.getBlockId(i, j - 1, k) == Blocks.holyGrass.get().blockID && event.entityLiving.worldObj.getFullBlockLightValue(i, j, k) > 8
|
|
|
|
&& event.entityLiving.worldObj.checkNoEntityCollision(event.entity.boundingBox) && !event.entityLiving.worldObj.isAnyLiquid(event.entityLiving.boundingBox)
|
|
|
|
&& event.entityLiving.worldObj.getCollidingBoundingBoxes(event.entityLiving, event.entityLiving.boundingBox).isEmpty()) {
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
}
|
|
|
|
}
|
2013-07-02 03:57:49 +00:00
|
|
|
}*/
|
2013-05-31 10:34:02 +00:00
|
|
|
|
2013-07-02 08:45:52 +00:00
|
|
|
@ForgeSubscribe
|
2013-05-31 10:34:02 +00:00
|
|
|
public void fallingFromPromisedLand(LivingHurtEvent event)
|
|
|
|
{
|
|
|
|
if (event.source == DamageSource.outOfWorld && event.entityLiving.dimension == BOPConfiguration.promisedLandDimID)
|
|
|
|
{
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
|
|
|
if (!event.entityLiving.worldObj.isRemote && !event.entityLiving.isDead)
|
|
|
|
{
|
|
|
|
if (event.entityLiving instanceof EntityPlayerMP)
|
|
|
|
{
|
|
|
|
EntityPlayerMP thePlayer = (EntityPlayerMP) event.entityLiving;
|
|
|
|
thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, 0, new TeleporterPromised(thePlayer.mcServer.worldServerForDimension(0), true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-02 08:45:52 +00:00
|
|
|
}
|
2013-06-15 08:46:50 +00:00
|
|
|
|
2013-06-20 08:56:03 +00:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void chunkEntered(EntityEvent.EnteringChunk event)
|
|
|
|
{
|
|
|
|
if (event.entity != null)
|
|
|
|
{
|
|
|
|
if (event.entity instanceof EntityPlayer)
|
|
|
|
{
|
|
|
|
EntityPlayer player = (EntityPlayer)event.entity;
|
|
|
|
World world = player.worldObj;
|
|
|
|
|
|
|
|
int x = MathHelper.floor_double(player.posX);
|
|
|
|
int y = MathHelper.floor_double(player.boundingBox.minY);
|
|
|
|
int z = MathHelper.floor_double(player.posZ);
|
|
|
|
|
|
|
|
int biomeID = world.getBiomeGenForCoords(x, z).biomeID;
|
2013-06-20 09:12:29 +00:00
|
|
|
|
2013-06-23 09:19:48 +00:00
|
|
|
if (biomeID == Biomes.alps.get().biomeID)
|
2013-06-20 09:12:29 +00:00
|
|
|
{
|
2013-06-23 09:19:48 +00:00
|
|
|
player.addStat(AchievementHelper.achAlps, 1);
|
2013-06-20 09:12:29 +00:00
|
|
|
}
|
2013-06-23 09:19:48 +00:00
|
|
|
if (biomeID == Biomes.arctic.get().biomeID)
|
2013-06-20 09:12:29 +00:00
|
|
|
{
|
2013-06-23 09:19:48 +00:00
|
|
|
player.addStat(AchievementHelper.achArctic, 1);
|
2013-06-20 09:12:29 +00:00
|
|
|
}
|
2013-06-25 23:11:07 +00:00
|
|
|
if (biomeID == Biomes.badlands.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBadlands, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.bambooForest.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBambooForest, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.bayou.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBayou, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.birchForest.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBirchForest, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.bog.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBog, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.borealForest.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBorealForest, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.brushland.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achBrushland, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.canyon.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achCanyon, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.chaparral.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achChaparral, 1);
|
|
|
|
}
|
|
|
|
if (biomeID == Biomes.cherryBlossomGrove.get().biomeID)
|
|
|
|
{
|
|
|
|
player.addStat(AchievementHelper.achCherryBlossom, 1);
|
|
|
|
}
|
2013-06-20 08:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 10:10:00 +00:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void playerJoin(EntityJoinWorldEvent event)
|
|
|
|
{
|
|
|
|
if (event.world.provider.terrainType instanceof WorldTypeBOP)
|
|
|
|
{
|
|
|
|
if (event.entity instanceof EntityPlayer)
|
|
|
|
{
|
|
|
|
EntityPlayer player = (EntityPlayer)event.entity;
|
|
|
|
|
|
|
|
player.addStat(AchievementHelper.achBOP, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:43:33 +00:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void entityInteract(EntityInteractEvent event)
|
|
|
|
{
|
|
|
|
ItemStack itemstack = event.entityPlayer.getCurrentEquippedItem();
|
|
|
|
Entity entity = event.target;
|
|
|
|
EntityPlayer player = event.entityPlayer;
|
|
|
|
|
|
|
|
if (itemstack != null)
|
|
|
|
{
|
2013-06-22 21:34:48 +00:00
|
|
|
int itemDamage = itemstack.getItemDamage();
|
|
|
|
|
2013-06-20 08:43:33 +00:00
|
|
|
if (itemstack.itemID == Items.soulManipulator.get().itemID && itemstack.getItemDamage() == 2)
|
|
|
|
{
|
|
|
|
if (entity instanceof EntityEnderman)
|
|
|
|
{
|
|
|
|
EntityEnderman entityenderman = (EntityEnderman)entity;
|
|
|
|
|
|
|
|
if (entityenderman.worldObj.rand.nextInt(2) == 0)
|
|
|
|
{
|
|
|
|
entityenderman.attackEntityFrom(DamageSource.causePlayerDamage(player), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
entityenderman.attackEntityFrom(DamageSource.causePlayerDamage(player), 0);
|
|
|
|
|
|
|
|
if (entityenderman.worldObj.rand.nextInt(6) == 0)
|
|
|
|
{
|
|
|
|
EntityVillager entityvillager = new EntityVillager(entityenderman.worldObj);
|
|
|
|
entityvillager.setLocationAndAngles(entityenderman.posX, entityenderman.posY, entityenderman.posZ, MathHelper.wrapAngleTo180_float(entityenderman.worldObj.rand.nextFloat() * 360.0F), 0.0F);
|
|
|
|
entityvillager.rotationYawHead = entityvillager.rotationYaw;
|
|
|
|
entityvillager.renderYawOffset = entityvillager.rotationYaw;
|
|
|
|
|
|
|
|
if (!entityenderman.worldObj.isRemote)
|
|
|
|
{
|
|
|
|
entityenderman.worldObj.spawnEntityInWorld(entityvillager);
|
|
|
|
|
|
|
|
FMLClientHandler.instance().getClient().sndManager.playSound("mob.endermen.death", (float) entityvillager.posX + 0.5F, (float) entityvillager.posY + 0.5F, (float) entityvillager.posZ + 0.5F, 5.0F, -8.0F);
|
|
|
|
entityenderman.setDead();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
|
|
{
|
|
|
|
itemstack.setItemDamage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
|
|
|
|
//entityvillager.playLivingSound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (itemstack.itemID == Items.miscItems.get().itemID && (itemDamage == 5 || itemDamage == 6 || itemDamage == 7 || itemDamage == 8 || itemDamage == 9))
|
|
|
|
{
|
|
|
|
int dyeMeta = convertToDyeMeta(itemDamage);
|
2013-07-02 03:57:49 +00:00
|
|
|
int i = BlockColored.getBlockFromDye(dyeMeta);
|
2013-06-20 08:43:33 +00:00
|
|
|
|
|
|
|
if (entity instanceof EntityWolf)
|
|
|
|
{
|
|
|
|
EntityWolf entitywolf = (EntityWolf)entity;
|
|
|
|
|
|
|
|
if (i != entitywolf.getCollarColor())
|
|
|
|
{
|
|
|
|
entitywolf.setCollarColor(i)
|
|
|
|
;
|
2013-06-22 21:39:18 +00:00
|
|
|
if (!event.entityPlayer.capabilities.isCreativeMode)
|
2013-06-20 08:43:33 +00:00
|
|
|
{
|
|
|
|
--itemstack.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (entity instanceof EntitySheep)
|
|
|
|
{
|
|
|
|
EntitySheep entitysheep = (EntitySheep)entity;
|
|
|
|
|
|
|
|
if (!entitysheep.getSheared() && entitysheep.getFleeceColor() != i)
|
|
|
|
{
|
|
|
|
entitysheep.setFleeceColor(i);
|
|
|
|
|
2013-06-22 21:39:18 +00:00
|
|
|
if (!event.entityPlayer.capabilities.isCreativeMode)
|
2013-06-20 08:43:33 +00:00
|
|
|
{
|
|
|
|
--itemstack.stackSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int convertToDyeMeta(int meta)
|
|
|
|
{
|
|
|
|
switch (meta)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
return 15;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 08:46:50 +00:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void lightningStrike(LivingHurtEvent event)
|
|
|
|
{
|
2013-06-16 00:30:58 +00:00
|
|
|
AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB((double)event.entity.posX, (double)event.entity.posY, (double)event.entity.posZ, (double)(event.entity.posX + 1), (double)(event.entity.posY + 1), (double)(event.entity.posZ + 1)).expand(5, 5, 5);
|
2013-06-15 08:46:50 +00:00
|
|
|
|
2013-06-16 00:30:58 +00:00
|
|
|
if (!event.entity.worldObj.getEntitiesWithinAABB(EntityLightningBolt.class, axisalignedbb).isEmpty());
|
|
|
|
{
|
|
|
|
if (!event.entity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, axisalignedbb).isEmpty());
|
2013-06-15 08:46:50 +00:00
|
|
|
{
|
2013-06-16 00:30:58 +00:00
|
|
|
if (isBlockInBB(event.entity.worldObj, axisalignedbb, Blocks.glass.get().blockID, 2) || isBlockInBB(event.entity.worldObj, axisalignedbb, Blocks.glass.get().blockID, 3))
|
|
|
|
{
|
|
|
|
event.setCanceled(true);
|
2013-06-15 08:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBlockInBB(World world, AxisAlignedBB par1AxisAlignedBB, int blockID, int blockMeta)
|
|
|
|
{
|
|
|
|
int i = MathHelper.floor_double(par1AxisAlignedBB.minX);
|
|
|
|
int j = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0D);
|
|
|
|
int k = MathHelper.floor_double(par1AxisAlignedBB.minY);
|
|
|
|
int l = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0D);
|
|
|
|
int i1 = MathHelper.floor_double(par1AxisAlignedBB.minZ);
|
|
|
|
int j1 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0D);
|
|
|
|
|
|
|
|
for (int k1 = i; k1 < j; ++k1)
|
|
|
|
{
|
|
|
|
for (int l1 = k; l1 < l; ++l1)
|
|
|
|
{
|
|
|
|
for (int i2 = i1; i2 < j1; ++i2)
|
|
|
|
{
|
|
|
|
Block block = Block.blocksList[world.getBlockId(k1, l1, i2)];
|
|
|
|
|
|
|
|
if (block != null && block.blockID == blockID && world.getBlockMetadata(k1, l1, i2) == blockMeta)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-11 11:19:28 +00:00
|
|
|
}
|