Skip to content

Commit

Permalink
✔ Railway Sign Wall Double
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Feb 8, 2024
1 parent 9d61ec1 commit d4a4254
Show file tree
Hide file tree
Showing 26 changed files with 948 additions and 28 deletions.
4 changes: 4 additions & 0 deletions common/src/main/java/ziyue/tjmetro/BlockEntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public interface BlockEntityTypes
RegistryObject<BlockEntityType<BlockRailwaySignWall.TileEntityRailwaySignWall>> RAILWAY_SIGN_WALL_6_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWall.TileEntityRailwaySignWall(6, pos, state), BlockList.RAILWAY_SIGN_WALL_6.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWall.TileEntityRailwaySignWall>> RAILWAY_SIGN_WALL_8_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWall.TileEntityRailwaySignWall(8, pos, state), BlockList.RAILWAY_SIGN_WALL_8.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWall.TileEntityRailwaySignWall>> RAILWAY_SIGN_WALL_10_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWall.TileEntityRailwaySignWall(10, pos, state), BlockList.RAILWAY_SIGN_WALL_10.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble>> RAILWAY_SIGN_WALL_DOUBLE_4_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble(4, pos, state), BlockList.RAILWAY_SIGN_WALL_DOUBLE_4.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble>> RAILWAY_SIGN_WALL_DOUBLE_6_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble(6, pos, state), BlockList.RAILWAY_SIGN_WALL_DOUBLE_6.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble>> RAILWAY_SIGN_WALL_DOUBLE_8_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble(8, pos, state), BlockList.RAILWAY_SIGN_WALL_DOUBLE_8.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble>> RAILWAY_SIGN_WALL_DOUBLE_10_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallDouble.TileEntityRailwaySignWallDouble(10, pos, state), BlockList.RAILWAY_SIGN_WALL_DOUBLE_10.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallBig.TileEntityRailwaySignWallBig>> RAILWAY_SIGN_WALL_BIG_2_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallBig.TileEntityRailwaySignWallBig(2, pos, state), BlockList.RAILWAY_SIGN_WALL_BIG_2.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallBig.TileEntityRailwaySignWallBig>> RAILWAY_SIGN_WALL_BIG_3_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallBig.TileEntityRailwaySignWallBig(3, pos, state), BlockList.RAILWAY_SIGN_WALL_BIG_3.get()));
RegistryObject<BlockEntityType<BlockRailwaySignWallBig.TileEntityRailwaySignWallBig>> RAILWAY_SIGN_WALL_BIG_4_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignWallBig.TileEntityRailwaySignWallBig(4, pos, state), BlockList.RAILWAY_SIGN_WALL_BIG_4.get()));
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/ziyue/tjmetro/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public interface BlockList
RegistryObject<Block> RAILWAY_SIGN_WALL_8 = new RegistryObject<>(() -> new BlockRailwaySignWall(8));
RegistryObject<Block> RAILWAY_SIGN_WALL_10 = new RegistryObject<>(() -> new BlockRailwaySignWall(10));
RegistryObject<Block> RAILWAY_SIGN_WALL_MIDDLE = new RegistryObject<>(() -> new BlockRailwaySignWall(0));
RegistryObject<Block> RAILWAY_SIGN_WALL_DOUBLE_4 = new RegistryObject<>(() -> new BlockRailwaySignWallDouble(4));
RegistryObject<Block> RAILWAY_SIGN_WALL_DOUBLE_6 = new RegistryObject<>(() -> new BlockRailwaySignWallDouble(6));
RegistryObject<Block> RAILWAY_SIGN_WALL_DOUBLE_8 = new RegistryObject<>(() -> new BlockRailwaySignWallDouble(8));
RegistryObject<Block> RAILWAY_SIGN_WALL_DOUBLE_10 = new RegistryObject<>(() -> new BlockRailwaySignWallDouble(10));
RegistryObject<Block> RAILWAY_SIGN_WALL_DOUBLE_MIDDLE = new RegistryObject<>(() -> new BlockRailwaySignWallDouble(0));
RegistryObject<Block> RAILWAY_SIGN_WALL_BIG_2 = new RegistryObject<>(() -> new BlockRailwaySignWallBig(2));
RegistryObject<Block> RAILWAY_SIGN_WALL_BIG_3 = new RegistryObject<>(() -> new BlockRailwaySignWallBig(3));
RegistryObject<Block> RAILWAY_SIGN_WALL_BIG_4 = new RegistryObject<>(() -> new BlockRailwaySignWallBig(4));
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/ziyue/tjmetro/TianjinMetro.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public static void init(
registerBlockItem.accept("railway_sign_wall_6", BlockList.RAILWAY_SIGN_WALL_6, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_8", BlockList.RAILWAY_SIGN_WALL_8, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_10", BlockList.RAILWAY_SIGN_WALL_10, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_double_4", BlockList.RAILWAY_SIGN_WALL_DOUBLE_4, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_double_6", BlockList.RAILWAY_SIGN_WALL_DOUBLE_6, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_double_8", BlockList.RAILWAY_SIGN_WALL_DOUBLE_8, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_double_10", BlockList.RAILWAY_SIGN_WALL_DOUBLE_10, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_big_2", BlockList.RAILWAY_SIGN_WALL_BIG_2, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_big_3", BlockList.RAILWAY_SIGN_WALL_BIG_3, RAILWAYS);
registerBlockItem.accept("railway_sign_wall_big_4", BlockList.RAILWAY_SIGN_WALL_BIG_4, RAILWAYS);
Expand All @@ -105,6 +109,7 @@ public static void init(

registerBlock.accept("railway_sign_wall_middle", BlockList.RAILWAY_SIGN_WALL_MIDDLE);
registerBlock.accept("railway_sign_wall_big_middle", BlockList.RAILWAY_SIGN_WALL_BIG_MIDDLE);
registerBlock.accept("railway_sign_wall_double_middle", BlockList.RAILWAY_SIGN_WALL_DOUBLE_MIDDLE);
registerBlock.accept("railway_sign_tianjin_middle", BlockList.RAILWAY_SIGN_TIANJIN_MIDDLE);

registerBlockEntityType.accept("station_name_sign_2", BlockEntityTypes.STATION_NAME_SIGN_ENTITY_2);
Expand All @@ -121,6 +126,10 @@ public static void init(
registerBlockEntityType.accept("railway_sign_wall_6", BlockEntityTypes.RAILWAY_SIGN_WALL_6_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_8", BlockEntityTypes.RAILWAY_SIGN_WALL_8_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_10", BlockEntityTypes.RAILWAY_SIGN_WALL_10_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_double_4", BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_4_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_double_6", BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_6_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_double_8", BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_8_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_double_10", BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_10_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_big_2", BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_2_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_big_3", BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_3_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_big_4", BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_4_TILE_ENTITY);
Expand Down Expand Up @@ -149,6 +158,7 @@ public static void init(
mtr.Registry.registerNetworkReceiver(PACKET_UPDATE_CUSTOM_CONTENT, PacketGuiServer::receiveCustomContentC2S);
mtr.Registry.registerNetworkReceiver(PACKET_UPDATE_CUSTOM_COLOR, PacketGuiServer::receiveCustomColorC2S);
mtr.Registry.registerNetworkReceiver(PACKET_SIGN_TYPES, PacketGuiServer::receiveSignIdsC2S);
mtr.Registry.registerNetworkReceiver(PACKET_SIGN_TYPES_DOUBLE, PacketGuiServer::receiveSignIdsDoubleC2S);
}

@FunctionalInterface
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/ziyue/tjmetro/TianjinMetroClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static void init() {
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_6_TILE_ENTITY.get(), RenderRailwaySignWall::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_8_TILE_ENTITY.get(), RenderRailwaySignWall::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_10_TILE_ENTITY.get(), RenderRailwaySignWall::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_4_TILE_ENTITY.get(), RenderRailwaySignWallDouble::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_6_TILE_ENTITY.get(), RenderRailwaySignWallDouble::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_8_TILE_ENTITY.get(), RenderRailwaySignWallDouble::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_10_TILE_ENTITY.get(), RenderRailwaySignWallDouble::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_2_TILE_ENTITY.get(), RenderRailwaySignWall::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_3_TILE_ENTITY.get(), RenderRailwaySignWall::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_4_TILE_ENTITY.get(), RenderRailwaySignWall::new);
Expand All @@ -75,5 +79,6 @@ public static void init() {
RegistryClient.registerNetworkReceiver(IPacket.PACKET_OPEN_CUSTOM_CONTENT_SCREEN, packet -> PacketGuiClient.openCustomContentScreenS2C(Minecraft.getInstance(), packet));
RegistryClient.registerNetworkReceiver(IPacket.PACKET_OPEN_CUSTOM_COLOR_SCREEN, packet -> PacketGuiClient.openCustomColorScreenS2C(Minecraft.getInstance(), packet));
RegistryClient.registerNetworkReceiver(IPacket.PACKET_OPEN_RAILWAY_SIGN_SCREEN, packet -> PacketGuiClient.openRailwaySignScreenS2C(Minecraft.getInstance(), packet));
RegistryClient.registerNetworkReceiver(IPacket.PACKET_OPEN_RAILWAY_SIGN_WALL_DOUBLE_SCREEN, packet -> PacketGuiClient.openRailwaySignWallDoubleScreenS2C(Minecraft.getInstance(), packet));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package ziyue.tjmetro.blocks;

import mtr.block.IBlock;
import mtr.mappings.BlockEntityClientSerializableMapper;
import mtr.mappings.BlockEntityMapper;
import mtr.mappings.Text;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ziyue.tjmetro.BlockEntityTypes;
import ziyue.tjmetro.BlockList;
import ziyue.tjmetro.blocks.base.BlockRailwaySignBase;
import ziyue.tjmetro.blocks.base.IRailwaySign;
import ziyue.tjmetro.packet.PacketGuiServer;

import java.util.*;

/**
* Railway Sign Wall, must be even.
*
* @author ZiYueCommentary
* @see BlockRailwaySignBase
* @see BlockRailwaySignWall
* @see BlockRailwaySignWallBig
* @since beta-1
*/

public class BlockRailwaySignWallDouble extends BlockRailwaySignWall
{
public BlockRailwaySignWallDouble(int length) {
super(length);
}

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand interactionHand, BlockHitResult hit) {
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
final BlockPos checkPos = findEndWithDirection(world, pos, facing, false);
return IBlock.checkHoldingBrush(world, player, () -> {
if (checkPos != null) {
PacketGuiServer.openRailwaySignWallDoubleScreenS2C((ServerPlayer) player, checkPos);
}
});
}

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (world.isClientSide) return;
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
for (int i = 1; i < getMiddleLength(); i++) {
world.setBlock(pos.relative(facing.getClockWise(), i), BlockList.RAILWAY_SIGN_WALL_DOUBLE_MIDDLE.get().defaultBlockState().setValue(FACING, facing).setValue(EOS, false), 3);
}
world.setBlock(pos.relative(facing.getClockWise(), getMiddleLength()), BlockList.RAILWAY_SIGN_WALL_DOUBLE_MIDDLE.get().defaultBlockState().setValue(FACING, facing).setValue(EOS, true), 3);
world.updateNeighborsAt(pos, Blocks.AIR);
state.updateNeighbourShapes(world, pos, 3);
}

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
final boolean isNext = ((!state.getValue(EOS) && (direction == facing.getClockWise())) || state.is(BlockList.RAILWAY_SIGN_WALL_DOUBLE_MIDDLE.get())) && (direction == facing.getCounterClockWise());
if (isNext && !(newState.getBlock() instanceof BlockRailwaySignBase)) {
return Blocks.AIR.defaultBlockState();
} else {
return state;
}
}

@Override
protected BlockPos findEndWithDirection(Level world, BlockPos startPos, Direction direction, boolean allowOpposite) {
return IRailwaySign.findEndWithDirection(world, startPos, direction, allowOpposite, BlockList.RAILWAY_SIGN_WALL_DOUBLE_MIDDLE.get());
}

@Override
public String getDescriptionId() {
return "block.tjmetro.railway_sign_wall_double";
}

@Override
public BlockEntityMapper createBlockEntity(BlockPos pos, BlockState state) {
if (this == BlockList.RAILWAY_SIGN_WALL_DOUBLE_MIDDLE.get())
return null;
else
return new TileEntityRailwaySignWallDouble(length, pos, state);
}

public static class TileEntityRailwaySignWallDouble extends BlockEntityClientSerializableMapper
{
protected final List<Set<Long>> selectedIds;
protected final String[][] signIds;
protected static final String KEY_SELECTED_IDS = "selected_ids";
protected static final String KEY_SIGN_LENGTH = "sign_length";

public TileEntityRailwaySignWallDouble(int length, BlockPos pos, BlockState state) {
super(getType(length), pos, state);
signIds = new String[2][length];
selectedIds = new ArrayList<>();
selectedIds.add(new HashSet<>());
selectedIds.add(new HashSet<>());
}

@Override
public void readCompoundTag(CompoundTag compoundTag) {
selectedIds.forEach(Set::clear);
for (int i = 0; i < 2; i++) {
Arrays.stream(compoundTag.getLongArray(KEY_SELECTED_IDS + i)).forEach(selectedIds.get(i)::add);
for (int j = 0; j < signIds[i].length; j++) {
final String signId = compoundTag.getString(KEY_SIGN_LENGTH + i + j);
signIds[i][j] = signId.isEmpty() ? null : signId;
}
}
}

@Override
public void writeCompoundTag(CompoundTag compoundTag) {
for (int i = 0; i < 2; i++) {
compoundTag.putLongArray(KEY_SELECTED_IDS + i, new ArrayList<>(selectedIds.get(i)));
for (int j = 0; j < signIds[i].length; j++) {
compoundTag.putString(KEY_SIGN_LENGTH + i + j, signIds[i][j] == null ? "" : signIds[i][j]);
}
}
}

public void setData(List<Set<Long>> selectedIds, String[][] signTypes) {
this.selectedIds.forEach(Set::clear);
this.selectedIds.addAll(selectedIds);
if (signIds[0].length == signTypes[0].length) { // Both lines have the same length
System.arraycopy(signTypes, 0, signIds, 0, signTypes.length);
}
setChanged();
syncData();
}

public List<Set<Long>> getSelectedIds() {
return selectedIds;
}

public String[][] getSignIds() {
return signIds;
}

protected static BlockEntityType<?> getType(int length) {
return switch (length) {
case 4 -> BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_4_TILE_ENTITY.get();
case 6 -> BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_6_TILE_ENTITY.get();
case 8 -> BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_8_TILE_ENTITY.get();
case 10 -> BlockEntityTypes.RAILWAY_SIGN_WALL_DOUBLE_10_TILE_ENTITY.get();
default -> null;
};
}
}
}
2 changes: 2 additions & 0 deletions common/src/main/java/ziyue/tjmetro/packet/IPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface IPacket
ResourceLocation PACKET_OPEN_CUSTOM_COLOR_SCREEN = new ResourceLocation(Reference.MOD_ID, "packet_open_custom_color_screen");
ResourceLocation PACKET_UPDATE_CUSTOM_COLOR = new ResourceLocation(Reference.MOD_ID, "packet_update_custom_color_screen");
ResourceLocation PACKET_OPEN_RAILWAY_SIGN_SCREEN = new ResourceLocation(Reference.MOD_ID, "packet_open_railway_sign_screen");
ResourceLocation PACKET_OPEN_RAILWAY_SIGN_WALL_DOUBLE_SCREEN = new ResourceLocation(Reference.MOD_ID, "packet_open_railway_sign_wall_double_screen");
ResourceLocation PACKET_SIGN_TYPES = new ResourceLocation(MTR.MOD_ID, "packet_sign_types");
ResourceLocation PACKET_SIGN_TYPES_DOUBLE = new ResourceLocation(MTR.MOD_ID, "packet_sign_types_double");
}
10 changes: 10 additions & 0 deletions common/src/main/java/ziyue/tjmetro/packet/PacketGuiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ziyue.tjmetro.screen.ColorPickerScreen;
import ziyue.tjmetro.screen.CustomContentScreen;
import ziyue.tjmetro.screen.RailwaySignScreen;
import ziyue.tjmetro.screen.RailwaySignWallDoubleScreen;

import static ziyue.tjmetro.packet.IPacket.*;

Expand Down Expand Up @@ -68,4 +69,13 @@ public static void openRailwaySignScreenS2C(Minecraft minecraftClient, FriendlyB
}
});
}

public static void openRailwaySignWallDoubleScreenS2C(Minecraft minecraftClient, FriendlyByteBuf packet) {
final BlockPos pos = packet.readBlockPos();
minecraftClient.execute(() -> {
if (!(minecraftClient.screen instanceof RailwaySignScreen)) {
UtilitiesClient.setScreen(minecraftClient, new RailwaySignWallDoubleScreen(pos));
}
});
}
}
Loading

0 comments on commit d4a4254

Please sign in to comment.