Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pollidisiac feeds flowers to brown mooshrooms #4521

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
package vazkii.botania.common.block.flower.functional;

import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.EntityEvent;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.MushroomCow;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.SuspiciousEffectHolder;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;

Expand All @@ -20,8 +25,11 @@
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.common.helper.DelayHelper;
import vazkii.botania.common.helper.EntityHelper;
import vazkii.botania.mixin.MushroomCowAccessor;

import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

public class PollidisiacBlockEntity extends FunctionalFlowerBlockEntity {
private static final int RANGE = 6;
Expand All @@ -35,37 +43,76 @@ public PollidisiacBlockEntity(BlockPos pos, BlockState state) {
public void tickFlower() {
super.tickFlower();

if (!getLevel().isClientSide) {
var pickupBounds = new AABB(getBlockPos().offset(-RANGE, -RANGE, -RANGE), getBlockPos().offset(RANGE + 1, RANGE + 1, RANGE + 1));
List<ItemEntity> items = getLevel().getEntitiesOfClass(ItemEntity.class, pickupBounds);
var bounds = new AABB(getEffectivePos().offset(-RANGE, -RANGE, -RANGE), getEffectivePos().offset(RANGE + 1, RANGE + 1, RANGE + 1));
List<Animal> animals = getLevel().getEntitiesOfClass(Animal.class, bounds);
if (!getLevel().isClientSide && getMana() >= MANA_COST) {
var pickupBounds = new AABB(getBlockPos()).inflate(RANGE);
List<ItemEntity> items = getLevel().getEntitiesOfClass(ItemEntity.class, pickupBounds,
itemEntity -> DelayHelper.canInteractWith(this, itemEntity));
if (items.isEmpty()) {
return;
}
var bounds = new AABB(getEffectivePos()).inflate(RANGE);
List<Animal> animals = getLevel().getEntitiesOfClass(Animal.class, bounds, Predicate.not(Animal::isBaby));
Collections.shuffle(animals);

for (Animal animal : animals) {
if (getMana() < MANA_COST) {
break;
// Note: Empty item stacks are implicitly excluded in Animal::isFood and ItemStack::is(TagKey)
if (!animal.isInLove()) {
for (ItemEntity item : items) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure this works as intended. Won't this consume multiple items on one animal? There's nothing that breaks out of the loop once a food item has been consumed from what i can see.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that item loop was definitely missing a break.

if (!animal.isFood(item.getItem())) {
continue;
}
consumeFoodItem(item);

animal.setInLoveTime(1200);
getLevel().broadcastEntityEvent(animal, EntityEvent.IN_LOVE_HEARTS);
break;
}

if (getMana() < MANA_COST) {
break;
}
}

if (animal.getAge() == 0 && !animal.isInLove()) {
if (isBrownMooshroomWithoutEffect(animal)) {
for (ItemEntity item : items) {
if (!DelayHelper.canInteractWith(this, item)) {
ItemStack stack = item.getItem();
if (!stack.is(ItemTags.SMALL_FLOWERS)) {
continue;
}
var effect = SuspiciousEffectHolder.tryGet(stack.getItem());
if (effect == null) {
continue;
}
consumeFoodItem(item);

if (animal.isFood(item.getItem())) {
EntityHelper.shrinkItem(item);
MushroomCowAccessor cowAccessor = (MushroomCowAccessor) animal;
cowAccessor.setEffect(effect.getSuspiciousEffect());
cowAccessor.setEffectDuration(effect.getEffectDuration());
animal.playSound(SoundEvents.MOOSHROOM_EAT, 2.0F, 1.0F);
break;
}

addMana(-MANA_COST);
animal.setInLoveTime(1200);
getLevel().broadcastEntityEvent(animal, EntityEvent.IN_LOVE_HEARTS);
break;
}
if (getMana() < MANA_COST) {
break;
}
}
}
}
}

private void consumeFoodItem(ItemEntity itemEntity) {
EntityHelper.shrinkItem(itemEntity);
addMana(-MANA_COST);
}

private static boolean isBrownMooshroomWithoutEffect(Animal animal) {
if (animal instanceof MushroomCow mushroomCow && mushroomCow.getVariant() == MushroomCow.MushroomType.BROWN) {
MushroomCowAccessor cowAccessor = (MushroomCowAccessor) animal;
return cowAccessor.getEffect() == null;
}
return false;
}

@Override
public RadiusDescriptor getRadius() {
return RadiusDescriptor.Rectangle.square(getEffectivePos(), RANGE);
Expand Down
3 changes: 3 additions & 0 deletions web/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ and start a new "Upcoming" section.

{% include changelog_header.html version="Upcoming" %}

* Add: Pollidisiac can feed flowers to brown mooshrooms so they produce suspicious stew

---

{% include changelog_header.html version="1.20.1-441" %}

Expand Down
Loading