Skip to content

Commit

Permalink
Chicken egg timer reduction via Drum of the Gathering
Browse files Browse the repository at this point in the history
- if more than 30 seconds remaining to next egg, the time is reduced by 50% (but not below 30 seconds)
- if less than 10 seconds remaining, chicken gets startled and lays its egg prematurely
- nothing happens between 10 and 30 seconds remaining
  • Loading branch information
TheRealWormbo committed Jun 30, 2024
1 parent 105a89b commit 6068b4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.Shearable;
import net.minecraft.world.entity.animal.Chicken;
import net.minecraft.world.entity.animal.MushroomCow;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.Item;
Expand All @@ -39,6 +40,7 @@
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.common.item.HornItem;
import vazkii.botania.common.lib.BotaniaTags;
import vazkii.botania.mixin.LivingEntityAccessor;
import vazkii.botania.mixin.MushroomCowAccessor;

import java.util.ArrayList;
Expand All @@ -49,6 +51,8 @@ public class DrumBlock extends BotaniaWaterloggedBlock {

public static final int MAX_NUM_SHEARED = 4;
public static final int GATHER_RANGE = 10;
public static final int MINIMUM_REMAINING_EGG_TIME = 600;
public static final int STARTLED_EGG_TIME = 200;

public enum Variant {
WILD,
Expand Down Expand Up @@ -76,6 +80,9 @@ public static void gatherProduce(Level world, BlockPos pos) {
List<Shearable> shearables = new ArrayList<>();

for (Mob mob : mobs) {
if (mob instanceof Chicken chicken && !chicken.isBaby() && !chicken.isChickenJockey()) {
speedUpEggLaying(chicken);
}
if (mob.getType().is(BotaniaTags.Entities.DRUM_MILKABLE) && !mob.isBaby()) {
convertNearby(mob, Items.BUCKET, Items.MILK_BUCKET);
}
Expand Down Expand Up @@ -103,6 +110,15 @@ public static void gatherProduce(Level world, BlockPos pos) {
}
}

private static void speedUpEggLaying(Chicken chicken) {
if (chicken.eggTime > MINIMUM_REMAINING_EGG_TIME) {
chicken.eggTime = Math.max(MINIMUM_REMAINING_EGG_TIME, chicken.eggTime / 2);
} else if (chicken.eggTime < STARTLED_EGG_TIME && chicken.eggTime > 1) {
chicken.eggTime = 1;
((LivingEntityAccessor) chicken).botania_playHurtSound(chicken.damageSources().magic());
}
}

private static void convertNearby(Mob mob, Item from, Item to) {
Level world = mob.level();
List<ItemEntity> fromEntities = world.getEntitiesOfClass(ItemEntity.class, mob.getBoundingBox(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
*/
package vazkii.botania.mixin;

import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(LivingEntity.class)
public interface LivingEntityAccessor {
@Accessor
void setUseItemRemaining(int ticks);

@Invoker("playHurtSound")
void botania_playHurtSound(DamageSource damageSource);
}

0 comments on commit 6068b4f

Please sign in to comment.