95 lines
3.6 KiB
Java
95 lines
3.6 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import java.util.function.BiPredicate;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import java.util.function.Function;
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
|
|
public class DoubleBlockCombiner {
|
|
public static <S extends BlockEntity> NeighborCombineResult<S> combineWithNeigbour(final BlockEntityType<S> bwj, final Function<BlockState, BlockType> function2, final Function<BlockState, Direction> function3, final DirectionProperty bzb, final BlockState byg, final LevelAccessor bju, final BlockPos fk, final BiPredicate<LevelAccessor, BlockPos> biPredicate) {
|
|
final S bwi9 = bwj.getBlockEntity(bju, fk);
|
|
if (bwi9 == null) {
|
|
return Combiner::acceptNone;
|
|
}
|
|
if (biPredicate.test(bju, fk)) {
|
|
return Combiner::acceptNone;
|
|
}
|
|
final BlockType a10 = function2.apply(byg);
|
|
final boolean boolean11 = a10 == BlockType.SINGLE;
|
|
final boolean boolean12 = a10 == BlockType.FIRST;
|
|
if (boolean11) {
|
|
return new NeighborCombineResult.Single<S>(bwi9);
|
|
}
|
|
final BlockPos fk2 = fk.relative(function3.apply(byg));
|
|
final BlockState byg2 = bju.getBlockState(fk2);
|
|
if (byg2.getBlock() == byg.getBlock()) {
|
|
final BlockType a11 = function2.apply(byg2);
|
|
if (a11 != BlockType.SINGLE && a10 != a11 && byg2.<Comparable>getValue((Property<Comparable>)bzb) == byg.<Comparable>getValue((Property<Comparable>)bzb)) {
|
|
if (biPredicate.test(bju, fk2)) {
|
|
return Combiner::acceptNone;
|
|
}
|
|
final S bwi10 = bwj.getBlockEntity(bju, fk2);
|
|
if (bwi10 != null) {
|
|
final S bwi11 = boolean12 ? bwi9 : bwi10;
|
|
final S bwi12 = boolean12 ? bwi10 : bwi9;
|
|
return new NeighborCombineResult.Double<S>(bwi11, bwi12);
|
|
}
|
|
}
|
|
}
|
|
return new NeighborCombineResult.Single<S>(bwi9);
|
|
}
|
|
|
|
public enum BlockType {
|
|
SINGLE,
|
|
FIRST,
|
|
SECOND;
|
|
}
|
|
|
|
public interface NeighborCombineResult<S> {
|
|
<T> T apply(final Combiner<? super S, T> b);
|
|
|
|
public static final class Double<S> implements NeighborCombineResult<S> {
|
|
private final S first;
|
|
private final S second;
|
|
|
|
public Double(final S object1, final S object2) {
|
|
this.first = object1;
|
|
this.second = object2;
|
|
}
|
|
|
|
@Override
|
|
public <T> T apply(final Combiner<? super S, T> b) {
|
|
return b.acceptDouble(this.first, this.second);
|
|
}
|
|
}
|
|
|
|
public static final class Single<S> implements NeighborCombineResult<S> {
|
|
private final S single;
|
|
|
|
public Single(final S object) {
|
|
this.single = object;
|
|
}
|
|
|
|
@Override
|
|
public <T> T apply(final Combiner<? super S, T> b) {
|
|
return b.acceptSingle(this.single);
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface Combiner<S, T> {
|
|
T acceptDouble(final S object1, final S object2);
|
|
|
|
T acceptSingle(final S object);
|
|
|
|
T acceptNone();
|
|
}
|
|
}
|