Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void tickCollisionEntities() {
- boolean volleyBallTest = true;
- float triggerDist = 4.0F;
- if (volleyBallTest) {
- double size = 1D;
- List entities = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(size, size, size));
- for (int i = 0; entities != null && i < entities.size(); ++i)
- {
- Entity var10 = (Entity)entities.get(i);
- if (var10 != null) {
- if (!var10.isDead) {
- if (var10 instanceof EntityPlayer) {
- EntityPlayer entP = (EntityPlayer)var10;
- if (entP.swingProgress > 0.2F) {
- double speed = Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
- System.out.println("dist: " + var10.getDistanceToEntity(this));
- if (var10.getDistanceToEntity(this) < triggerDist) {
- System.out.println("hit ball!");
- hitEvent(this, var10);
- }
- }
- }
- }
- }
- }
- }
- }
- public void hitEvent(Entity ball, Entity player) {
- float hitPower = 0.5F;
- double vecX = ball.posX - player.posX;
- double vecY = ball.posY - player.posY;
- double vecZ = ball.posZ - player.posZ;
- Vec3 vecBallToPlayer = Vec3.createVectorHelper(vecX, vecY, vecZ).normalize();
- Vec3 vecThrust = getHitAim(player).normalize();
- //invert z to fix things
- vecThrust.zCoord *= -1;
- vecThrust.xCoord *= hitPower;
- vecThrust.yCoord *= hitPower;
- vecThrust.zCoord *= hitPower;
- ball.motionX = vecThrust.xCoord;
- ball.motionY = vecThrust.yCoord;
- ball.motionZ = vecThrust.zCoord;
- //more adjustments
- ball.motionY += 0.3F;
- }
- public Vec3 getHitAim(Entity ent) {
- float f1 = MathHelper.cos(ent.rotationYaw * 0.017453292F/* - (float)Math.PI*/);
- float f2 = MathHelper.sin(ent.rotationYaw * 0.017453292F/* - (float)Math.PI*/);
- float f3 = -MathHelper.cos(-ent.rotationPitch * 0.017453292F);
- float f4 = MathHelper.sin(-ent.rotationPitch * 0.017453292F);
- return Vec3.createVectorHelper((double)(f2 * f3), (double)f4, (double)(f1 * f3));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement