|
| 1 | +package org.teneted.neotenet.mixin.world.entity.animal; |
| 2 | + |
| 3 | +import net.minecraft.core.BlockPos; |
| 4 | +import net.minecraft.sounds.SoundEvents; |
| 5 | +import net.minecraft.sounds.SoundSource; |
| 6 | +import net.minecraft.world.entity.PathfinderMob; |
| 7 | +import net.minecraft.world.entity.ai.goal.MoveToBlockGoal; |
| 8 | +import net.minecraft.world.entity.ai.util.DefaultRandomPos; |
| 9 | +import net.minecraft.world.entity.animal.Turtle; |
| 10 | +import net.minecraft.world.level.Level; |
| 11 | +import net.minecraft.world.level.block.Blocks; |
| 12 | +import net.minecraft.world.level.block.TurtleEggBlock; |
| 13 | +import net.minecraft.world.level.block.state.BlockState; |
| 14 | +import net.minecraft.world.level.gameevent.GameEvent; |
| 15 | +import net.minecraft.world.phys.Vec3; |
| 16 | +import org.spongepowered.asm.mixin.Final; |
| 17 | +import org.spongepowered.asm.mixin.Mixin; |
| 18 | +import org.spongepowered.asm.mixin.Overwrite; |
| 19 | +import org.spongepowered.asm.mixin.Shadow; |
| 20 | + |
| 21 | +@Mixin(targets = "net.minecraft.world.entity.animal.Turtle.TurtleLayEggGoal") |
| 22 | +public abstract class MixinTurtle_TurtleLayEggGoal extends MoveToBlockGoal { |
| 23 | + |
| 24 | + @Shadow |
| 25 | + @Final |
| 26 | + private Turtle turtle; |
| 27 | + |
| 28 | + public MixinTurtle_TurtleLayEggGoal(PathfinderMob p_25609_, double p_25610_, int p_25611_) { |
| 29 | + super(p_25609_, p_25610_, p_25611_); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @author wdog5 |
| 34 | + * @reason bukkit |
| 35 | + */ |
| 36 | + @Overwrite |
| 37 | + public void tick() { |
| 38 | + super.tick(); |
| 39 | + BlockPos blockpos = this.turtle.blockPosition(); |
| 40 | + if (!this.turtle.isInWater() && this.isReachedTarget()) { |
| 41 | + if (this.turtle.layEggCounter < 1) { |
| 42 | + this.turtle.setLayingEgg(true); |
| 43 | + } else if (this.turtle.layEggCounter > this.adjustedTickDelay(200)) { |
| 44 | + Level level = this.turtle.level(); |
| 45 | + if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.turtle, this.blockPos.above(), (BlockState) Blocks.TURTLE_EGG.defaultBlockState().setValue(TurtleEggBlock.EGGS, this.turtle.random.nextInt(4) + 1))) { // CraftBukkit |
| 46 | + level.playSound(null, blockpos, SoundEvents.TURTLE_LAY_EGG, SoundSource.BLOCKS, 0.3F, 0.9F + level.random.nextFloat() * 0.2F); |
| 47 | + BlockPos blockpos1 = this.blockPos.above(); |
| 48 | + BlockState blockstate = Blocks.TURTLE_EGG |
| 49 | + .defaultBlockState() |
| 50 | + .setValue(TurtleEggBlock.EGGS, Integer.valueOf(this.turtle.random.nextInt(4) + 1)); |
| 51 | + level.setBlock(blockpos1, blockstate, 3); |
| 52 | + level.gameEvent(GameEvent.BLOCK_PLACE, blockpos1, GameEvent.Context.of(this.turtle, blockstate)); |
| 53 | + } |
| 54 | + this.turtle.setHasEgg(false); |
| 55 | + this.turtle.setLayingEgg(false); |
| 56 | + this.turtle.setInLoveTime(600); |
| 57 | + } |
| 58 | + |
| 59 | + if (this.turtle.isLayingEgg()) { |
| 60 | + this.turtle.layEggCounter++; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments