minecraft-src/net/minecraft/world/level/redstone/NeighborUpdater.java
2025-07-04 01:41:11 +03:00

66 lines
2.7 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.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, BlockPos neighborPos);
void neighborChanged(BlockState state, BlockPos pos, Block neighborBlock, BlockPos neighborPos, boolean movedByPiston);
default void updateNeighborsAtExceptFromFacing(BlockPos pos, Block block, @Nullable Direction facing) {
for (Direction direction : UPDATE_ORDER) {
if (direction != facing) {
this.neighborChanged(pos.relative(direction), block, pos);
}
}
}
static void executeShapeUpdate(LevelAccessor level, Direction direction, BlockState state, BlockPos pos, BlockPos neighborPos, int flags, int recursionLevel) {
BlockState blockState = level.getBlockState(pos);
BlockState blockState2 = blockState.updateShape(direction, state, level, pos, neighborPos);
Block.updateOrDestroy(blockState, blockState2, level, pos, flags, recursionLevel);
}
static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, BlockPos neighborPos, boolean movedByPiston) {
try {
state.handleNeighborChanged(level, pos, neighborBlock, neighborPos, 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);
}
}
}