Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ENTITY SMG]
- package mod.sparkyfox.servermod.entity;
- import javax.annotation.Nonnull;
- import mod.sparkyfox.servermod.init.ModItems;
- import mod.sparkyfox.servermod.init.ModSoundEvent;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.monster.EntityEnderman;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.projectile.EntityArrow;
- import net.minecraft.init.SoundEvents;
- import net.minecraft.item.ItemStack;
- import net.minecraft.network.datasync.DataParameter;
- import net.minecraft.network.datasync.DataSerializers;
- import net.minecraft.network.datasync.EntityDataManager;
- import net.minecraft.util.EnumParticleTypes;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.math.RayTraceResult;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.World;
- public class EntitySMGRounds extends EntityArrow {
- private EnumParticleTypes particle;
- //added by me\\
- private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(EntityArrow.class, DataSerializers.BYTE);
- private int xTile;
- private int yTile;
- private int zTile;
- private Block inTile;
- private int inData;
- protected boolean inGround;
- protected int timeInGround;
- /** 1 if the player can pick up the arrow */
- public EntityArrow.PickupStatus pickupStatus;
- /** Seems to be some sort of timer for animating an arrow. */
- public int arrowShake;
- /** The owner of this arrow. */
- public Entity shootingEntity;
- private int ticksInGround;
- private int ticksInAir;
- private double damage;
- /** The amount of knockback an arrow applies when it hits a mob. */
- private int knockbackStrength;
- //added by me\\
- public EntitySMGRounds(World worldIn) {
- super(worldIn);
- this.pickupStatus = EntitySMGRounds.PickupStatus.DISALLOWED;
- this.setSize(0.5F, 0.5F);
- }
- //
- public EntitySMGRounds(World worldIn, EntityLivingBase shooter) {
- super(worldIn, shooter);
- //
- {
- this.shootingEntity = shooter;
- if (shooter instanceof EntityPlayer)
- {
- this.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
- }
- }
- //
- }
- public EntitySMGRounds(World worldIn, double x, double y, double z) {
- super(worldIn, x, y, z);
- }
- @Override
- public void setDamage(double damageIn) {
- super.setDamage(4.5D);
- }
- @Override
- public void onUpdate() {
- super.onUpdate();
- if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
- {
- float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
- this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
- this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
- this.prevRotationYaw = this.rotationYaw;
- this.prevRotationPitch = this.rotationPitch;
- }
- BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
- IBlockState iblockstate = this.world.getBlockState(blockpos);
- Block block = iblockstate.getBlock();
- if (iblockstate.getMaterial() != Material.AIR)
- {
- AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
- if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).isVecInside(new Vec3d(this.posX, this.posY, this.posZ)))
- {
- this.inGround = true;
- }
- }
- if (this.arrowShake > 0)
- {
- --this.arrowShake;
- }
- if (this.inGround)
- {
- int j = block.getMetaFromState(iblockstate);
- if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().expandXyz(0.05D)))
- {
- this.inGround = false;
- this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
- this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
- this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
- this.ticksInGround = 0;
- this.ticksInAir = 0;
- }
- else
- {
- ++this.ticksInGround;
- if (this.ticksInGround >= 1200)
- {
- this.setDead();
- }
- }
- ++this.timeInGround;
- }
- }
- /**
- * Called when the arrow hits a block or an entity
- */
- protected void onHit(RayTraceResult raytraceResultIn) {
- super.onHit(raytraceResultIn);
- this.playSound(ModSoundEvent.impact, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
- Entity entity = raytraceResultIn.entityHit;
- if (entity != null)
- {
- float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
- int i = MathHelper.ceil((double)f * this.damage);
- if (this.getIsCritical())
- {
- i += this.rand.nextInt(i / 2 + 2);
- }
- }
- }
- @Override
- @Nonnull
- public ItemStack getArrowStack() {
- return new ItemStack(ModItems.SMGRounds);
- }
- @Override
- public void arrowHit(EntityLivingBase living) {
- super.arrowHit(living);
- this.playSound(ModSoundEvent.impact, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));//
- //added by me\\
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment