Search in sources :

Example 1 with GantryShaftTileEntity

use of com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity in project FrostedHeart by TeamMoegMC.

the class MixinGantryContraptionEntity method checkPinionShaft.

@Inject(at = @At("HEAD"), method = "checkPinionShaft", remap = false)
protected void checkPinionShaft(CallbackInfo cbi) {
    Direction facing = ((GantryContraption) contraption).getFacing();
    Vector3d currentPosition = getAnchorVec().add(.5, .5, .5);
    BlockPos gantryShaftPos = new BlockPos(currentPosition).offset(facing.getOpposite());
    TileEntity te = world.getTileEntity(gantryShaftPos);
    if (te instanceof IGantryShaft) {
        GantryShaftTileEntity gte = (GantryShaftTileEntity) te;
        ((IGantryShaft) gte).setEntity(this);
        gte.networkDirty = true;
        return;
    }
}
Also used : GantryShaftTileEntity(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) GantryContraption(com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraption) Vector3d(net.minecraft.util.math.vector.Vector3d) IGantryShaft(com.teammoeg.frostedheart.util.IGantryShaft) GantryShaftTileEntity(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with GantryShaftTileEntity

use of com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity in project Create by Creators-of-Create.

the class GantryCarriageTileEntity method shouldAssemble.

private boolean shouldAssemble() {
    BlockState blockState = getBlockState();
    if (!(blockState.getBlock() instanceof GantryCarriageBlock))
        return false;
    Direction facing = blockState.getValue(GantryCarriageBlock.FACING).getOpposite();
    BlockState shaftState = level.getBlockState(worldPosition.relative(facing));
    if (!(shaftState.getBlock() instanceof GantryShaftBlock))
        return false;
    if (shaftState.getValue(GantryShaftBlock.POWERED))
        return false;
    BlockEntity te = level.getBlockEntity(worldPosition.relative(facing));
    return te instanceof GantryShaftTileEntity && ((GantryShaftTileEntity) te).canAssembleOn();
}
Also used : GantryShaftBlock(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock) BlockState(net.minecraft.world.level.block.state.BlockState) GantryShaftTileEntity(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with GantryShaftTileEntity

use of com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity in project Create by Creators-of-Create.

the class GantryCarriageTileEntity method tryAssemble.

private void tryAssemble() {
    BlockState blockState = getBlockState();
    if (!(blockState.getBlock() instanceof GantryCarriageBlock))
        return;
    Direction direction = blockState.getValue(GantryCarriageBlock.FACING);
    GantryContraption contraption = new GantryContraption(direction);
    BlockEntity shaftTe = level.getBlockEntity(worldPosition.relative(direction.getOpposite()));
    if (!(shaftTe instanceof GantryShaftTileEntity))
        return;
    BlockState shaftState = shaftTe.getBlockState();
    if (!AllBlocks.GANTRY_SHAFT.has(shaftState))
        return;
    float pinionMovementSpeed = ((GantryShaftTileEntity) shaftTe).getPinionMovementSpeed();
    Direction shaftOrientation = shaftState.getValue(GantryShaftBlock.FACING);
    Direction movementDirection = shaftOrientation;
    if (pinionMovementSpeed < 0)
        movementDirection = movementDirection.getOpposite();
    try {
        lastException = null;
        if (!contraption.assemble(level, worldPosition))
            return;
        sendData();
    } catch (AssemblyException e) {
        lastException = e;
        sendData();
        return;
    }
    if (ContraptionCollider.isCollidingWithWorld(level, contraption, worldPosition.relative(movementDirection), movementDirection))
        return;
    contraption.removeBlocksFromWorld(level, BlockPos.ZERO);
    GantryContraptionEntity movedContraption = GantryContraptionEntity.create(level, contraption, shaftOrientation);
    BlockPos anchor = worldPosition;
    movedContraption.setPos(anchor.getX(), anchor.getY(), anchor.getZ());
    AllSoundEvents.CONTRAPTION_ASSEMBLE.playOnServer(level, worldPosition);
    level.addFreshEntity(movedContraption);
}
Also used : AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) BlockState(net.minecraft.world.level.block.state.BlockState) GantryShaftTileEntity(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 4 with GantryShaftTileEntity

use of com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity in project Create by Creators-of-Create.

the class GantryContraptionEntity method checkPinionShaft.

protected void checkPinionShaft() {
    Vec3 movementVec;
    Direction facing = ((GantryContraption) contraption).getFacing();
    Vec3 currentPosition = getAnchorVec().add(.5, .5, .5);
    BlockPos gantryShaftPos = new BlockPos(currentPosition).relative(facing.getOpposite());
    BlockEntity te = level.getBlockEntity(gantryShaftPos);
    if (!(te instanceof GantryShaftTileEntity) || !AllBlocks.GANTRY_SHAFT.has(te.getBlockState())) {
        if (!level.isClientSide) {
            setContraptionMotion(Vec3.ZERO);
            disassemble();
        }
        return;
    }
    BlockState blockState = te.getBlockState();
    Direction direction = blockState.getValue(GantryShaftBlock.FACING);
    GantryShaftTileEntity gantryShaftTileEntity = (GantryShaftTileEntity) te;
    float pinionMovementSpeed = gantryShaftTileEntity.getPinionMovementSpeed();
    movementVec = Vec3.atLowerCornerOf(direction.getNormal()).scale(pinionMovementSpeed);
    if (blockState.getValue(GantryShaftBlock.POWERED) || pinionMovementSpeed == 0) {
        setContraptionMotion(Vec3.ZERO);
        if (!level.isClientSide)
            disassemble();
        return;
    }
    Vec3 nextPosition = currentPosition.add(movementVec);
    double currentCoord = direction.getAxis().choose(currentPosition.x, currentPosition.y, currentPosition.z);
    double nextCoord = direction.getAxis().choose(nextPosition.x, nextPosition.y, nextPosition.z);
    if ((Mth.floor(currentCoord) + .5f < nextCoord != (pinionMovementSpeed * direction.getAxisDirection().getStep() < 0)))
        if (!gantryShaftTileEntity.canAssembleOn()) {
            setContraptionMotion(Vec3.ZERO);
            if (!level.isClientSide)
                disassemble();
            return;
        }
    if (level.isClientSide)
        return;
    axisMotion = pinionMovementSpeed;
    setContraptionMotion(movementVec);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) GantryShaftTileEntity(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

GantryShaftTileEntity (com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity)4 Direction (net.minecraft.core.Direction)3 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 BlockPos (net.minecraft.core.BlockPos)2 AssemblyException (com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException)1 GantryContraption (com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraption)1 GantryShaftBlock (com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock)1 IGantryShaft (com.teammoeg.frostedheart.util.IGantryShaft)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Direction (net.minecraft.util.Direction)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 Vec3 (net.minecraft.world.phys.Vec3)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1