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()));
}
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());
}
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);
}
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()));
}
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;
}
Aggregations