HyCodeYourTale
classpublicPriority 3

DirectionalKnockback

com.hypixel.hytale.server.core.modules.interaction.interaction.config.server.combat.DirectionalKnockback

extends Knockback

2

Methods

2

Public Methods

3

Fields

1

Constructors

Constants

BuilderCodec<DirectionalKnockback>CODEC= BuilderCodec.builder( DirectionalKnockback.class, DirectionalKnockback::new, Knockback.B...

Constructors

public
DirectionalKnockback()

Methods

Public Methods (2)

public
Vector3d calculateVector(Vector3d source, float yaw, Vector3d target)
@Nonnull@Override
public
String toString()
@Nonnull@Override

Fields

Protected Fields (3)

protectedfloat relativeX
protectedfloat relativeZ
protectedfloat velocityY

Inheritance

Parent
Current
Interface
Child

Use mouse wheel to zoom, drag to pan. Click nodes to navigate.

Related Classes

Source Code

package com.hypixel.hytale.server.core.modules.interaction.interaction.config.server.combat;

import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.math.vector.Vector3d;
import javax.annotation.Nonnull;

public class DirectionalKnockback extends Knockback {
   public static final BuilderCodec<DirectionalKnockback> CODEC = BuilderCodec.builder(
         DirectionalKnockback.class, DirectionalKnockback::new, Knockback.BASE_CODEC
      )
      .append(
         new KeyedCodec<>("RelativeX", Codec.DOUBLE),
         (knockbackAttachment, d) -> knockbackAttachment.relativeX = d.floatValue(),
         knockbackAttachment -> (double)knockbackAttachment.relativeX
      )
      .add()
      .append(
         new KeyedCodec<>("VelocityY", Codec.DOUBLE),
         (knockbackAttachment, d) -> knockbackAttachment.velocityY = d.floatValue(),
         knockbackAttachment -> (double)knockbackAttachment.velocityY
      )
      .add()
      .append(
         new KeyedCodec<>("RelativeZ", Codec.DOUBLE),
         (knockbackAttachment, d) -> knockbackAttachment.relativeZ = d.floatValue(),
         knockbackAttachment -> (double)knockbackAttachment.relativeZ
      )
      .add()
      .build();
   protected float relativeX;
   protected float velocityY;
   protected float relativeZ;

   public DirectionalKnockback() {
   }

   @Nonnull
   @Override
   public Vector3d calculateVector(@Nonnull Vector3d source, float yaw, @Nonnull Vector3d target) {
      Vector3d vector = source.clone().subtract(target);
      if (vector.squaredLength() <= 1.0E-8) {
         Vector3d lookVector = new Vector3d(0.0, 0.0, -1.0);
         lookVector.rotateY(yaw);
         vector.assign(lookVector);
      } else {
         vector.normalize();
      }

      if (this.relativeX != 0.0F || this.relativeZ != 0.0F) {
         Vector3d rotation = new Vector3d((double)this.relativeX, 0.0, (double)this.relativeZ);
         rotation.rotateY(yaw);
         vector.add(rotation);
      }

      double x = vector.getX() * (double)this.force;
      double z = vector.getZ() * (double)this.force;
      double y = (double)this.velocityY;
      return new Vector3d(x, y, z);
   }

   @Nonnull
   @Override
   public String toString() {
      return "DirectionalKnockback{relativeX=" + this.relativeX + ", relativeZ=" + this.relativeZ + "}";
   }
}