Search in sources :

Example 1 with BlockBreakingMovementBehaviour

use of com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour 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

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 CocoaBlock (net.minecraft.world.level.block.CocoaBlock)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)1