-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
BikeEntity.java
102 lines (87 loc) · 3.19 KB
/
BikeEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package software.bernie.example.entity;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.builder.ILoopType.EDefaultLoopTypes;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.util.GeckoLibUtil;
import javax.annotation.Nullable;
public class BikeEntity extends Animal implements IAnimatable {
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.bike.idle", EDefaultLoopTypes.LOOP));
return PlayState.CONTINUE;
}
public BikeEntity(EntityType<? extends Animal> type, Level worldIn) {
super(type, worldIn);
this.noCulling = true;
}
@Override
public InteractionResult mobInteract(Player player, InteractionHand hand) {
if (!this.isVehicle()) {
player.startRiding(this);
return super.mobInteract(player, hand);
}
return super.mobInteract(player, hand);
}
@Override
protected void playStepSound(BlockPos pos, BlockState blockIn) {
}
@Override
public void travel(Vec3 pos) {
if (this.isAlive()) {
if (this.isVehicle()) {
LivingEntity livingentity = (LivingEntity) this.getControllingPassenger();
this.setYRot(livingentity.getYRot());
this.yRotO = this.getYRot();
this.setXRot(livingentity.getXRot() * 0.5F);
this.setRot(this.getYRot(), this.getXRot());
this.yBodyRot = this.getYRot();
this.yHeadRot = this.yBodyRot;
float f = livingentity.xxa * 0.5F;
float f1 = livingentity.zza;
if (f1 <= 0.0F) {
f1 *= 0.25F;
}
this.setSpeed(0.3F);
super.travel(new Vec3((double) f, pos.y, (double) f1));
}
}
}
@Nullable
public Entity getControllingPassenger() {
return this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
}
@Override
public boolean isControlledByLocalInstance() {
return true;
}
@Override
public void registerControllers(AnimationData data) {
data.addAnimationController(new AnimationController<BikeEntity>(this, "controller", 0, this::predicate));
}
@Override
public AnimationFactory getFactory() {
return this.factory;
}
@Override
public AgeableMob getBreedOffspring(ServerLevel p_241840_1_, AgeableMob p_241840_2_) {
return null;
}
}