Skip to content

Commit

Permalink
[FIX] Butterfly chrysalises will now spawn in the correct position.
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-bok committed Oct 28, 2023
1 parent 1134236 commit 5c6fc4c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public static void registerCreativeTabContents(BuildCreativeModeTabContentsEvent
event.accept(BUTTERFLY_LONGWING_EGG);
event.accept(BUTTERFLY_CLIPPER_EGG);
event.accept(BUTTERFLY_BUCKEYE_EGG);

event.accept(CATERPILLAR_MORPHO_EGG);
event.accept(CATERPILLAR_FORESTER_EGG);
event.accept(CATERPILLAR_COMMON_EGG);
Expand All @@ -223,6 +224,7 @@ public static void registerCreativeTabContents(BuildCreativeModeTabContentsEvent
event.accept(CATERPILLAR_LONGWING_EGG);
event.accept(CATERPILLAR_CLIPPER_EGG);
event.accept(CATERPILLAR_BUCKEYE_EGG);

event.accept(ADMIRAL_BUTTERFLY_EGG);
event.accept(BUCKEYE_BUTTERFLY_EGG);
event.accept(CABBAGE_BUTTERFLY_EGG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,12 @@ protected void customServerAiStep() {
String encodeId = this.getEncodeId();
if (encodeId != null) {
String[] splitEncodeId = encodeId.split("_");
Chrysalis.spawn((ServerLevel) this.level(), splitEncodeId[0], this.blockPosition(),
this.getSurfaceDirection(), this.getYRot());
Chrysalis.spawn((ServerLevel) this.level(),
splitEncodeId[0],
this.getSurfaceBlock(),
this.getSurfaceDirection(),
this.position(),
this.getYRot());
this.remove(RemovalReason.DISCARDED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -243,14 +244,18 @@ public static Chrysalis createSwallowtail(EntityType<? extends Chrysalis> entity

/**
* Spawns a chrysalis into the world.
*
* @param entityId The type of chrysalis to release.
* @param position The current position of the player.
* @param level The level to spawn the chrysalis.
* @param entityId The Entity ID of the chrysalis to spawn.
* @param spawnBlock The block to spawn the chrysalis on.
* @param surfaceDirection The direction the chrysalis is facing.
* @param position The position of the chrysalis.
* @param yRotation The y-rotation of the chrysalis.
*/
public static void spawn(ServerLevel level,
String entityId,
BlockPos position,
Direction direction,
BlockPos spawnBlock,
Direction surfaceDirection,
Vec3 position,
float yRotation) {

ResourceLocation key = new ResourceLocation(entityId + "_chrysalis");
Expand All @@ -259,28 +264,14 @@ public static void spawn(ServerLevel level,
if (entityType != null) {
Entity entity = entityType.create(level);
if (entity instanceof Chrysalis chrysalis) {
BlockPos spawnPosition;
if (direction == Direction.DOWN) {
spawnPosition = position.below();
} else if (direction == Direction.UP) {
spawnPosition = position.above();
} else if (direction == Direction.NORTH) {
spawnPosition = position.north();
} else if (direction == Direction.SOUTH) {
spawnPosition = position.south();
} else if (direction == Direction.WEST) {
spawnPosition = position.west();
} else {
spawnPosition = position.east();
}

chrysalis.moveTo(position, 0.0F, 0.0F);

chrysalis.moveTo(position.x, position.y, position.z, 0.0F, 0.0F);
chrysalis.setYRot(yRotation);
chrysalis.setSurfaceDirection(direction);
chrysalis.setSurfaceBlock(spawnPosition);
chrysalis.setSurfaceDirection(surfaceDirection);
chrysalis.setSurfaceBlock(spawnBlock);

chrysalis.finalizeSpawn(level,
level.getCurrentDifficultyAt(position),
level.getCurrentDifficultyAt(spawnBlock),
MobSpawnType.NATURAL,
null,
null);
Expand Down Expand Up @@ -345,7 +336,7 @@ protected void customServerAiStep() {
kill();
}

// Spawn Chrysalis.
// Spawn Butterfly.
if (this.getAge() > 24000 && this.random.nextInt(0, 15) == 0) {
String encodeId = this.getEncodeId();
if (encodeId != null) {
Expand Down

0 comments on commit 5c6fc4c

Please sign in to comment.