Skip to content

Commit 4929dd5

Browse files
committed
baby 判断
1 parent 2b20d03 commit 4929dd5

File tree

1 file changed

+23
-6
lines changed
  • src/main/java/org/polaris_bear/wild_wind/common/entity

1 file changed

+23
-6
lines changed

src/main/java/org/polaris_bear/wild_wind/common/entity/Firefly.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535

3636
public class Firefly extends PathfinderMob implements FlyingAnimal, GeoEntity {
3737
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
38+
3839
private static final EntityDataAccessor<Boolean> roost = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.BOOLEAN);
39-
private static final EntityDataAccessor<Boolean> baby = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.BOOLEAN);
40+
private static final EntityDataAccessor<Integer> baby = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.INT);
41+
4042
public static final RawAnimation idleRaw = RawAnimation.begin().thenLoop("idle");
4143
public static final RawAnimation babyRaw = RawAnimation.begin().thenLoop("baby");
4244
public Firefly(EntityType<? extends PathfinderMob> type, Level level) {
@@ -49,7 +51,7 @@ public Firefly(EntityType<? extends PathfinderMob> type, Level level) {
4951
protected void defineSynchedData(SynchedEntityData.Builder builder) {
5052
super.defineSynchedData(builder);
5153
builder.define(roost, false);
52-
builder.define(baby, false);
54+
builder.define(baby, 0);
5355
}
5456

5557
@Nullable
@@ -67,9 +69,24 @@ public boolean isRoost() {
6769
return this.entityData.get(roost);
6870
}
6971

70-
public boolean isBaby() { return this.entityData.get(baby); }
71-
public void setBaby(boolean b) {this.entityData.set(baby, b);}
72+
@Override
73+
public boolean isBaby() {
74+
return this.entityData.get(baby) < 300;
75+
}
7276

77+
public int getBaby() {
78+
return this.entityData.get(baby);
79+
}
80+
81+
public void setBaby(int b) {this.entityData.set(baby, b);}
82+
83+
@Override
84+
public void tick() {
85+
super.tick();
86+
if (isBaby()) {
87+
setBaby(getBaby()+1);
88+
}
89+
}
7390

7491
@Override
7592
public boolean canBeLeashed() {
@@ -80,14 +97,14 @@ public boolean canBeLeashed() {
8097
public void readAdditionalSaveData(CompoundTag compound) {
8198
super.readAdditionalSaveData(compound);
8299
this.setRoost(compound.getBoolean("roost"));
83-
this.setBaby(compound.getBoolean("baby"));
100+
this.setBaby(compound.getInt("baby"));
84101
}
85102

86103
@Override
87104
public void addAdditionalSaveData(CompoundTag compound) {
88105
super.addAdditionalSaveData(compound);
89106
compound.putBoolean("roost", isRoost());
90-
compound.putBoolean("baby", isBaby());
107+
compound.putInt("baby", getBaby());
91108
}
92109

93110
@Override

0 commit comments

Comments
 (0)