Skip to content

Commit

Permalink
✔ Railway Sign Tianjin
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed May 5, 2024
1 parent 5bcf122 commit eb145c6
Show file tree
Hide file tree
Showing 58 changed files with 723 additions and 55 deletions.
1 change: 0 additions & 1 deletion common/src/main/java/ziyue/tjmetro/BlockEntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public interface BlockEntityTypes
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_5_EVEN_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(5, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_5_EVEN.get()));
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_6_EVEN_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(6, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_6_EVEN.get()));
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_7_EVEN_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(7, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_7_EVEN.get()));
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_2_ODD_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(2, true, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_2_ODD.get()));
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_3_ODD_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(3, true, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_3_ODD.get()));
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_4_ODD_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(4, true, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_4_ODD.get()));
RegistryObject<BlockEntityType<BlockRailwaySignTianjin.TileEntityRailwaySignTianjin>> RAILWAY_SIGN_TIANJIN_5_ODD_TILE_ENTITY = new RegistryObject<>(() -> RegistryUtilities.getBlockEntityType((pos, state) -> new BlockRailwaySignTianjin.TileEntityRailwaySignTianjin(5, true, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_5_ODD.get()));
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/ziyue/tjmetro/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public interface BlockList
RegistryObject<Block> RAILWAY_SIGN_WALL_BIG_9 = new RegistryObject<>(() -> new BlockRailwaySignWallBig(9));
RegistryObject<Block> RAILWAY_SIGN_WALL_BIG_10 = new RegistryObject<>(() -> new BlockRailwaySignWallBig(10));
RegistryObject<Block> RAILWAY_SIGN_WALL_BIG_MIDDLE = new RegistryObject<>(() -> new BlockRailwaySignWallBig(0));
RegistryObject<Block> RAILWAY_SIGN_TIANJIN_2_ODD = new RegistryObject<>(() -> new BlockRailwaySignTianjin(2, true));
RegistryObject<Block> RAILWAY_SIGN_TIANJIN_3_ODD = new RegistryObject<>(() -> new BlockRailwaySignTianjin(3, true));
RegistryObject<Block> RAILWAY_SIGN_TIANJIN_4_ODD = new RegistryObject<>(() -> new BlockRailwaySignTianjin(4, true));
RegistryObject<Block> RAILWAY_SIGN_TIANJIN_5_ODD = new RegistryObject<>(() -> new BlockRailwaySignTianjin(5, true));
Expand Down
2 changes: 0 additions & 2 deletions common/src/main/java/ziyue/tjmetro/TianjinMetro.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public static void init(
registerBlockItem.accept("railway_sign_wall_big_8", BlockList.RAILWAY_SIGN_WALL_BIG_8, RAILWAY_SIGNS);
registerBlockItem.accept("railway_sign_wall_big_9", BlockList.RAILWAY_SIGN_WALL_BIG_9, RAILWAY_SIGNS);
registerBlockItem.accept("railway_sign_wall_big_10", BlockList.RAILWAY_SIGN_WALL_BIG_10, RAILWAY_SIGNS);
registerBlockItem.accept("railway_sign_tianjin_2_odd", BlockList.RAILWAY_SIGN_TIANJIN_2_ODD, RAILWAY_SIGNS);
registerBlockItem.accept("railway_sign_tianjin_3_odd", BlockList.RAILWAY_SIGN_TIANJIN_3_ODD, RAILWAY_SIGNS);
registerBlockItem.accept("railway_sign_tianjin_4_odd", BlockList.RAILWAY_SIGN_TIANJIN_4_ODD, RAILWAY_SIGNS);
registerBlockItem.accept("railway_sign_tianjin_5_odd", BlockList.RAILWAY_SIGN_TIANJIN_5_ODD, RAILWAY_SIGNS);
Expand Down Expand Up @@ -153,7 +152,6 @@ public static void init(
registerBlockEntityType.accept("railway_sign_wall_big_8", BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_8_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_big_9", BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_9_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_wall_big_10", BlockEntityTypes.RAILWAY_SIGN_WALL_BIG_10_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_tianjin_2_odd", BlockEntityTypes.RAILWAY_SIGN_TIANJIN_2_ODD_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_tianjin_3_odd", BlockEntityTypes.RAILWAY_SIGN_TIANJIN_3_ODD_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_tianjin_4_odd", BlockEntityTypes.RAILWAY_SIGN_TIANJIN_4_ODD_TILE_ENTITY);
registerBlockEntityType.accept("railway_sign_tianjin_5_odd", BlockEntityTypes.RAILWAY_SIGN_TIANJIN_5_ODD_TILE_ENTITY);
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/ziyue/tjmetro/TianjinMetroClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public static void init() {
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_5_EVEN_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_6_EVEN_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_7_EVEN_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_2_ODD_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_3_ODD_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_4_ODD_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
RegistryClient.registerTileEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_5_ODD_TILE_ENTITY.get(), RenderRailwaySignTianjin::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ziyue.tjmetro.block;

import mtr.block.IBlock;
import mtr.mappings.BlockEntityMapper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -8,11 +9,13 @@
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.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import ziyue.tjmetro.BlockEntityTypes;
import ziyue.tjmetro.BlockList;
Expand All @@ -36,12 +39,36 @@ public BlockState updateShape(BlockState state, Direction direction, BlockState

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
IRailwaySign.setPlacedBy(world, pos, state, BlockList.RAILWAY_SIGN_TIANJIN_MIDDLE.get(), getMiddleLength());
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_TIANJIN_MIDDLE.get().defaultBlockState().setValue(FACING, facing), 3);
}
world.setBlock(pos.relative(facing.getClockWise(), getMiddleLength() + 1), state.getBlock().defaultBlockState().setValue(FACING, facing.getOpposite()), 3);
world.updateNeighborsAt(pos, Blocks.AIR);
state.updateNeighbourShapes(world, pos, 3);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos pos, CollisionContext collisionContext) {
return IRailwaySign.getShape(state, getXStart(), BlockList.RAILWAY_SIGN_TIANJIN_MIDDLE.get());
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
if (state.is(BlockList.RAILWAY_SIGN_TIANJIN_MIDDLE.get())) {
return IBlock.getVoxelShapeByDirection(0, 0, 7, 16, 9, 9, facing);
} else {
final VoxelShape main = IBlock.getVoxelShapeByDirection(getXStart() - 0.5, 0, 7, 16, 9, 9, facing);
final VoxelShape pole = IBlock.getVoxelShapeByDirection(getXStart() + 3, 0, 7.5, getXStart() + 4, 16, 8.5, facing);
return Shapes.or(main, pole);
}
}

@Override
public int getXStart() {
return switch (length % 4) {
case 1 -> isOdd ? 4 : 12;
case 2 -> isOdd ? 0 : 8;
case 3 -> isOdd ? 12 : 4;
default -> isOdd ? 8 : 0;
};
}

@Override
Expand Down Expand Up @@ -72,7 +99,7 @@ public TileEntityRailwaySignTianjin(int length, boolean isOdd, BlockPos pos, Blo
public static BlockEntityType<?> getType(int length, boolean isOdd) {
return switch (length) {
case 2 ->
isOdd ? BlockEntityTypes.RAILWAY_SIGN_TIANJIN_2_ODD_TILE_ENTITY.get() : BlockEntityTypes.RAILWAY_SIGN_TIANJIN_2_EVEN_TILE_ENTITY.get();
isOdd ? null : BlockEntityTypes.RAILWAY_SIGN_TIANJIN_2_EVEN_TILE_ENTITY.get();
case 3 ->
isOdd ? BlockEntityTypes.RAILWAY_SIGN_TIANJIN_3_ODD_TILE_ENTITY.get() : BlockEntityTypes.RAILWAY_SIGN_TIANJIN_3_EVEN_TILE_ENTITY.get();
case 4 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import mtr.block.BlockRailwaySignPole;
import mtr.block.IBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

public class BlockRailwaySignTianjinPole extends BlockRailwaySignPole
{
Expand All @@ -17,6 +23,18 @@ public BlockRailwaySignTianjinPole(Properties settings) {
super(settings);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos pos, CollisionContext collisionContext) {
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
return switch (IBlock.getStatePropertySafe(state, TYPE)) {
case 0 -> IBlock.getVoxelShapeByDirection(3, 0, 7.5, 4, 16, 8.5, facing);
case 1 -> IBlock.getVoxelShapeByDirection(15, 0, 7.5, 16, 16, 8.5, facing);
case 2 -> IBlock.getVoxelShapeByDirection(11, 0, 7.5, 12, 16, 8.5, facing);
case 3 -> IBlock.getVoxelShapeByDirection(7, 0, 7.5, 8, 16, 8.5, facing);
default -> Shapes.block();
};
}

@Override
protected BlockState placeWithState(BlockState stateBelow) {
final int type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@

public class BlockStationNameEntranceTianjin extends BlockStationNameBase implements IBlock
{
/**
* 0 - short<br>
* 1 - tall<br>
* 2 - short, no routes<br>
* 3 - tall, no routes<br>
* 4 - short, no background<br>
* 5 - tall, no background<br>
* 6 - short, no routes, no background<br>
/*
* 0 - short
* 1 - tall
* 2 - short, no routes
* 3 - tall, no routes
* 4 - short, no background
* 5 - tall, no background
* 6 - short, no routes, no background
* 7 - tall, no routes, no background
*/
public static final IntegerProperty STYLE = IntegerProperty.create("style", 0, 7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public BlockRailwaySignBase(Properties properties, int length, boolean isOdd) {
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand interactionHand, BlockHitResult hit) {
return IBlockExtends.checkHoldingBrushOrWrench(world, player, () -> {
final Direction facing = IBlock.getStatePropertySafe(state, FACING);
final BlockPos checkPos = findEndWithDirection(world, pos, facing, false);
if (checkPos != null) {
PacketGuiServer.openRailwaySignScreenS2C((ServerPlayer) player, checkPos);
final Direction hitSide = hit.getDirection();
if (hitSide == facing || hitSide == facing.getOpposite()) {
final BlockPos checkPos = findEndWithDirection(world, pos, hitSide.getOpposite(), false);
if (checkPos != null) {
PacketGuiServer.openRailwaySignScreenS2C((ServerPlayer) player, checkPos);
}
}
});
}
Expand Down
13 changes: 10 additions & 3 deletions common/src/main/java/ziyue/tjmetro/client/ClientCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import mtr.MTR;
import mtr.client.ClientCache.ColorNameTuple;
import mtr.client.ClientCache.PlatformRouteDetails;
import mtr.client.Config;
import mtr.data.*;
import mtr.mappings.Utilities;
import mtr.client.ClientCache.PlatformRouteDetails;
import mtr.client.ClientCache.ColorNameTuple;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.Tuple;
import ziyue.tjmetro.Reference;
import ziyue.tjmetro.TianjinMetro;

Expand Down Expand Up @@ -143,6 +142,14 @@ public DynamicResource getRouteMap(long platformId, boolean vertical, boolean fl
return getResource(String.format("tjmetro_route_map_%s_%s_%s_%s_%s", platformId, vertical, flip, aspectRatio, transparentWhite), () -> RouteMapGenerator.generateRouteMap(platformId, vertical, flip, aspectRatio, transparentWhite), transparentWhite ? ClientCache.DefaultRenderingColor.TRANSPARENT : ClientCache.DefaultRenderingColor.WHITE);
}

public DynamicResource getRouteSquare(int color, String routeName, IGui.HorizontalAlignment horizontalAlignment) {
return getResource(String.format("tjmetro_route_square_%s_%s_%s", color, routeName, horizontalAlignment), () -> RouteMapGenerator.generateRouteSquare(color, routeName, horizontalAlignment), DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getSignText(String string, HorizontalAlignment horizontalAlignment, float paddingScale, int backgroundColor, int textColor) {
return getResource(String.format("tjmetro_sign_text_%s_%s_%s_%s_%s", string, horizontalAlignment, paddingScale, backgroundColor, textColor), () -> RouteMapGenerator.generateSignText(string, horizontalAlignment, paddingScale, backgroundColor, textColor), DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getStationNameEntrance(long stationId, long selectedId, int style, String stationName, float aspectRatio) {
return getResource(String.format("tjmetro_station_name_entrance_%s_%s_%s_%s_%s", stationId, selectedId, style, stationName, aspectRatio), () -> RouteMapGenerator.generateStationNameEntrance(stationId, selectedId, style, stationName, aspectRatio), ClientCache.DefaultRenderingColor.TRANSPARENT);
}
Expand Down
43 changes: 43 additions & 0 deletions common/src/main/java/ziyue/tjmetro/client/RouteMapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,49 @@ public static NativeImage generateRouteMap(long platformId, boolean vertical, bo
return null;
}

public static NativeImage generateRouteSquare(int color, String routeName, HorizontalAlignment horizontalAlignment) {
try {
final int padding = scale / 32;
final ClientCache.Text text = ClientCache.DATA_CACHE.getText(routeName, Integer.MAX_VALUE, (int) ((fontSizeBig + fontSizeSmall) * mtr.client.ClientCache.LINE_HEIGHT_MULTIPLIER), fontSizeBig, fontSizeSmall, padding, horizontalAlignment);

final int width = text.renderWidth() + padding * 2;
final int height = text.height() + padding * 2;
final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, width, height, false);
nativeImage.fillRect(0, 0, width, height, invertColor(ARGB_BLACK | color));
drawString(nativeImage, text, width / 2, height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
return nativeImage;
} catch (Exception e) {
TianjinMetro.LOGGER.error(e.getMessage());
}

return null;
}

public static NativeImage generateSignText(String string, HorizontalAlignment horizontalAlignment, float paddingScale, int backgroundColor, int textColor) {
try {
final int height = scale;
final int padding = Math.round(height * paddingScale);
final int tileSize = height - padding * 2;
final int tilePadding = tileSize / 4;

final ClientCache.Text text = ClientCache.DATA_CACHE.getText(string, Integer.MAX_VALUE, (int) (tileSize * mtr.client.ClientCache.LINE_HEIGHT_MULTIPLIER), tileSize * 3 / 5, tileSize * 3 / 10, tilePadding, horizontalAlignment);
final int width = text.renderWidth() - tilePadding * 2;

if (width <= 0 || height <= 0) return null;

final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, width, height, false);
nativeImage.fillRect(0, 0, width, height, 0);
drawString(nativeImage, text, width / 2, height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, backgroundColor, textColor, false);
clearColor(nativeImage, invertColor(backgroundColor));

return nativeImage;
} catch (Exception e) {
TianjinMetro.LOGGER.error(e.getMessage());
}

return null;
}

public static NativeImage generateStationNameEntrance(long stationId, long selectedId, int style, String stationName, float aspectRatio) {
if (aspectRatio <= 0) return null;

Expand Down
Loading

0 comments on commit eb145c6

Please sign in to comment.