From 6b11d51b37c5e68f3cdf7df0647c0706bfbc75a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=82=A6=E8=A7=A3=E8=AF=B4?= Date: Wed, 18 Sep 2024 23:01:13 +0800 Subject: [PATCH] High Speed Repeater --- .../java/ziyue/tjmetro/mod/BlockList.java | 2 +- .../ziyue/tjmetro/mod/TianjinMetroClient.java | 1 + .../mod/block/BlockHighSpeedRepeater.java | 19 ++++++++++--------- .../ziyue/tjmetro/mod/client/Filters.java | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java b/fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java index 5fe85d7..3e478f1 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java @@ -96,7 +96,7 @@ public interface BlockList BlockRegistryObject PSD_GLASS_END_TIANJIN_BLOCK = Registry.registerBlock("psd_glass_end_tianjin", () -> new Block(new BlockPSDGlassEndTianjin())); BlockRegistryObject PSD_TOP_TIANJIN = Registry.registerBlock("psd_top_tianjin", () -> new Block(new BlockPSDTopTianjin())); BlockRegistryObject METAL_DETECTION_DOOR = Registry.registerBlockWithBlockItem("metal_detection_door", () -> new Block(new BlockMetalDetectionDoor()), CreativeModeTabs.TIANJIN_METRO); -// BlockRegistryObject HIGH_SPEED_REPEATER = Registry.registerBlockWithBlockItem("high_speed_repeater", () -> new Block(new BlockHighSpeedRepeater()), CreativeModeTabs.TIANJIN_METRO); + BlockRegistryObject HIGH_SPEED_REPEATER = Registry.registerBlockWithBlockItem("high_speed_repeater", () -> new Block(new BlockHighSpeedRepeater()), CreativeModeTabs.TIANJIN_METRO); BlockRegistryObject STATION_NAME_WALL_LEGACY = Registry.registerBlockWithBlockItem("station_name_wall_legacy", () -> new Block(new BlockStationNameWallLegacy()), CreativeModeTabs.TIANJIN_METRO); BlockRegistryObject STATION_NAME_PLATE = Registry.registerBlockWithBlockItem("station_name_plate", () -> new Block(new BlockStationNamePlate()), CreativeModeTabs.TIANJIN_METRO); BlockRegistryObject STATION_NAME_PLATE_MIDDLE = Registry.registerBlock("station_name_plate_middle", () -> new Block(new BlockStationNamePlate())); diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/TianjinMetroClient.java b/fabric/src/main/java/ziyue/tjmetro/mod/TianjinMetroClient.java index 3100a5e..e14af6f 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/TianjinMetroClient.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/TianjinMetroClient.java @@ -35,6 +35,7 @@ public static void init() { RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.PSD_DOOR_TIANJIN_BMT_BLOCK); RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.PSD_GLASS_TIANJIN_BMT_BLOCK); RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.PSD_GLASS_END_TIANJIN_BMT_BLOCK); + RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.HIGH_SPEED_REPEATER); RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.STATION_NAME_SIGN_1, RenderStationNameSign::new); RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.STATION_NAME_SIGN_2, RenderStationNameSign::new); diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/block/BlockHighSpeedRepeater.java b/fabric/src/main/java/ziyue/tjmetro/mod/block/BlockHighSpeedRepeater.java index 13d2c24..f7b5d46 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/block/BlockHighSpeedRepeater.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/block/BlockHighSpeedRepeater.java @@ -13,11 +13,8 @@ /** * @author ZiYueCommentary * @since 1.0.0-beta-1 - * @deprecated */ -// Screw this. -@Deprecated public class BlockHighSpeedRepeater extends BlockExtension implements DirectionHelper { public static final BooleanProperty LOCKED = BooleanProperty.of("locked"); @@ -40,7 +37,7 @@ public VoxelShape getOutlineShape2(BlockState state, BlockView world, BlockPos p @Override public int getStrongRedstonePower2(BlockState state, BlockView world, BlockPos pos, Direction direction) { - return IBlock.getStatePropertySafe(state, POWERED) ? 15 : 0; + return direction == IBlock.getStatePropertySafe(state, FACING) && IBlock.getStatePropertySafe(state, POWERED) ? 15 : 0; } @Override @@ -50,11 +47,15 @@ public int getWeakRedstonePower2(BlockState state, BlockView world, BlockPos pos @Override public void neighborUpdate2(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { - if (this.isLocked(world, pos, state)) return; - Direction direction = IBlock.getStatePropertySafe(state, FACING); - BlockPos blockPos1 = pos.offset(direction); - boolean powered = world.getBlockState(blockPos1).getStrongRedstonePower(new BlockView(world.data), blockPos1, direction) > 0; - world.setBlockState(pos, state.with(new Property<>(POWERED.data), powered)); + if (IBlock.getStatePropertySafe(state, LOCKED)) { + world.setBlockState(pos, state.with(new Property<>(LOCKED.data), this.isLocked(world, pos, state))); + return; + } + final Direction direction = IBlock.getStatePropertySafe(state, FACING); + final BlockPos blockPos1 = pos.offset(direction); + final boolean powered = world.getBlockState(blockPos1).getStrongRedstonePower(new BlockView(world.data), blockPos1, direction) > 0; + final boolean isLocked = this.isLocked(world, pos, state); + world.setBlockState(pos, state.with(new Property<>(POWERED.data), powered).with(new Property<>(LOCKED.data), isLocked)); } protected int getInputLevel(World world, BlockPos pos, Direction dir) { diff --git a/fabric/src/main/java/ziyue/tjmetro/mod/client/Filters.java b/fabric/src/main/java/ziyue/tjmetro/mod/client/Filters.java index 19a0d00..4e6d0d6 100644 --- a/fabric/src/main/java/ziyue/tjmetro/mod/client/Filters.java +++ b/fabric/src/main/java/ziyue/tjmetro/mod/client/Filters.java @@ -27,7 +27,7 @@ public interface Filters static void init() { FilterBuilder.addItems(Filters.TIANJIN_MISCELLANEOUS, WRENCH); - FilterBuilder.addBlocks(Filters.TIANJIN_MISCELLANEOUS, PLAYER_DETECTOR); + FilterBuilder.addBlocks(Filters.TIANJIN_MISCELLANEOUS, PLAYER_DETECTOR, HIGH_SPEED_REPEATER); FilterBuilder.addBlocks(Filters.TIANJIN_BUILDING, ROLLING, PLATFORM_TJ_1, PLATFORM_TJ_2, PLATFORM_TJ_1_INDENTED, PLATFORM_TJ_2_INDENTED,