Search in sources :

Example 1 with BracketedTileEntityBehaviour

use of com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour in project Create by Creators-of-Create.

the class FluidPipeBlock method removeBracket.

@Override
public Optional<ItemStack> removeBracket(BlockGetter world, BlockPos pos, boolean inOnReplacedContext) {
    BracketedTileEntityBehaviour behaviour = BracketedTileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
    if (behaviour == null)
        return Optional.empty();
    BlockState bracket = behaviour.getBracket();
    behaviour.removeBracket(inOnReplacedContext);
    if (bracket == Blocks.AIR.defaultBlockState())
        return Optional.empty();
    return Optional.of(new ItemStack(bracket.getBlock()));
}
Also used : BracketedTileEntityBehaviour(com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with BracketedTileEntityBehaviour

use of com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour in project Create by Creators-of-Create.

the class FluidPipeBlock method canConnectTo.

public static boolean canConnectTo(BlockAndTintGetter world, BlockPos neighbourPos, BlockState neighbour, Direction direction) {
    if (FluidPropagator.hasFluidCapability(world, neighbourPos, direction.getOpposite()))
        return true;
    if (VanillaFluidTargets.shouldPipesConnectTo(neighbour))
        return true;
    FluidTransportBehaviour transport = TileEntityBehaviour.get(world, neighbourPos, FluidTransportBehaviour.TYPE);
    BracketedTileEntityBehaviour bracket = TileEntityBehaviour.get(world, neighbourPos, BracketedTileEntityBehaviour.TYPE);
    if (isPipe(neighbour))
        return bracket == null || !bracket.isBracketPresent() || FluidPropagator.getStraightPipeAxis(neighbour) == direction.getAxis();
    if (transport == null)
        return false;
    return transport.canHaveFlowToward(neighbour, direction.getOpposite());
}
Also used : BracketedTileEntityBehaviour(com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour) FluidTransportBehaviour(com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour)

Example 3 with BracketedTileEntityBehaviour

use of com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour in project Create by Creators-of-Create.

the class FluidPipeBlock method updateBlockState.

public BlockState updateBlockState(BlockState state, Direction preferredDirection, @Nullable Direction ignore, BlockAndTintGetter world, BlockPos pos) {
    BracketedTileEntityBehaviour bracket = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
    if (bracket != null && bracket.isBracketPresent())
        return state;
    BlockState prevState = state;
    int prevStateSides = (int) Arrays.stream(Iterate.directions).map(PROPERTY_BY_DIRECTION::get).filter(prevState::getValue).count();
    // Update sides that are not ignored
    for (Direction d : Iterate.directions) if (d != ignore) {
        boolean shouldConnect = canConnectTo(world, pos.relative(d), world.getBlockState(pos.relative(d)), d);
        state = state.setValue(PROPERTY_BY_DIRECTION.get(d), shouldConnect);
    }
    // See if it has enough connections
    Direction connectedDirection = null;
    for (Direction d : Iterate.directions) {
        if (isOpenAt(state, d)) {
            if (connectedDirection != null)
                return state;
            connectedDirection = d;
        }
    }
    // Add opposite end if only one connection
    if (connectedDirection != null)
        return state.setValue(PROPERTY_BY_DIRECTION.get(connectedDirection.getOpposite()), true);
    // If we can't connect to anything and weren't connected before, do nothing
    if (prevStateSides == 2)
        return prevState;
    // Use preferred
    return state.setValue(PROPERTY_BY_DIRECTION.get(preferredDirection), true).setValue(PROPERTY_BY_DIRECTION.get(preferredDirection.getOpposite()), true);
}
Also used : BracketedTileEntityBehaviour(com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 4 with BracketedTileEntityBehaviour

use of com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour in project Create by Creators-of-Create.

the class AxisPipeBlock method removeBracket.

@Override
public Optional<ItemStack> removeBracket(BlockGetter world, BlockPos pos, boolean inOnReplacedContext) {
    BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
    if (behaviour == null)
        return Optional.empty();
    BlockState bracket = behaviour.getBracket();
    behaviour.removeBracket(inOnReplacedContext);
    if (bracket == Blocks.AIR.defaultBlockState())
        return Optional.empty();
    return Optional.of(new ItemStack(bracket.getBlock()));
}
Also used : BracketedTileEntityBehaviour(com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with BracketedTileEntityBehaviour

use of com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour in project Create by Creators-of-Create.

the class BracketBlockItem method useOn.

@Override
public InteractionResult useOn(UseOnContext context) {
    Level world = context.getLevel();
    BlockPos pos = context.getClickedPos();
    BlockState state = world.getBlockState(pos);
    BracketBlock bracketBlock = getBracketBlock();
    Player player = context.getPlayer();
    BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
    if (behaviour == null)
        return InteractionResult.FAIL;
    if (!behaviour.canHaveBracket())
        return InteractionResult.FAIL;
    if (world.isClientSide)
        return InteractionResult.SUCCESS;
    Optional<BlockState> suitableBracket = bracketBlock.getSuitableBracket(state, context.getClickedFace());
    if (!suitableBracket.isPresent() && player != null)
        suitableBracket = bracketBlock.getSuitableBracket(state, Direction.orderedByNearest(player)[0].getOpposite());
    if (!suitableBracket.isPresent())
        return InteractionResult.SUCCESS;
    BlockState bracket = behaviour.getBracket();
    BlockState newBracket = suitableBracket.get();
    if (bracket == newBracket)
        return InteractionResult.SUCCESS;
    world.playSound(null, pos, newBracket.getSoundType().getPlaceSound(), SoundSource.BLOCKS, 0.75f, 1);
    behaviour.applyBracket(newBracket);
    if (!world.isClientSide && player != null)
        behaviour.triggerAdvancements(world, player, state);
    if (player == null || !player.isCreative()) {
        context.getItemInHand().shrink(1);
        if (bracket != Blocks.AIR.defaultBlockState()) {
            ItemStack returnedStack = new ItemStack(bracket.getBlock());
            if (player == null)
                Block.popResource(world, pos, returnedStack);
            else
                player.getInventory().placeItemBackInInventory(returnedStack);
        }
    }
    return InteractionResult.SUCCESS;
}
Also used : Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) BracketedTileEntityBehaviour(com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

BracketedTileEntityBehaviour (com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour)7 BlockState (net.minecraft.world.level.block.state.BlockState)4 ItemStack (net.minecraft.world.item.ItemStack)3 Direction (net.minecraft.core.Direction)2 FluidTransportBehaviour (com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour)1 BlockPos (net.minecraft.core.BlockPos)1 AxisDirection (net.minecraft.core.Direction.AxisDirection)1 Player (net.minecraft.world.entity.player.Player)1 Level (net.minecraft.world.level.Level)1