Search in sources :

Example 21 with StructureBlockInfo

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.

the class Contraption method addBlock.

protected void addBlock(BlockPos pos, Pair<StructureBlockInfo, BlockEntity> pair) {
    StructureBlockInfo captured = pair.getKey();
    BlockPos localPos = pos.subtract(anchor);
    StructureBlockInfo StructureBlockInfo = new StructureBlockInfo(localPos, captured.state, captured.nbt);
    if (blocks.put(localPos, StructureBlockInfo) != null)
        return;
    bounds = bounds.minmax(new AABB(localPos));
    BlockEntity te = pair.getValue();
    if (te != null && MountedStorage.canUseAsStorage(te))
        storage.put(localPos, new MountedStorage(te));
    if (te != null && MountedFluidStorage.canUseAsStorage(te))
        fluidStorage.put(localPos, new MountedFluidStorage(te));
    if (AllMovementBehaviours.contains(captured.state.getBlock()))
        actors.add(MutablePair.of(StructureBlockInfo, null));
    if (AllInteractionBehaviours.contains(captured.state.getBlock()))
        interactors.put(localPos, AllInteractionBehaviours.of(captured.state.getBlock()));
    if (te instanceof CreativeCrateTileEntity && ((CreativeCrateTileEntity) te).getBehaviour(FilteringBehaviour.TYPE).getFilter().isEmpty())
        hasUniversalCreativeCrate = true;
}
Also used : CreativeCrateTileEntity(com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity) BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) AABB(net.minecraft.world.phys.AABB) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 22 with StructureBlockInfo

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo 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)

Example 23 with StructureBlockInfo

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.

the class AbstractContraptionEntity method tickActors.

public void tickActors() {
    boolean stalledPreviously = contraption.stalled;
    if (!level.isClientSide)
        contraption.stalled = false;
    ticking = true;
    for (MutablePair<StructureBlockInfo, MovementContext> pair : contraption.getActors()) {
        MovementContext context = pair.right;
        StructureBlockInfo blockInfo = pair.left;
        MovementBehaviour actor = AllMovementBehaviours.of(blockInfo.state);
        Vec3 oldMotion = context.motion;
        Vec3 actorPosition = toGlobalVector(VecHelper.getCenterOf(blockInfo.pos).add(actor.getActiveAreaOffset(context)), 1);
        BlockPos gridPosition = new BlockPos(actorPosition);
        boolean newPosVisited = !context.stall && shouldActorTrigger(context, blockInfo, actor, actorPosition, gridPosition);
        context.rotation = v -> applyRotation(v, 1);
        context.position = actorPosition;
        if (!actor.isActive(context))
            continue;
        if (newPosVisited && !context.stall) {
            actor.visitNewPosition(context, gridPosition);
            if (!isAlive())
                break;
            context.firstMovement = false;
        }
        if (!oldMotion.equals(context.motion)) {
            actor.onSpeedChanged(context, oldMotion, context.motion);
            if (!isAlive())
                break;
        }
        actor.tick(context);
        if (!isAlive())
            break;
        contraption.stalled |= context.stall;
    }
    if (!isAlive()) {
        contraption.stop(level);
        return;
    }
    ticking = false;
    for (Entity entity : getPassengers()) {
        if (!(entity instanceof OrientedContraptionEntity))
            continue;
        if (!contraption.stabilizedSubContraptions.containsKey(entity.getUUID()))
            continue;
        OrientedContraptionEntity orientedCE = (OrientedContraptionEntity) entity;
        if (orientedCE.contraption != null && orientedCE.contraption.stalled) {
            contraption.stalled = true;
            break;
        }
    }
    if (!level.isClientSide) {
        if (!stalledPreviously && contraption.stalled)
            onContraptionStalled();
        entityData.set(STALLED, contraption.stalled);
        return;
    }
    contraption.stalled = isStalled();
}
Also used : SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) SeatEntity(com.simibubi.create.content.contraptions.components.actors.SeatEntity) Entity(net.minecraft.world.entity.Entity) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)

Aggregations

StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)23 BlockPos (net.minecraft.core.BlockPos)16 BlockState (net.minecraft.world.level.block.state.BlockState)13 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)9 AABB (net.minecraft.world.phys.AABB)8 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)7 Axis (net.minecraft.core.Direction.Axis)7 MagnetBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock)6 RopeBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock)6 Direction (net.minecraft.core.Direction)6 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)5 SeatEntity (com.simibubi.create.content.contraptions.components.actors.SeatEntity)5 MechanicalBearingBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock)5 WindmillBearingBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock)5 AbstractChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock)5 StickerBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock)5 GantryCarriageBlock (com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock)5 MechanicalPistonBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock)5 MechanicalPistonHeadBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock)5 PistonExtensionPoleBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock)5