Skip to content

Commit

Permalink
simplified some crop harvest module logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Dec 18, 2023
1 parent 532cfb1 commit 5c4455d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -41,17 +40,14 @@
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;

import org.apache.commons.lang3.mutable.MutableBoolean;

import org.violetmoon.quark.api.event.SimpleHarvestEvent;
import org.violetmoon.quark.api.event.SimpleHarvestEvent.ActionType;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.QuarkClient;
import org.violetmoon.quark.base.config.Config;
import org.violetmoon.quark.base.handler.MiscUtil;
import org.violetmoon.quark.base.network.message.HarvestMessage;
import org.violetmoon.quark.mixin.accessor.AccessorCropBlock;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.bus.PlayEvent;
import org.violetmoon.zeta.event.load.ZCommonSetup;
Expand Down Expand Up @@ -121,16 +117,16 @@ public void configChanged(ZConfigChanged event) {
staticEnabled = enabled;

if(doHarvestingSearch) {
BuiltInRegistries.BLOCK.stream()
.filter(b -> !isVanilla(b) && b instanceof CropBlock)
.map(b -> (CropBlock) b)
//only grabbing blocks whose max age is acceptable
.filter(b -> b.isMaxAge(b.defaultBlockState().setValue(((AccessorCropBlock) b).quark$getAgeProperty(), last(((AccessorCropBlock) b).quark$getAgeProperty().getPossibleValues()))))
.forEach(b -> crops.put(b.defaultBlockState().setValue(((AccessorCropBlock) b).quark$getAgeProperty(), last(((AccessorCropBlock) b).quark$getAgeProperty().getPossibleValues())), b.defaultBlockState()));

BuiltInRegistries.BLOCK.stream()
.filter(b -> !isVanilla(b) && (b instanceof BushBlock || b instanceof GrowingPlantBlock) && b instanceof BonemealableBlock && !(b instanceof CropBlock))
.forEach(rightClickCrops::add);
for (var b : BuiltInRegistries.BLOCK) {
if (!isVanilla(b)) {
if (b instanceof CropBlock c) {
//only grabbing blocks whose max age is acceptable
crops.put(c.getStateForAge(c.getMaxAge()), c.defaultBlockState());
} else if ((b instanceof BushBlock || b instanceof GrowingPlantBlock) && b instanceof BonemealableBlock) {
rightClickCrops.add(b);
}
}
}
}

for(String harvestKey : harvestableBlocks) {
Expand All @@ -155,10 +151,6 @@ public void configChanged(ZConfigChanged event) {
crops.values().forEach(bl -> cropBlocks.add(bl.getBlock()));
}

private int last(Collection<Integer> vals) {
return vals.stream().max(Integer::compare).orElse(0);
}

private String[] tokenize(String harvestKey) {
boolean inBracket = false;
for(int i = 0; i < harvestKey.length(); i++) {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/quark.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"WallBlockMixin",
"accessor.AccessorAbstractArrow",
"accessor.AccessorAbstractChestedHorse",
"accessor.AccessorCropBlock",
"accessor.AccessorLivingEntity",
"accessor.AccessorMerchantOffer",
"accessor.AccessorPotionBrewing"
Expand Down

0 comments on commit 5c4455d

Please sign in to comment.