Update HarvesterMovementBehaviour.java

- harvestpartial only breaks age zero crops if replant is disabled
This commit is contained in:
simibubi 2021-10-21 19:10:34 +02:00
parent a2043bebc5
commit 3093bf5917

View file

@ -24,6 +24,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.CocoaBlock; import net.minecraft.block.CocoaBlock;
import net.minecraft.block.CropsBlock; import net.minecraft.block.CropsBlock;
import net.minecraft.block.SugarCaneBlock; import net.minecraft.block.SugarCaneBlock;
import net.minecraft.block.SweetBerryBushBlock;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
@ -51,14 +52,16 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
@Nullable @Nullable
@Override @Override
public ActorInstance createInstance(MaterialManager<?> materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { public ActorInstance createInstance(MaterialManager<?> materialManager, PlacementSimulationWorld simulationWorld,
MovementContext context) {
return new HarvesterActorInstance(materialManager, simulationWorld, context); return new HarvesterActorInstance(materialManager, simulationWorld, context);
} }
@Override @Override
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld, public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, IRenderTypeBuffer buffers) { ContraptionMatrices matrices, IRenderTypeBuffer buffers) {
if (!Backend.getInstance().canUseInstancing()) if (!Backend.getInstance()
.canUseInstancing())
HarvesterRenderer.renderInContraption(context, renderWorld, matrices, buffers); HarvesterRenderer.renderInContraption(context, renderWorld, matrices, buffers);
} }
@ -87,18 +90,18 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
ItemStack item = ItemStack.EMPTY; ItemStack item = ItemStack.EMPTY;
float effectChance = 1; float effectChance = 1;
if (stateVisited.getBlock().is(BlockTags.LEAVES)) { if (stateVisited.getBlock()
.is(BlockTags.LEAVES)) {
item = new ItemStack(Items.SHEARS); item = new ItemStack(Items.SHEARS);
effectChance = .45f; effectChance = .45f;
} }
MutableBoolean seedSubtracted = new MutableBoolean(notCropButCuttable); MutableBoolean seedSubtracted = new MutableBoolean(notCropButCuttable);
BlockState state = stateVisited; BlockState state = stateVisited;
BlockHelper.destroyBlockAs(world, pos, null, item, effectChance, stack -> { BlockHelper.destroyBlockAs(world, pos, null, item, effectChance, stack -> {
if (AllConfigs.SERVER.kinetics.harvesterReplants.get() if (AllConfigs.SERVER.kinetics.harvesterReplants.get() && !seedSubtracted.getValue()
&& !seedSubtracted.getValue() && stack.sameItem(new ItemStack(state.getBlock()))) {
&& stack.sameItem(new ItemStack(state.getBlock()))) {
stack.shrink(1); stack.shrink(1);
seedSubtracted.setTrue(); seedSubtracted.setTrue();
} }
@ -109,24 +112,31 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
} }
private boolean isValidCrop(World world, BlockPos pos, BlockState state) { private boolean isValidCrop(World world, BlockPos pos, BlockState state) {
boolean harvestPartial = AllConfigs.SERVER.kinetics.harvestPartiallyGrown.get();
boolean replant = AllConfigs.SERVER.kinetics.harvesterReplants.get();
if (state.getBlock() instanceof CropsBlock) { if (state.getBlock() instanceof CropsBlock) {
CropsBlock crop = (CropsBlock) state.getBlock(); CropsBlock crop = (CropsBlock) state.getBlock();
if (!crop.isMaxAge(state) && !AllConfigs.SERVER.kinetics.harvestPartiallyGrown.get()) if (harvestPartial)
return false; return state.getValue(crop.getAgeProperty()) != 0 || !replant;
return true; return crop.isMaxAge(state);
} }
if (state.getCollisionShape(world, pos) if (state.getCollisionShape(world, pos)
.isEmpty() || state.getBlock() instanceof CocoaBlock) { .isEmpty() || state.getBlock() instanceof CocoaBlock) {
for (Property<?> property : state.getProperties()) { for (Property<?> property : state.getProperties()) {
if (!(property instanceof IntegerProperty)) if (!(property instanceof IntegerProperty))
continue; continue;
IntegerProperty ageProperty = (IntegerProperty) property;
if (!property.getName() if (!property.getName()
.equals(BlockStateProperties.AGE_1.getName())) .equals(BlockStateProperties.AGE_1.getName()))
continue; continue;
if (!AllConfigs.SERVER.kinetics.harvestPartiallyGrown.get() int age = state.getValue(ageProperty)
&& (((IntegerProperty) property).getPossibleValues().size() - 1 .intValue();
!= state.getValue((IntegerProperty) property) if (state.getBlock() instanceof SweetBerryBushBlock && age <= 1 && replant)
.intValue())) continue;
if (age == 0 && replant || !harvestPartial && (ageProperty.getPossibleValues()
.size() - 1 != age))
continue; continue;
return true; return true;
} }
@ -140,7 +150,8 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
return false; return false;
if (state.getBlock() instanceof SugarCaneBlock) if (state.getBlock() instanceof SugarCaneBlock)
return true; return true;
if (state.getBlock().is(BlockTags.LEAVES)) if (state.getBlock()
.is(BlockTags.LEAVES))
return true; return true;
if (state.getCollisionShape(world, pos) if (state.getCollisionShape(world, pos)
@ -167,10 +178,10 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
private BlockState cutCrop(World world, BlockPos pos, BlockState state) { private BlockState cutCrop(World world, BlockPos pos, BlockState state) {
if (!AllConfigs.SERVER.kinetics.harvesterReplants.get()) { if (!AllConfigs.SERVER.kinetics.harvesterReplants.get()) {
if (state.getFluidState() if (state.getFluidState()
.isEmpty()) .isEmpty())
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
return state.getFluidState() return state.getFluidState()
.createLegacyBlock(); .createLegacyBlock();
} }
Block block = state.getBlock(); Block block = state.getBlock();
@ -183,18 +194,18 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
} }
if (block == Blocks.SUGAR_CANE || block instanceof AbstractPlantBlock) { if (block == Blocks.SUGAR_CANE || block instanceof AbstractPlantBlock) {
if (state.getFluidState() if (state.getFluidState()
.isEmpty()) .isEmpty())
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
return state.getFluidState() return state.getFluidState()
.createLegacyBlock(); .createLegacyBlock();
} }
if (state.getCollisionShape(world, pos) if (state.getCollisionShape(world, pos)
.isEmpty() || block instanceof CocoaBlock) { .isEmpty() || block instanceof CocoaBlock) {
for (Property<?> property : state.getProperties()) { for (Property<?> property : state.getProperties()) {
if (!(property instanceof IntegerProperty)) if (!(property instanceof IntegerProperty))
continue; continue;
if (!property.getName() if (!property.getName()
.equals(BlockStateProperties.AGE_1.getName())) .equals(BlockStateProperties.AGE_1.getName()))
continue; continue;
return state.setValue((IntegerProperty) property, Integer.valueOf(0)); return state.setValue((IntegerProperty) property, Integer.valueOf(0));
} }