Skip to content
Open
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
43 changes: 31 additions & 12 deletions src/pokecube/java/pokecube/core/ai/tasks/utility/GatherItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import pokecube.api.entity.pokemob.ai.LogicStates;
import pokecube.api.events.pokemobs.ai.HarvestCheckEvent;
import pokecube.core.PokecubeCore;
import pokecube.core.blocks.berries.BerryFruit;
import pokecube.core.ai.brain.BrainUtils;
import pokecube.core.ai.brain.MemoryModules;
import pokecube.core.ai.brain.sensors.NearBlocks.NearBlock;
Expand Down Expand Up @@ -79,7 +80,9 @@ public class GatherItems extends PokemobBehaviour
"harvest_extra");

private static final Predicate<BlockState> fullCropNormal = input -> input.getBlock() instanceof CropBlock crop
&& input.hasProperty(CropBlock.AGE) && input.getValue(CropBlock.AGE) >= crop.getMaxAge();
&& crop.isMaxAge(input);

private static final Predicate<BlockState> fullCropPokeBerry = input -> input.getBlock() instanceof BerryFruit;

private static final Predicate<BlockState> fullCropBeet = input -> input.getBlock() instanceof CropBlock crop
&& input.hasProperty(BeetrootBlock.AGE) && input.getValue(BeetrootBlock.AGE) >= crop.getMaxAge();
Expand All @@ -97,7 +100,8 @@ public class GatherItems extends PokemobBehaviour
final boolean blacklisted = ItemList.is(GatherItems.BLACKLIST, input);
if (blacklisted) return false;
final boolean fullCrop = GatherItems.fullCropNormal.test(input) || GatherItems.fullCropBeet.test(input)
|| GatherItems.fullCropNetherWart.test(input);
|| GatherItems.fullCropNetherWart.test(input)
|| GatherItems.fullCropPokeBerry.test(input);
return fullCrop || ItemList.is(GatherItems.HARVEST, input);
};

Expand All @@ -107,19 +111,25 @@ public static record HarvestContext(ServerLevel level, BlockState state, BlockPo

public static interface IHarvester
{
default boolean isAvailable(BlockState state) {
return GatherItems.harvestMatcher.apply(state);
}

default boolean isHarvestable(Mob entity, IPokemob pokemob, HarvestContext context)
{
final HarvestCheckEvent event = new HarvestCheckEvent(pokemob, context.state(), context.pos());
PokecubeAPI.POKEMOB_BUS.post(event);
return event.getResult() == TriState.TRUE || (event.getResult() != TriState.FALSE
&& GatherItems.harvestMatcher.apply(context.state()));
&& this.isAvailable(context.state()));
}

default void harvest(Mob entity, IPokemob pokemob, HarvestContext context)
{
context.level().setBlockAndUpdate(context.pos(), Blocks.AIR.defaultBlockState());
final List<ItemStack> list = Block.getDrops(context.state(), context.level(), context.pos(),
context.level().getBlockEntity(context.pos()));

context.level().setBlockAndUpdate(context.pos(), Blocks.AIR.defaultBlockState());

boolean replanted = false;

int startSlot = context.isPokemobInventory() ? 2 : 0;
Expand Down Expand Up @@ -246,12 +256,9 @@ public void harvest(final Mob entity, final IPokemob pokemob, HarvestContext con
}

@Override
public boolean isHarvestable(final Mob entity, final IPokemob pokemob, HarvestContext context)
public boolean isAvailable(final BlockState state)
{
final HarvestCheckEvent event = new HarvestCheckEvent(pokemob, context.state(), context.pos());
PokecubeAPI.POKEMOB_BUS.post(event);
return event.getResult() == TriState.TRUE
|| event.getResult() != TriState.FALSE && GatherItems.sweetBerry.apply(context.state());
return GatherItems.sweetBerry.apply(state);
}
});
}
Expand Down Expand Up @@ -313,9 +320,21 @@ private boolean hasStuff(StoreItems storage, GatherDetails details)
final BlockState state = storage.entity.level().getBlockState(details.targetBlock.getPos());
final HarvestCheckEvent event = new HarvestCheckEvent(storage.pokemob, state, details.targetBlock.getPos());
PokecubeAPI.POKEMOB_BUS.post(event);
final boolean gatherable = event.getResult() == TriState.TRUE
|| event.getResult() != TriState.FALSE && GatherItems.harvestMatcher.apply(state);
if (!gatherable) details.targetBlock = null;
boolean canHarvest = false;
final boolean blacklisted = ItemList.is(GatherItems.BLACKLIST, state);
if (blacklisted) {
details.targetBlock = null;
}
else {
for (final Entry<ResourceLocation, IHarvester> entry : GatherItems.REGISTRY.entrySet())
{
canHarvest = entry.getValue().isAvailable(state);
if (canHarvest) break;
}
final boolean gatherable = event.getResult() == TriState.TRUE
|| event.getResult() != TriState.FALSE && canHarvest;
if (!gatherable) details.targetBlock = null;
}
}
return details.targetItem != null || details.targetBlock != null;
}
Expand Down