Search in sources :

Example 1 with CocoaBlock

use of net.minecraft.world.level.block.CocoaBlock 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;
}
Also used : IntegerProperty(net.minecraft.world.level.block.state.properties.IntegerProperty) CocoaBlock(net.minecraft.world.level.block.CocoaBlock) SweetBerryBushBlock(net.minecraft.world.level.block.SweetBerryBushBlock) CropBlock(net.minecraft.world.level.block.CropBlock)

Example 2 with CocoaBlock

use of net.minecraft.world.level.block.CocoaBlock in project Create by Creators-of-Create.

the class ContraptionCollider method isCollidingWithWorld.

public static boolean isCollidingWithWorld(Level world, TranslatingContraption contraption, BlockPos anchor, Direction movementDirection) {
    for (BlockPos pos : contraption.getColliders(world, movementDirection)) {
        BlockPos colliderPos = pos.offset(anchor);
        if (!world.isLoaded(colliderPos))
            return true;
        BlockState collidedState = world.getBlockState(colliderPos);
        StructureBlockInfo blockInfo = contraption.getBlocks().get(pos);
        boolean emptyCollider = collidedState.getCollisionShape(world, pos).isEmpty();
        if (collidedState.getBlock() instanceof CocoaBlock)
            continue;
        if (AllMovementBehaviours.contains(blockInfo.state.getBlock())) {
            MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state.getBlock());
            if (movementBehaviour instanceof BlockBreakingMovementBehaviour) {
                BlockBreakingMovementBehaviour behaviour = (BlockBreakingMovementBehaviour) movementBehaviour;
                if (!behaviour.canBreak(world, colliderPos, collidedState) && !emptyCollider)
                    return true;
                continue;
            }
            if (movementBehaviour instanceof HarvesterMovementBehaviour) {
                HarvesterMovementBehaviour harvesterMovementBehaviour = (HarvesterMovementBehaviour) movementBehaviour;
                if (!harvesterMovementBehaviour.isValidCrop(world, colliderPos, collidedState) && !harvesterMovementBehaviour.isValidOther(world, colliderPos, collidedState) && !emptyCollider)
                    return true;
                continue;
            }
        }
        if (AllBlocks.PULLEY_MAGNET.has(collidedState) && pos.equals(BlockPos.ZERO) && movementDirection == Direction.UP)
            continue;
        if (!collidedState.getMaterial().isReplaceable() && !emptyCollider) {
            return true;
        }
    }
    return false;
}
Also used : HarvesterMovementBehaviour(com.simibubi.create.content.contraptions.components.actors.HarvesterMovementBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) CocoaBlock(net.minecraft.world.level.block.CocoaBlock) BlockPos(net.minecraft.core.BlockPos) BlockBreakingMovementBehaviour(com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) BlockBreakingMovementBehaviour(com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour) HarvesterMovementBehaviour(com.simibubi.create.content.contraptions.components.actors.HarvesterMovementBehaviour)

Aggregations

CocoaBlock (net.minecraft.world.level.block.CocoaBlock)2 BlockBreakingMovementBehaviour (com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour)1 HarvesterMovementBehaviour (com.simibubi.create.content.contraptions.components.actors.HarvesterMovementBehaviour)1 BlockPos (net.minecraft.core.BlockPos)1 CropBlock (net.minecraft.world.level.block.CropBlock)1 SweetBerryBushBlock (net.minecraft.world.level.block.SweetBerryBushBlock)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 IntegerProperty (net.minecraft.world.level.block.state.properties.IntegerProperty)1 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)1