Skip to content

Commit

Permalink
popom eat flower
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Jan 19, 2025
1 parent aa1286d commit e544acb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public void render(MatrixStack matrices, VertexConsumer vertices, int light, int
float f = 0.5F;
matrices.scale(f, f, f);
matrices.translate(0.0F, 1.6F, 0.0F);
this.getFurs()[2].render(matrices, vertices, light, overlay, color);
this.getFurs()[1].render(matrices, vertices, light, overlay, color);
matrices.pop();
} else {
this.getFurs()[furSize].render(matrices, vertices, light, overlay, color);
this.getFurs()[Math.min(3, furSize)].render(matrices, vertices, light, overlay, color);
}
}

Expand Down
86 changes: 86 additions & 0 deletions src/main/java/net/id/paradiselost/entities/ai/EatFlowersGoal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package net.id.paradiselost.entities.ai;

import net.id.paradiselost.entities.passive.PopomEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.ai.goal.MoveToTargetPosGoal;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.WorldEvents;
import net.minecraft.world.WorldView;

public class EatFlowersGoal extends MoveToTargetPosGoal {
private final PopomEntity goober;
private final World world;
private int timer;
private boolean eating;

public EatFlowersGoal(PopomEntity goober, double speed) {
super(goober, speed, 8, 3);
this.goober = goober;
this.world = goober.getWorld();
this.eating = false;
}

@Override
public boolean canStart() {
return this.goober.getFurSize() < 3 && super.canStart(); //this.cat.isTamed() && !this.cat.isSitting() && super.canStart();
}

@Override
public void stop() {
super.stop();
this.timer = 0;
this.eating = false;
}

@Override
public double getDesiredDistanceToTarget() {
return 1.4;
}

public int getTimer() {
return this.timer;
}

@Override
public void tick() {
super.tick();
this.timer = Math.max(0, this.timer - 1);
if (this.hasReached() && !this.eating) {
this.timer = this.getTickCount(40);
this.eating = true;
this.world.sendEntityStatus(this.mob, EntityStatuses.SET_SHEEP_EAT_GRASS_TIMER_OR_PRIME_TNT_MINECART);
}
if (this.timer == this.getTickCount(4)) {
BlockPos pos = null;
for (int x = -1; x < 2; x++) {
for (int z = -1; z < 2; z++) {
for (int y = -1; y < 2; y++) {
if (world.getBlockState(goober.getBlockPos().add(x, y, z)).isIn(BlockTags.SMALL_FLOWERS)) {
pos = goober.getBlockPos().add(x, y, z);
}
}
}
}
if (pos != null) {
if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) {
this.world.syncWorldEvent(WorldEvents.BLOCK_BROKEN, pos, Block.getRawIdFromState(world.getBlockState(pos)));
this.world.setBlockState(pos, Blocks.AIR.getDefaultState(), Block.NOTIFY_LISTENERS);
}
this.goober.eat();
this.stop();
}
}
}

@Override
protected boolean isTargetPos(WorldView world, BlockPos pos) {
BlockState blockState = world.getBlockState(pos.up());
return blockState.isIn(BlockTags.SMALL_FLOWERS);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.id.paradiselost.entities.passive;

import net.id.paradiselost.entities.ai.EatFlowersGoal;
import net.id.paradiselost.tag.ParadiseLostItemTags;
import net.id.paradiselost.util.ParadiseLostSoundEvents;
import net.minecraft.client.render.entity.SheepEntityRenderer;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.goal.AnimalMateGoal;
import net.minecraft.entity.ai.goal.EscapeDangerGoal;
Expand Down Expand Up @@ -48,6 +50,7 @@ protected void initGoals() {
this.goalSelector.add(2, new AnimalMateGoal(this, 0.9));
this.goalSelector.add(3, new TemptGoal(this, 0.8, stack -> stack.isIn(ParadiseLostItemTags.MOA_TEMPTABLES), false));
this.goalSelector.add(4, new FollowParentGoal(this, 1.05));
this.goalSelector.add(5, new EatFlowersGoal(this, 0.95));
this.goalSelector.add(6, new WanderAroundFarGoal(this, 0.6));
this.goalSelector.add(7, new LookAtEntityGoal(this, PlayerEntity.class, 8.0F));
this.goalSelector.add(8, new LookAroundGoal(this));
Expand Down Expand Up @@ -104,6 +107,10 @@ public int getFurSize() {
return this.dataTracker.get(FUR_SIZE);
}

public void eat() {
this.dataTracker.set(FUR_SIZE, this.dataTracker.get(FUR_SIZE)+1);
}

static {
FUR_SIZE = DataTracker.registerData(PopomEntity.class, TrackedDataHandlerRegistry.INTEGER);
}
Expand Down

0 comments on commit e544acb

Please sign in to comment.