2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.EquinePredicates;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityType;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class RacingCloudEntity extends CloudEntity {
|
|
|
|
|
|
|
|
public RacingCloudEntity(EntityType<RacingCloudEntity> type, World world) {
|
|
|
|
super(type, world);
|
|
|
|
setCloudSize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBeControlledByRider() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canAddPassenger(Entity passenger) {
|
|
|
|
return getPassengerList().size() < getCloudSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public Entity getPrimaryPassenger() {
|
|
|
|
List<Entity> list = getPassengerList();
|
|
|
|
return list.isEmpty() ? null : list.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
|
|
|
|
if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) {
|
2020-04-26 14:46:03 +02:00
|
|
|
if (EquinePredicates.PLAYER_PEGASUS.test(player)) {
|
2020-01-27 11:05:22 +01:00
|
|
|
if (!getStationary()) {
|
|
|
|
player.startRiding(this);
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ActionResult.FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tick() {
|
|
|
|
Entity jockey = getPrimaryPassenger();
|
|
|
|
|
|
|
|
Vec3d vel = getVelocity();
|
|
|
|
double motionX = vel.x;
|
|
|
|
double motionY = vel.y;
|
|
|
|
double motionZ = vel.z;
|
|
|
|
|
|
|
|
if (jockey != null && canBeControlledByRider()) {
|
|
|
|
LivingEntity rider = (LivingEntity)jockey;
|
|
|
|
|
|
|
|
double speed = 1.5F * rider.forwardSpeed / 5;
|
|
|
|
double horizontalDriving = (jockey.yaw - rider.sidewaysSpeed * 90) * Math.PI / 180;
|
|
|
|
|
|
|
|
motionX += -Math.sin(horizontalDriving) * speed;
|
|
|
|
motionZ += Math.cos(horizontalDriving) * speed;
|
|
|
|
|
|
|
|
double pitch = jockey.pitch * Math.PI / 180;
|
|
|
|
|
|
|
|
motionY += -Math.sin(pitch) * (speed / 20);
|
|
|
|
} else {
|
|
|
|
motionY = 0;
|
|
|
|
}
|
|
|
|
setVelocity(motionX, motionY, motionZ);
|
|
|
|
|
|
|
|
super.tick();
|
|
|
|
}
|
|
|
|
}
|