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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.simibubi.create.compat.farmersdelight.FarmersDelightCompat;

import net.minecraft.world.level.block.CaveVines;
import net.minecraft.world.level.block.MushroomBlock;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -91,8 +92,10 @@ public void visitNewPosition(MovementContext context, BlockPos pos) {
MutableBoolean seedSubtracted = new MutableBoolean(notCropButCuttable);
BlockState state = stateVisited;
BlockHelper.destroyBlockAs(world, pos, null, item, effectChance, stack -> {
if (AllConfigs.server().kinetics.harvesterReplants.get() && !seedSubtracted.getValue()
&& ItemHelper.sameItem(stack, new ItemStack(state.getBlock()))) {
if (AllConfigs.server().kinetics.harvesterReplants.get()
&& !seedSubtracted.getValue()
&& ItemHelper.sameItem(stack, new ItemStack(state.getBlock()))
&& !ItemHelper.sameItem(stack, new ItemStack(Items.GLOW_BERRIES))) {
stack.shrink(1);
seedSubtracted.setTrue();
}
Expand All @@ -107,6 +110,13 @@ public boolean isValidCrop(Level world, BlockPos pos, BlockState state) {
boolean harvestPartial = AllConfigs.server().kinetics.harvestPartiallyGrown.get();
boolean replant = AllConfigs.server().kinetics.harvesterReplants.get();

if (state.getBlock() instanceof CaveVines) {
if (harvestPartial)
return true;
return state.getValue(BlockStateProperties.BERRIES);
}


if (state.getBlock() instanceof CropBlock crop) {
if (harvestPartial)
return state != crop.getStateForAge(0) || !replant;
Expand Down Expand Up @@ -144,6 +154,8 @@ public boolean isValidOther(Level world, BlockPos pos, BlockState state) {
return true;
if (state.getBlock() instanceof CocoaBlock)
return state.getValue(CocoaBlock.AGE) == CocoaBlock.MAX_AGE;
if (state.getBlock() instanceof CaveVines)
return false;

if (state.getCollisionShape(world, pos)
.isEmpty()) {
Expand Down Expand Up @@ -174,15 +186,25 @@ public boolean isValidOther(Level world, BlockPos pos, BlockState state) {
}

private BlockState cutCrop(Level world, BlockPos pos, BlockState state) {
if (!AllConfigs.server().kinetics.harvesterReplants.get()) {
if (state.getFluidState()
.isEmpty())
return Blocks.AIR.defaultBlockState();
return state.getFluidState()
.createLegacyBlock();
}
boolean replant = AllConfigs.server().kinetics.harvesterReplants.get();
boolean harvestPartial = AllConfigs.server().kinetics.harvestPartiallyGrown.get();

Block block = state.getBlock();

if (block instanceof CaveVines) {
if (harvestPartial || !replant)
return removeBlockKeepingFluid(state);

if (state.hasProperty(BlockStateProperties.BERRIES))
return state.setValue(BlockStateProperties.BERRIES, false);

return state;
}

if (!replant) {
return removeBlockKeepingFluid(state);
}

if (block instanceof CropBlock crop) {
BlockState newState = crop.getStateForAge(0);
if (!newState.is(block))
Expand All @@ -194,11 +216,7 @@ private BlockState cutCrop(Level world, BlockPos pos, BlockState state) {
return state.setValue(BlockStateProperties.AGE_3, Integer.valueOf(1));
}
if (AllBlockTags.SUGAR_CANE_VARIANTS.matches(block) || block instanceof GrowingPlantBlock) {
if (state.getFluidState()
.isEmpty())
return Blocks.AIR.defaultBlockState();
return state.getFluidState()
.createLegacyBlock();
return removeBlockKeepingFluid(state);
}
if (state.getCollisionShape(world, pos)
.isEmpty() || block instanceof CocoaBlock) {
Expand All @@ -212,9 +230,14 @@ private BlockState cutCrop(Level world, BlockPos pos, BlockState state) {
}
}

return removeBlockKeepingFluid(state);
}

private BlockState removeBlockKeepingFluid(BlockState state) {
if (state.getFluidState()
.isEmpty())
return Blocks.AIR.defaultBlockState();

return state.getFluidState()
.createLegacyBlock();
}
Expand Down