use of net.minecraft.world.level.block.CropBlock in project AlexsMobs by Alex-the-666.
the class CrowAICircleCrops method pollinate.
private void pollinate() {
if (crow.level.getBlockState(blockPos).getBlock() instanceof CropBlock) {
CropBlock block = (CropBlock) crow.level.getBlockState(blockPos).getBlock();
int cropAge = crow.level.getBlockState(blockPos).getValue(block.getAgeProperty());
if (cropAge > 0) {
crow.level.setBlockAndUpdate(blockPos, crow.level.getBlockState(blockPos).setValue(block.getAgeProperty(), cropAge - 1));
} else {
crow.level.destroyBlock(blockPos, true);
}
stop();
} else {
crow.level.destroyBlock(blockPos, true);
stop();
}
tryTicks = 1200;
}
use of net.minecraft.world.level.block.CropBlock in project AlexsMobs by Alex-the-666.
the class HummingbirdAIPollinate method isGrowable.
private boolean isGrowable(BlockPos pos, ServerLevel world) {
BlockState blockstate = world.getBlockState(pos);
Block block = blockstate.getBlock();
return block instanceof CropBlock && !((CropBlock) block).isMaxAge(blockstate);
}
use of net.minecraft.world.level.block.CropBlock in project Create by Creators-of-Create.
the class HarvesterMovementBehaviour method isValidCrop.
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 CropBlock) {
CropBlock crop = (CropBlock) state.getBlock();
if (harvestPartial)
return state.getValue(crop.getAgeProperty()) != 0 || !replant;
return crop.isMaxAge(state);
}
if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) {
for (Property<?> property : state.getProperties()) {
if (!(property instanceof IntegerProperty))
continue;
IntegerProperty ageProperty = (IntegerProperty) property;
if (!property.getName().equals(BlockStateProperties.AGE_1.getName()))
continue;
int age = state.getValue(ageProperty).intValue();
if (state.getBlock() instanceof SweetBerryBushBlock && age <= 1 && replant)
continue;
if (age == 0 && replant || !harvestPartial && (ageProperty.getPossibleValues().size() - 1 != age))
continue;
return true;
}
}
return false;
}
use of net.minecraft.world.level.block.CropBlock in project Cyclic by Lothrazar.
the class HarvestUtil method getAgeProp.
public static IntegerProperty getAgeProp(BlockState blockState) {
if (blockState.getBlock() instanceof CropBlock) {
CropBlock crops = (CropBlock) blockState.getBlock();
// better mod compatibility if they dont use 'age'
return crops.getAgeProperty();
}
String age = CropBlock.AGE.getName();
ResourceLocation bid = blockState.getBlock().getRegistryName();
if (CompatConstants.RESYNTH.equalsIgnoreCase(bid.getNamespace())) {
// some silly old mods dont use age for compatibility
// https://github.com/Resynth-Minecraft-Mod/Resynth-Mod/blob/a9f47439d103c1c17ca7a4ffd05c2dc0397e5e5f/src/main/java/com/ki11erwolf/resynth/plant/block/BlockBiochemicalPlant.java#L59
// so we hack it
age = CompatConstants.RESYNTH_GROWTH_STAGE;
}
for (Property<?> p : blockState.getProperties()) {
if (p != null && p.getName() != null && p instanceof IntegerProperty && p.getName().equalsIgnoreCase(age)) {
return (IntegerProperty) p;
}
}
// IGrowable is useless here, i tried. no way to tell if its fully grown, or what age/stage its in
return null;
}
use of net.minecraft.world.level.block.CropBlock in project Atum2 by TeamMetallurgy.
the class AtumFarmTask method isValidPosForFarming.
private boolean isValidPosForFarming(BlockPos pos, ServerLevel serverworld) {
BlockState blockstate = serverworld.getBlockState(pos);
Block block = blockstate.getBlock();
Block block1 = serverworld.getBlockState(pos.below()).getBlock();
return block instanceof CropBlock && ((CropBlock) block).isMaxAge(blockstate) || blockstate.isAir() && block1 instanceof FertileSoilTilledBlock;
}
Aggregations