Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tiviacz.chocolatequestrepoured.objects.entity;
- import java.util.List;
- import net.minecraft.block.Block;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.projectile.EntityThrowable;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.EnumParticleTypes;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.RayTraceResult;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.common.registry.IThrowableEntity;
- public class EntityProjectileEarthQuake extends EntityThrowable
- {
- private int lifeTime = 60;
- private EntityLivingBase thrower;
- public EntityProjectileEarthQuake(World worldIn)
- {
- super(worldIn);
- }
- public EntityProjectileEarthQuake(World worldIn, double x, double y, double z)
- {
- super(worldIn, x, y, z);
- }
- public EntityProjectileEarthQuake(World worldIn, EntityLivingBase throwerIn)
- {
- super(worldIn, throwerIn);
- this.thrower = throwerIn;
- float rot = throwerIn.getRotationYawHead();
- this.setRotationYawHead(rot);
- this.posY -= 1.25D;
- this.motionX = 0.1D;
- this.motionY = -1.0D;
- this.motionZ = 0.1D;
- this.isImmuneToFire = true;
- }
- @Override
- protected void onImpact(RayTraceResult result)
- {
- if(!world.isRemote)
- {
- if(!(result.entityHit instanceof EntityLiving))
- {
- motionY = 0.0D;
- }
- }
- }
- @Override
- public void onUpdate()
- {
- motionX *= 1.01D;
- motionZ *= 1.01D;
- if(getThrower() != null && getThrower().isDead)
- {
- setDead();
- }
- else
- {
- if(ticksExisted++ > 300)
- {
- setDead();
- }
- this.onUpdateInAir();
- super.onUpdate();
- }
- }
- private void onUpdateInAir()
- {
- lifeTime -= 1;
- if(lifeTime <= 0)
- {
- setDead();
- }
- BlockPos pos = new BlockPos(this.getPosition().getX(), this.getPosition().getY() - 1, this.getPosition().getZ());
- Block block = world.getBlockState(pos).getBlock();
- if(block == null || block == Blocks.AIR)
- {
- block = Blocks.GLASS;
- }
- double dist = 1.0D;
- AxisAlignedBB var3 = getEntityBoundingBox().expand(dist, 2.0D, dist);
- List<Entity> list = world.getEntitiesWithinAABB(EntityLivingBase.class, var3);
- for(Entity entity : list)
- {
- if(entity instanceof EntityLivingBase && entity != getThrower() && !world.isRemote && entity.onGround)
- {
- entity.motionY = 0.3D;
- entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this, getThrower()), 1.0F);
- }
- }
- if(world.isRemote)
- {
- for(int i = 0; i < 8; i++)
- {
- world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + rand.nextFloat() - 0.5D, posY + rand.nextFloat() - 0.5D, posZ + rand.nextFloat() - 0.5D, rand.nextFloat() - 0.5F, rand.nextFloat(), rand.nextFloat() - 0.5F, Block.getStateId(world.getBlockState(pos)));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement