diff --git a/common/src/main/java/net/satisfy/wildernature/core/entity/ai/goal/animal/RaccoonGoals.java b/common/src/main/java/net/satisfy/wildernature/core/entity/ai/goal/animal/RaccoonGoals.java index 921ab4f..ed9daf8 100644 --- a/common/src/main/java/net/satisfy/wildernature/core/entity/ai/goal/animal/RaccoonGoals.java +++ b/common/src/main/java/net/satisfy/wildernature/core/entity/ai/goal/animal/RaccoonGoals.java @@ -261,7 +261,43 @@ private void setDoorOpen(BlockPos blockPos) { doorBlock.setOpen(this.raccoon, this.raccoon.level(), blockState, blockPos, true); } } + + public static class HarvestBerryBushGoal extends MoveToBlockGoal { + private final RaccoonEntity raccoon; + + public HarvestBerryBushGoal(RaccoonEntity raccoon, double speed) { + super(raccoon, speed, 8); + this.raccoon = raccoon; + } + @Override + protected boolean isValidTarget(LevelReader level, BlockPos pos) { + BlockState state = level.getBlockState(pos); + return state.is(Blocks.SWEET_BERRY_BUSH) && state.getValue(SweetBerryBushBlock.AGE) >= 2; + } + + @Override + public void tick() { + super.tick(); + if (this.isReachedTarget()) { + BlockState state = raccoon.level().getBlockState(this.blockPos); + if (state.is(Blocks.SWEET_BERRY_BUSH) && state.getValue(SweetBerryBushBlock.AGE) >= 2) { + int dropCount = 1 + raccoon.getRandom().nextInt(2); + ItemStack berries = new ItemStack(Items.SWEET_BERRIES, dropCount); + + if (raccoon.getMainHandItem().isEmpty()) { + raccoon.setItemSlot(EquipmentSlot.MAINHAND, berries); + } else { + Block.popResource(raccoon.level(), blockPos, berries); // drop them + } + + raccoon.level().setBlock(blockPos, state.setValue(SweetBerryBushBlock.AGE, 1), 2); + raccoon.playSound(SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, 1.0F, 1.0F); + } + } + } + } + public static class RaccoonVillageStrollGoal extends Goal { private static final int SEARCH_COOLDOWN_MIN = 40; private static final int SEARCH_COOLDOWN_MAX = 90; @@ -1257,4 +1293,4 @@ private boolean isValidCrop(BlockPos blockPos) { return blockState.getValue(ageProperty) > 0; } } -} \ No newline at end of file +} diff --git a/common/src/main/java/net/satisfy/wildernature/core/entity/animal/neutral/RaccoonEntity.java b/common/src/main/java/net/satisfy/wildernature/core/entity/animal/neutral/RaccoonEntity.java index 21a51d9..80f70e3 100644 --- a/common/src/main/java/net/satisfy/wildernature/core/entity/animal/neutral/RaccoonEntity.java +++ b/common/src/main/java/net/satisfy/wildernature/core/entity/animal/neutral/RaccoonEntity.java @@ -135,19 +135,20 @@ protected void registerGoals() { this.goalSelector.addGoal(4, new RaccoonGoals.RaccoonAvoidEntityGoal<>(this, Villager.class)); this.goalSelector.addGoal(5, new RaccoonGoals.RaccoonAvoidEntityGoal<>(this, DogEntity.class)); this.goalSelector.addGoal(7, new RaccoonGoals.RaccoonDoorInteractGoal(this)); - this.goalSelector.addGoal(8, new RaccoonGoals.RaccoonWashSelfGoal(this)); - this.goalSelector.addGoal(9, new CacheStoreGoal<>(this, 1.15D)); - this.goalSelector.addGoal(10, new CacheEatGoal<>(this, 1.15D)); - this.goalSelector.addGoal(11, new RaccoonGoals.RaccoonOpenContainerGoal(this, 1.2D)); - this.goalSelector.addGoal(12, new RaccoonGoals.RaccoonNibbleCropGoal(this, 1.15D)); - this.goalSelector.addGoal(13, new RaccoonGoals.RaccoonStealEggGoal(this, 1.15D)); - this.goalSelector.addGoal(14, new RaccoonGoals.RaccoonVillageStrollGoal(this, 1.1D)); - this.goalSelector.addGoal(15, new RaccoonGoals.RaccoonCuriosityGoal(this)); - this.goalSelector.addGoal(16, new BreedGoal(this, 1.1D)); - this.goalSelector.addGoal(17, new TemptGoal(this, 1.1D, FOOD_ITEMS, false)); - this.goalSelector.addGoal(18, new FollowParentGoal(this, 1.2D)); - this.goalSelector.addGoal(19, new WaterAvoidingRandomStrollGoal(this, 1.05D)); - this.goalSelector.addGoal(20, new RandomLookAroundGoal(this)); + this.goalSelector.addGoal(8, new RaccoonGoals.HarvestBerryBushGoal(this, 1.0)); + this.goalSelector.addGoal(9, new RaccoonGoals.RaccoonWashSelfGoal(this)); + this.goalSelector.addGoal(10, new CacheStoreGoal<>(this, 1.15D)); + this.goalSelector.addGoal(11, new CacheEatGoal<>(this, 1.15D)); + this.goalSelector.addGoal(12, new RaccoonGoals.RaccoonOpenContainerGoal(this, 1.2D)); + this.goalSelector.addGoal(13, new RaccoonGoals.RaccoonNibbleCropGoal(this, 1.15D)); + this.goalSelector.addGoal(14, new RaccoonGoals.RaccoonStealEggGoal(this, 1.15D)); + this.goalSelector.addGoal(15, new RaccoonGoals.RaccoonVillageStrollGoal(this, 1.1D)); + this.goalSelector.addGoal(16, new RaccoonGoals.RaccoonCuriosityGoal(this)); + this.goalSelector.addGoal(17, new BreedGoal(this, 1.1D)); + this.goalSelector.addGoal(18, new TemptGoal(this, 1.1D, FOOD_ITEMS, false)); + this.goalSelector.addGoal(19, new FollowParentGoal(this, 1.2D)); + this.goalSelector.addGoal(20, new WaterAvoidingRandomStrollGoal(this, 1.05D)); + this.goalSelector.addGoal(21, new RandomLookAroundGoal(this)); } public void tick() { @@ -374,7 +375,12 @@ public void onCacheEatFinished(ItemStack itemStack) { @Override public void onCacheEatGoalStopped() { } - + + @Override + public boolean isInvulnerableTo(DamageSource source) { + return source.is(DamageTypes.SWEET_BERRY_BUSH) || super.isInvulnerableTo(source); + } + @Override protected SoundEvent getAmbientSound() { return SoundEventRegistry.RACCOON_AMBIENT.get(); @@ -836,4 +842,4 @@ private void setFlag(int flag, boolean value) { private boolean getFlag(int flag) { return (this.entityData.get(DATA_FLAGS_ID) & flag) != 0; } -} \ No newline at end of file +}