Skip to content

Commit eef2134

Browse files
committed
更新
1 parent 8c6ff70 commit eef2134

12 files changed

+124
-75
lines changed

build.gradle

+12-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ if (!jijg.isEmpty()) {
8888
dependencies {
8989
compileOnly(project(":annotation"))
9090
annotationProcessor(project(":processor"))
91-
9291
compileOnly(libs.bundles.linkage)
9392
runtimeOnly(libs.bundles.linkage)
9493
implementation(jij)
@@ -116,9 +115,14 @@ var generateModMetadata = tasks.register("generateModMetadata", ProcessResources
116115
from "src/main/templates"
117116
into "build/generated/sources/modMetadata"
118117
}
118+
def at = file("src/main/resources/META-INF/accesstransformer.cfg")
119119

120120
sourceSets.main.resources.srcDir generateModMetadata
121121
neoForge.ideSyncTask generateModMetadata
122+
if (at.readBytes().length != 0) {
123+
neoForge.setAccessTransformers(at)
124+
}
125+
122126

123127
publishing {
124128
publications {
@@ -133,9 +137,15 @@ publishing {
133137
}
134138
}
135139

140+
jar {
141+
exclude(".cache")
142+
if (at.readBytes().length == 0) {
143+
exclude("META-INF/accesstransformer.cfg")
144+
}
145+
}
146+
136147
tasks.withType(JavaCompile).configureEach {
137148
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
138-
exclude(".cache/**")
139149
}
140150

141151
if (!jijg.isEmpty()) {

src/main/java/org/polaris_bear/wild_wind/client/model/FireflyModel.java

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public ResourceLocation getModelResource(Firefly animatable) {
2626
*/
2727
@Override
2828
public ResourceLocation getTextureResource(Firefly animatable) {
29+
if (animatable.getLastHurtByMob() == null) {
30+
return Helpers.location("textures/entity/firefly_glow.png");
31+
}
2932
return Helpers.location("textures/entity/firefly.png");
3033
}
3134

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

+54-30
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import net.minecraft.network.syncher.EntityDataAccessor;
77
import net.minecraft.network.syncher.EntityDataSerializers;
88
import net.minecraft.network.syncher.SynchedEntityData;
9-
import net.minecraft.world.DifficultyInstance;
9+
import net.minecraft.server.level.ServerLevel;
1010
import net.minecraft.world.InteractionHand;
1111
import net.minecraft.world.InteractionResult;
1212
import net.minecraft.world.damagesource.DamageSource;
@@ -18,17 +18,21 @@
1818
import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation;
1919
import net.minecraft.world.entity.ai.navigation.PathNavigation;
2020
import net.minecraft.world.entity.ambient.AmbientCreature;
21+
import net.minecraft.world.entity.animal.Animal;
2122
import net.minecraft.world.entity.animal.FlyingAnimal;
2223
import net.minecraft.world.entity.player.Player;
24+
import net.minecraft.world.item.ItemStack;
2325
import net.minecraft.world.level.Level;
24-
import net.minecraft.world.level.ServerLevelAccessor;
2526
import net.minecraft.world.level.block.state.BlockState;
2627
import org.jetbrains.annotations.NotNull;
2728
import org.jetbrains.annotations.Nullable;
28-
import org.polaris_bear.wild_wind.WildWindConfig;
29+
import org.polaris_bear.wild_wind.WildWindMod;
2930
import org.polaris_bear.wild_wind.common.entity.goal.FireflyBaseGoal;
3031
import org.polaris_bear.wild_wind.common.entity.goal.FireflyFlyGoal;
3132
import org.polaris_bear.wild_wind.common.entity.goal.FireflyRoostGoal;
33+
import org.polaris_bear.wild_wind.common.entity.goal.FireflyGlowGoal;
34+
import org.polaris_bear.wild_wind.common.init.ModEntities;
35+
import org.polaris_bear.wild_wind.common.init.tags.ModItemTags;
3236
import software.bernie.geckolib.animatable.GeoEntity;
3337
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
3438
import software.bernie.geckolib.animation.*;
@@ -37,59 +41,72 @@
3741

3842
import java.util.List;
3943

40-
public class Firefly extends PathfinderMob implements FlyingAnimal, GeoEntity {
44+
public class Firefly extends Animal implements FlyingAnimal, GeoEntity {
4145
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
4246

47+
private static final EntityDimensions BABY_DIMENSIONS = ModEntities.FIREFLY.get().getDimensions().scale(0.5f).withEyeHeight(0.2975F);
48+
4349
private static final EntityDataAccessor<Boolean> ROOST = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.BOOLEAN);
44-
private static final EntityDataAccessor<Integer> BABY = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.INT);
50+
private static final EntityDataAccessor<Integer> TICKER = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.INT);
4551

4652
public static final RawAnimation IDLE_RAW = RawAnimation.begin().thenLoop("idle");
4753
public static final RawAnimation BABY_RAW = RawAnimation.begin().thenLoop("baby");
48-
public Firefly(EntityType<? extends PathfinderMob> type, Level level) {
54+
public Firefly(EntityType<? extends Animal> type, Level level) {
4955
super(type, level);
5056
this.moveControl = new FlyingMoveControl(this, 20, true);
5157
this.xpReward = getRandom().nextInt(3) + 1;
58+
5259
}
5360

5461
@Override
55-
protected void defineSynchedData(SynchedEntityData.Builder builder) {
56-
super.defineSynchedData(builder);
57-
builder.define(ROOST, false);
58-
builder.define(BABY, 0);
62+
protected @NotNull EntityDimensions getDefaultDimensions(@NotNull Pose pose) {
63+
return isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
5964
}
6065

6166
@Nullable
6267
@Override
63-
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
68+
public AgeableMob getBreedOffspring(@NotNull ServerLevel serverLevel, @NotNull AgeableMob ageableMob) {
69+
return ModEntities.FIREFLY.get().create(serverLevel);
70+
}
71+
72+
@Override
73+
protected void defineSynchedData(SynchedEntityData.@NotNull Builder builder) {
74+
super.defineSynchedData(builder);
75+
builder.define(ROOST, false);
76+
builder.define(TICKER, 0);
77+
6478

65-
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
6679
}
6780

81+
82+
6883
public void setRoost(boolean r) {
6984
this.entityData.set(ROOST, r);
7085
}
7186

72-
public boolean isRoost() {
73-
return this.entityData.get(ROOST);
74-
}
87+
public void setTicker(int ticker) { this.entityData.set(TICKER, ticker); }
7588

76-
@Override
77-
public boolean isBaby() {
78-
return this.entityData.get(BABY) < WildWindConfig.firefly_age;
89+
public int getTicker() { return this.entityData.get(TICKER); }
90+
91+
public boolean isTicker() {
92+
if (getTicker() < 600) {
93+
addTicker();
94+
return true;
95+
}
96+
return false;
7997
}
8098

81-
public int getBaby() {
82-
return this.entityData.get(BABY);
99+
public void addTicker() { this.entityData.set(TICKER, this.entityData.get(TICKER)+1); }
100+
public void clearTicker() { this.entityData.set(TICKER, 0); }
101+
102+
public boolean isRoost() {
103+
return this.entityData.get(ROOST);
83104
}
84105

85-
public void setBaby(int b) {this.entityData.set(BABY, b);}
86106

87107
@Override
88108
public void tick() {
89109
super.tick();
90-
if (isBaby()) {
91-
setBaby(getBaby()+1);
92-
}
93110
}
94111

95112
@Override
@@ -101,18 +118,23 @@ public boolean canBeLeashed() {
101118
public void readAdditionalSaveData(@NotNull CompoundTag compound) {
102119
super.readAdditionalSaveData(compound);
103120
this.setRoost(compound.getBoolean("roost"));
104-
this.setBaby(compound.getInt("baby"));
121+
this.setTicker(compound.getInt("ticker"));
122+
}
123+
124+
@Override
125+
public boolean isFood(ItemStack itemStack) {
126+
return itemStack.is(ModItemTags.FIREFLY_FOOD.get());
105127
}
106128

107129
@Override
108-
public void addAdditionalSaveData(CompoundTag compound) {
130+
public void addAdditionalSaveData(@NotNull CompoundTag compound) {
109131
super.addAdditionalSaveData(compound);
110132
compound.putBoolean("roost", isRoost());
111-
compound.putInt("baby", getBaby());
133+
compound.putInt("ticker", getTicker());
112134
}
113135

114136
@Override
115-
protected PathNavigation createNavigation(Level level) {
137+
protected @NotNull PathNavigation createNavigation(@NotNull Level level) {
116138
FlyingPathNavigation flyingPathNavigation = new FlyingPathNavigation(this, level) {
117139
@Override
118140
public boolean isStableDestination(BlockPos pos) {
@@ -143,7 +165,8 @@ protected void checkFallDamage(double y, boolean onGround, BlockState state, Blo
143165
.of(
144166
FireflyBaseGoal::new,
145167
FireflyFlyGoal::new,
146-
FireflyRoostGoal::new
168+
FireflyRoostGoal::new,
169+
FireflyGlowGoal::new
147170
);
148171
@Override
149172
protected void registerGoals() {
@@ -153,14 +176,15 @@ protected void registerGoals() {
153176
}
154177

155178
@Override
156-
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
179+
public InteractionResult mobInteract(Player player, InteractionHand hand) {
157180
return super.mobInteract(player, hand);
158181
}
159182

160183
public static AttributeSupplier createAttributes() {
161184
return AmbientCreature.createMobAttributes()
162185
.add(Attributes.MAX_HEALTH, 8f)
163186
.add(Attributes.FLYING_SPEED, 0.6f)
187+
.add(Attributes.GRAVITY, 0.0f)
164188
.build();
165189
}
166190

src/main/java/org/polaris_bear/wild_wind/common/entity/goal/FireflyBaseGoal.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import net.minecraft.world.entity.ai.goal.Goal;
44
import org.polaris_bear.wild_wind.common.entity.Firefly;
55

6+
67
public class FireflyBaseGoal extends Goal {
78

89
public final Firefly firefly;
910

10-
public FireflyBaseGoal(Firefly Firefly) {
11-
this.firefly = Firefly;
11+
public FireflyBaseGoal(Firefly firefly) {
12+
this.firefly = firefly;
1213
}
1314

1415
@Override

src/main/java/org/polaris_bear/wild_wind/common/entity/goal/FireflyFlyGoal.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@
55

66
public class FireflyFlyGoal extends FireflyBaseGoal {
77

8-
public FireflyFlyGoal(Firefly Firefly) {
9-
super(Firefly);
8+
public FireflyFlyGoal(Firefly firefly) {
9+
super(firefly);
1010
}
1111

1212
@Override
1313
public void tick() {
1414
super.tick();
15-
}
1615

17-
private void checkMovement() {
18-
Vec3 vec3 = firefly.getDeltaMovement();
19-
if (Math.abs(vec3.x) > 0.1 || Math.abs(vec3.z) > 0.1) {
20-
double d = Math.abs(firefly.xo - firefly.getX());
21-
if (d < 0.1)
22-
firefly.getNavigation().stop();
23-
}
2416
}
2517

18+
19+
2620
@Override
2721
public boolean canUse() {
2822
if (firefly.isFlying()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.polaris_bear.wild_wind.common.entity.goal;
2+
3+
import org.polaris_bear.wild_wind.common.entity.Firefly;
4+
5+
public class FireflyGlowGoal extends FireflyBaseGoal {
6+
7+
public FireflyGlowGoal(Firefly firefly) {
8+
super(firefly);
9+
}
10+
11+
@Override
12+
public void tick() {
13+
if (firefly.isTicker()) {
14+
firefly.clearTicker();
15+
firefly.setLastHurtByMob(null);
16+
}
17+
}
18+
19+
@Override
20+
public boolean canUse() {
21+
return firefly.getLastHurtByMob() != null;
22+
}
23+
}

src/main/java/org/polaris_bear/wild_wind/common/entity/goal/FireflyRoostGoal.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class FireflyRoostGoal extends FireflyFlyGoal{
88

9-
public FireflyRoostGoal(Firefly Firefly) {
10-
super(Firefly);
9+
public FireflyRoostGoal(Firefly firefly) {
10+
super(firefly);
1111
}
1212

1313
@Override

src/main/java/org/polaris_bear/wild_wind/datagen/ModDataGenerator.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.polaris_bear.wild_wind.WildWindMod;
77
import org.polaris_bear.wild_wind.datagen.lang.ModLangProviderEn;
88
import org.polaris_bear.wild_wind.datagen.lang.ModLangProviderZh;
9+
import org.polaris_bear.wild_wind.datagen.lang.ModLangProviderZhTw;
910
import org.polaris_bear.wild_wind.datagen.tag.ModBlockTagsProvider;
1011
import org.polaris_bear.wild_wind.datagen.tag.ModEntityTypeTagsProvider;
1112
import org.polaris_bear.wild_wind.datagen.tag.ModItemTagsProvider;
@@ -21,6 +22,7 @@ public static void gatherData(GatherDataEvent event) {
2122
var helper = event.getExistingFileHelper();
2223
gen.addProvider(event.includeClient(), new ModLangProviderEn(pack));
2324
gen.addProvider(event.includeClient(), new ModLangProviderZh(pack));
25+
gen.addProvider(event.includeClient(), new ModLangProviderZhTw(pack));
2426
gen.addProvider(event.includeClient(), new ModItemModelProvider(pack, helper));
2527
gen.addProvider(event.includeServer(), new ModEntityTypeTagsProvider(pack, provider, helper));
2628
ModBlockTagsProvider blockTagsProvider = new ModBlockTagsProvider(pack, provider, helper);

src/main/java/org/polaris_bear/wild_wind/datagen/lang/ModLangProviderZh.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public ModLangProviderZh(PackOutput output) {
1414

1515
@Override
1616
protected void addTranslations() {
17-
add(ModItems.FIREFLY_SPAWN_EGG.get(), "生成萤火虫");
17+
add(ModItems.FIREFLY_SPAWN_EGG.get(), "萤火虫刷怪蛋");
1818
add(ModEntities.FIREFLY.get(), "萤火虫");
1919
}
2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.polaris_bear.wild_wind.datagen.lang;
2+
3+
import net.minecraft.data.PackOutput;
4+
import net.neoforged.neoforge.common.data.LanguageProvider;
5+
import org.polaris_bear.wild_wind.WildWindMod;
6+
import org.polaris_bear.wild_wind.common.init.ModEntities;
7+
import org.polaris_bear.wild_wind.common.init.ModItems;
8+
9+
public class ModLangProviderZhTw extends LanguageProvider {
10+
11+
public ModLangProviderZhTw(PackOutput output) {
12+
super(output, WildWindMod.MOD_ID, "zh_cn");
13+
}
14+
15+
@Override
16+
protected void addTranslations() {
17+
add(ModItems.FIREFLY_SPAWN_EGG.get(), "螢火蟲刷怪蛋");
18+
add(ModEntities.FIREFLY.get(), "螢火蟲");
19+
}
20+
}

src/main/java/org/polaris_bear/wild_wind/test/Test1.java

-14
This file was deleted.

src/main/java/org/polaris_bear/wild_wind/test/WildWindGameTest.java

-14
This file was deleted.

0 commit comments

Comments
 (0)