Skip to content

Commit 8998e6d

Browse files
Implement egg count and laying mechanics in ChickenCoopEntity
Added egg count functionality to ChickenCoopEntity, allowing it to store and manage eggs laid by chickens during night mode.
1 parent 23fe127 commit 8998e6d

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/java/com/tcm/MineTale/block/entity/ChickenCoopEntity.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
public class ChickenCoopEntity extends BlockEntity {
3535
private final List<CompoundTag> storedChickensNbt = new ArrayList<>();
3636
private boolean isNightMode = false;
37+
private int eggCount = 0;
38+
private static final int MAX_EGGS = 16; // Limit storage so it's not infinite
3739

3840
public ChickenCoopEntity(BlockPos pos, BlockState state) {
3941
super(ModBlockEntities.CHICKEN_COOP_BE, pos, state);
@@ -55,6 +57,28 @@ public static void tick(Level level, BlockPos pos, BlockState state, ChickenCoop
5557
be.isNightMode = false;
5658
be.setChanged();
5759
}
60+
61+
// If it's night and we have chickens inside, try to lay eggs
62+
if (be.isNightMode && !be.storedChickensNbt.isEmpty() && be.eggCount < MAX_EGGS) {
63+
// Minecraft chickens lay eggs every 6000-12000 ticks.
64+
// With up to 6 chickens, a 1 in 1000 chance per tick is roughly realistic.
65+
if (level.random.nextInt(1000) < be.storedChickensNbt.size()) {
66+
be.eggCount++;
67+
be.setChanged();
68+
// Optional: Play a muffled chicken sound from inside the coop
69+
level.playSound(null, pos, SoundEvents.CHICKEN_EGG, SoundSource.BLOCKS, 0.5f, 1.0f);
70+
}
71+
}
72+
}
73+
74+
// Helper for the player to interact
75+
public int takeEgg() {
76+
if (eggCount > 0) {
77+
eggCount--;
78+
setChanged();
79+
return 1;
80+
}
81+
return 0;
5882
}
5983

6084
private void collectChickens(ServerLevel level, BlockPos pos) {
@@ -331,4 +355,4 @@ public ValueInput childOrEmpty(String key) {
331355
};
332356
}
333357
}
334-
}
358+
}

0 commit comments

Comments
 (0)