71 lines
3 KiB
Java
71 lines
3 KiB
Java
package net.minecraft.world.level.redstone;
|
|
|
|
import java.util.Locale;
|
|
import net.minecraft.CrashReport;
|
|
import net.minecraft.CrashReportCategory;
|
|
import net.minecraft.CrashReportDetail;
|
|
import net.minecraft.ReportedException;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.registries.BuiltInRegistries;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public interface NeighborUpdater {
|
|
Direction[] UPDATE_ORDER = new Direction[]{Direction.WEST, Direction.EAST, Direction.DOWN, Direction.UP, Direction.NORTH, Direction.SOUTH};
|
|
|
|
void shapeUpdate(Direction direction, BlockState state, BlockPos pos, BlockPos neighborPos, int flags, int recursionLevel);
|
|
|
|
void neighborChanged(BlockPos pos, Block neighborBlock, @Nullable Orientation orientation);
|
|
|
|
void neighborChanged(BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston);
|
|
|
|
default void updateNeighborsAtExceptFromFacing(BlockPos pos, Block block, @Nullable Direction facing, @Nullable Orientation orientation) {
|
|
for (Direction direction : UPDATE_ORDER) {
|
|
if (direction != facing) {
|
|
this.neighborChanged(pos.relative(direction), block, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void executeShapeUpdate(
|
|
LevelAccessor level, Direction direction, BlockPos pos, BlockPos neighborPos, BlockState neighborState, int flags, int recursionLeft
|
|
) {
|
|
BlockState blockState = level.getBlockState(pos);
|
|
if ((flags & 128) == 0 || !blockState.is(Blocks.REDSTONE_WIRE)) {
|
|
BlockState blockState2 = blockState.updateShape(level, level, pos, direction, neighborPos, neighborState, level.getRandom());
|
|
Block.updateOrDestroy(blockState, blockState2, level, pos, flags, recursionLeft);
|
|
}
|
|
}
|
|
|
|
static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston) {
|
|
try {
|
|
state.handleNeighborChanged(level, pos, neighborBlock, orientation, movedByPiston);
|
|
} catch (Throwable var9) {
|
|
CrashReport crashReport = CrashReport.forThrowable(var9, "Exception while updating neighbours");
|
|
CrashReportCategory crashReportCategory = crashReport.addCategory("Block being updated");
|
|
crashReportCategory.setDetail(
|
|
"Source block type",
|
|
(CrashReportDetail<String>)(() -> {
|
|
try {
|
|
return String.format(
|
|
Locale.ROOT,
|
|
"ID #%s (%s // %s)",
|
|
BuiltInRegistries.BLOCK.getKey(neighborBlock),
|
|
neighborBlock.getDescriptionId(),
|
|
neighborBlock.getClass().getCanonicalName()
|
|
);
|
|
} catch (Throwable var2) {
|
|
return "ID #" + BuiltInRegistries.BLOCK.getKey(neighborBlock);
|
|
}
|
|
})
|
|
);
|
|
CrashReportCategory.populateBlockDetails(crashReportCategory, level, pos, state);
|
|
throw new ReportedException(crashReport);
|
|
}
|
|
}
|
|
}
|