Skip to content

Commit

Permalink
Automatic Platform Gates (Tianjin, Line 9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Aug 8, 2024
1 parent a48dd92 commit d3fe0a2
Show file tree
Hide file tree
Showing 21 changed files with 1,149 additions and 86 deletions.
2 changes: 2 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/BlockEntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public interface BlockEntityTypes
BlockEntityTypeRegistryObject<BlockRailwaySignTianjinBMT.BlockEntity> RAILWAY_SIGN_TIANJIN_BMT_6_EVEN = Registry.registerBlockEntityType("railway_sign_tianjin_bmt_6_even", (pos, state) -> new BlockRailwaySignTianjinBMT.BlockEntity(6, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_BMT_6_EVEN::get);
BlockEntityTypeRegistryObject<BlockRailwaySignTianjinBMT.BlockEntity> RAILWAY_SIGN_TIANJIN_BMT_7_EVEN = Registry.registerBlockEntityType("railway_sign_tianjin_bmt_7_even", (pos, state) -> new BlockRailwaySignTianjinBMT.BlockEntity(7, false, pos, state), BlockList.RAILWAY_SIGN_TIANJIN_BMT_7_EVEN::get);
BlockEntityTypeRegistryObject<BlockAPGDoorTianjin.BlockEntity> APG_DOOR_TIANJIN = Registry.registerBlockEntityType("apg_door_tianjin", BlockAPGDoorTianjin.BlockEntity::new, BlockList.APG_DOOR_TIANJIN::get);
BlockEntityTypeRegistryObject<BlockAPGDoorTianjinBMT.BlockEntity> APG_DOOR_TIANJIN_BMT = Registry.registerBlockEntityType("apg_door_tianjin_bmt", BlockAPGDoorTianjinBMT.BlockEntity::new, BlockList.APG_DOOR_TIANJIN_BMT::get);
BlockEntityTypeRegistryObject<BlockAPGGlassTianjinBMT.BlockEntity> APG_GLASS_TIANJIN_BMT = Registry.registerBlockEntityType("apg_glass_tianjin_bmt", BlockAPGGlassTianjinBMT.BlockEntity::new, BlockList.APG_GLASS_TIANJIN_BMT::get);
BlockEntityTypeRegistryObject<BlockMetalPoleBMT.BlockEntity> METAL_POLE_BMT = Registry.registerBlockEntityType("metal_pole_bmt", BlockMetalPoleBMT.BlockEntity::new, BlockList.METAL_POLE_BMT::get);

static void registerBlockEntities() {
Expand Down
3 changes: 3 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public interface BlockList
BlockRegistryObject APG_DOOR_TIANJIN = Registry.registerBlock("apg_door_tianjin", () -> new Block(new BlockAPGDoorTianjin()));
BlockRegistryObject APG_GLASS_TIANJIN = Registry.registerBlock("apg_glass_tianjin", () -> new Block(new BlockAPGGlassTianjin()));
BlockRegistryObject APG_GLASS_END_TIANJIN = Registry.registerBlock("apg_glass_end_tianjin", () -> new Block(new BlockAPGGlassEndTianjin()));
BlockRegistryObject APG_DOOR_TIANJIN_BMT = Registry.registerBlock("apg_door_tianjin_bmt", () -> new Block(new BlockAPGDoorTianjinBMT()));
BlockRegistryObject APG_GLASS_TIANJIN_BMT = Registry.registerBlock("apg_glass_tianjin_bmt", () -> new Block(new BlockAPGGlassTianjinBMT()));
BlockRegistryObject APG_GLASS_END_TIANJIN_BMT = Registry.registerBlock("apg_glass_end_tianjin_bmt", () -> new Block(new BlockAPGGlassEndTianjinBMT()));
BlockRegistryObject METAL_POLE_BMT = Registry.registerBlockWithBlockItem("metal_pole_bmt", () -> new Block(new BlockMetalPoleBMT()), BlockItemExtension::new, DECORATION);

static void registerBlocks() {
Expand Down
3 changes: 3 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public interface ItemList
ItemRegistryObject APG_DOOR_TIANJIN = Registry.registerItem("apg_door_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_DOOR_TIANJIN, itemSettings)), GATES);
ItemRegistryObject APG_GLASS_TIANJIN = Registry.registerItem("apg_glass_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_GLASS_TIANJIN, itemSettings)), GATES);
ItemRegistryObject APG_GLASS_END_TIANJIN = Registry.registerItem("apg_glass_end_tianjin", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_GLASS_END_TIANJIN, itemSettings)), GATES);
ItemRegistryObject APG_DOOR_TIANJIN_BMT = Registry.registerItem("apg_door_tianjin_bmt", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_DOOR_TIANJIN_BMT, itemSettings)), GATES);
ItemRegistryObject APG_GLASS_TIANJIN_BMT = Registry.registerItem("apg_glass_tianjin_bmt", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_GLASS_TIANJIN_BMT, itemSettings)), GATES);
ItemRegistryObject APG_GLASS_END_TIANJIN_BMT = Registry.registerItem("apg_glass_end_tianjin_bmt", itemSettings -> new Item(new ItemPSDAPGTianjinBase(BlockList.APG_GLASS_END_TIANJIN_BMT, itemSettings)), GATES);

static void registerItems() {
// Calling this class to initialize constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import org.mtr.mapping.holder.RenderLayer;
import org.mtr.mapping.holder.Screen;
import org.mtr.mapping.mapper.TextHelper;
import org.mtr.mod.Blocks;
import org.mtr.mod.Items;
import org.mtr.mod.render.RenderAPGGlass;
import org.mtr.mod.render.RenderPSDAPGDoor;
import ziyue.tjmetro.mod.client.Filters;
import ziyue.tjmetro.mod.config.ConfigClient;
import ziyue.tjmetro.mapping.FilterBuilder;
import ziyue.tjmetro.mod.render.*;
Expand All @@ -33,6 +29,9 @@ public static void init() {
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_DOOR_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_GLASS_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_GLASS_END_TIANJIN);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_DOOR_TIANJIN_BMT);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_GLASS_TIANJIN_BMT);
RegistryClient.registerBlockRenderType(RenderLayer.getCutout(), BlockList.APG_GLASS_END_TIANJIN_BMT);
RegistryClient.registerBlockRenderType(RenderLayer.getTranslucent(), BlockList.ROLLING);

RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.STATION_NAME_SIGN_1, RenderStationNameSign::new);
Expand Down Expand Up @@ -89,6 +88,8 @@ public static void init() {
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_BMT_6_EVEN, RenderRailwaySignTianjinBMT::new);
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.RAILWAY_SIGN_TIANJIN_BMT_7_EVEN, RenderRailwaySignTianjinBMT::new);
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.APG_DOOR_TIANJIN, dispatcher -> new RenderPSDAPGDoor<>(dispatcher, 2));
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.APG_DOOR_TIANJIN_BMT, dispatcher -> new RenderPSDAPGDoor<>(dispatcher, 2));
RegistryClient.registerBlockEntityRenderer(BlockEntityTypes.APG_GLASS_TIANJIN_BMT, RenderAPGGlassTianjinBMT::new);

RegistryClient.registerEntityRenderer(EntityTypes.SEAT, RenderSeat::new);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ziyue.tjmetro.mod.block;

import org.mtr.mapping.holder.BlockPos;
import org.mtr.mapping.holder.BlockState;
import org.mtr.mapping.holder.Item;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mod.block.BlockPSDAPGDoorBase;
import ziyue.tjmetro.mod.BlockEntityTypes;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagAPGTianjinBMT;

import javax.annotation.Nonnull;

public class BlockAPGDoorTianjinBMT extends BlockPSDAPGDoorBase implements BlockFlagAPGTianjinBMT
{
@Override
protected boolean isAPG() {
return true;
}

@Nonnull
@Override
public Item asItem2() {
return ItemList.APG_DOOR_TIANJIN_BMT.get();
}

@Override
public BlockEntityExtension createBlockEntity(BlockPos blockPos, BlockState blockState) {
return new BlockEntity(blockPos, blockState);
}

public static class BlockEntity extends BlockEntityBase {
public BlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.APG_DOOR_TIANJIN_BMT.get(), pos, state);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ziyue.tjmetro.mod.block;

import org.mtr.mapping.holder.Item;
import org.mtr.mod.block.BlockAPGGlassEnd;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagAPGTianjinBMT;

import javax.annotation.Nonnull;

public class BlockAPGGlassEndTianjinBMT extends BlockAPGGlassEnd implements BlockFlagAPGTianjinBMT
{
@Override
protected boolean isAPG() {
return true;
}

@Nonnull
@Override
public Item asItem2() {
return ItemList.APG_GLASS_END_TIANJIN_BMT.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package ziyue.tjmetro.mod.block;

import org.mtr.mapping.holder.*;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mapping.tool.HolderBase;
import org.mtr.mod.block.BlockAPGGlass;
import org.mtr.mod.block.BlockPSDTop;
import org.mtr.mod.block.IBlock;
import ziyue.tjmetro.mod.BlockEntityTypes;
import ziyue.tjmetro.mod.BlockList;
import ziyue.tjmetro.mod.ItemList;
import ziyue.tjmetro.mod.block.base.BlockFlagAPGTianjinBMT;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;

public class BlockAPGGlassTianjinBMT extends BlockAPGGlass implements BlockFlagAPGTianjinBMT
{
public static final EnumProperty<EnumDoorType> STYLE = EnumProperty.of("style", EnumDoorType.class);

@Nonnull
@Override
public ActionResult onUse2(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
final double y = hit.getPos().getYMapped();
if (IBlock.getStatePropertySafe(state, HALF) == DoubleBlockHalf.UPPER) {
return IBlock.checkHoldingItem(world, player, item -> {
if (item.data == ItemList.WRENCH.get().data) {
world.setBlockState(pos, state.cycle(new Property<>(STYLE.data)));
BiConsumer<Boolean, Direction> setStyle = (bool, direction) -> {
EnumDoorType style = IBlock.getStatePropertySafe(world, pos, STYLE);
BlockPos offsetPos = pos;
for (; ; ) {
if (IBlockExtension.isBlock(world.getBlockState(offsetPos), BlockList.APG_DOOR_TIANJIN_BMT.get())) {
offsetPos = offsetPos.offset(direction);
if (bool) {
final int id = (style.asId() - 1);
style = EnumDoorType.byId(id < 0 ? 2 : id % 3);
} else {
style = EnumDoorType.byId((style.asId() + 1) % 3);
}
} else if (IBlockExtension.isBlock(world.getBlockState(offsetPos), BlockList.APG_GLASS_TIANJIN_BMT.get())) {
world.setBlockState(offsetPos, world.getBlockState(offsetPos).with(new Property<>(STYLE.data), style));
} else {
break;
}
offsetPos = offsetPos.offset(direction);
}
};
setStyle.accept(true, IBlock.getStatePropertySafe(state, FACING).rotateYClockwise());
setStyle.accept(false, IBlock.getStatePropertySafe(state, FACING).rotateYCounterclockwise());
} else {
world.setBlockState(pos, state.cycle(new Property<>(ARROW_DIRECTION.data)));
propagate(world, pos, IBlock.getStatePropertySafe(state, FACING).rotateYClockwise(), new Property<>(ARROW_DIRECTION.data), 1);
propagate(world, pos, IBlock.getStatePropertySafe(state, FACING).rotateYCounterclockwise(), new Property<>(ARROW_DIRECTION.data), 1);
}
}, null, org.mtr.mod.Items.BRUSH.get(), ItemList.WRENCH.get());
} else {
return super.onUse2(state, world, pos, player, hand, hit);
}
}

@Override
protected boolean isAPG() {
return true;
}

@Nonnull
@Override
public Item asItem2() {
return ItemList.APG_GLASS_TIANJIN_BMT.get();
}

@Override
public BlockEntityExtension createBlockEntity(BlockPos blockPos, BlockState blockState) {
return new BlockEntity(blockPos, blockState);
}

@Override
public void addBlockProperties(List<HolderBase<?>> properties) {
properties.add(STYLE);
super.addBlockProperties(properties);
}

public static class BlockEntity extends BlockPSDTop.BlockEntityBase
{
public BlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.APG_GLASS_TIANJIN_BMT.get(), pos, state);
}
}

public enum EnumDoorType implements StringIdentifiable
{
ROUTE(0, "route"),
STATION_NAME(1, "station_name"),
NEXT_STATION(2, "next_station");

final int id;
final String name;

EnumDoorType(int id, String name) {
this.id = id;
this.name = name;
}

public int asId() {
return this.id;
}

public static EnumDoorType byId(int id) {
switch (id) {
case 0:
return ROUTE;
case 1:
return STATION_NAME;
case 2:
return NEXT_STATION;
default:
throw new IllegalStateException();
}
}

@Nonnull
@Override
public String asString2() {
return this.name;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ziyue.tjmetro.mod.block.base;

public interface BlockFlagAPGTianjinBMT
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.mtr.mapping.holder.*;
import org.mtr.mapping.mapper.ResourceManagerHelper;
import org.mtr.mod.Init;
import org.mtr.mod.client.MinecraftClientData;
import org.mtr.mod.config.Config;
import org.mtr.mod.config.LanguageDisplay;
import org.mtr.mod.data.IGui;
Expand All @@ -26,7 +25,6 @@
import java.text.AttributedString;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
import java.util.function.Supplier;

Expand Down Expand Up @@ -72,12 +70,12 @@ public DynamicResource getDirectionArrow(long platformId, boolean hasLeft, boole
return getResource(String.format("tjmetro_direction_arrow_%s_%s_%s_%s_%s_%s_%s_%s_%s_%s", platformId, hasLeft, hasRight, horizontalAlignment, showToString, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), () -> RouteMapGenerator.generateDirectionArrow(platformId, hasLeft, hasRight, horizontalAlignment, showToString, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), transparentColor == 0 && backgroundColor == ARGB_WHITE ? DefaultRenderingColor.WHITE : DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getPSDStationName(long platformId, IGui.HorizontalAlignment horizontalAlignment, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
return getResource(String.format("tjmetro_psd_station_name_%s_%s_%s_%s_%s_%s_%s", platformId, horizontalAlignment, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), () -> RouteMapGenerator.generatePSDStationName(platformId, horizontalAlignment, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), transparentColor == 0 && backgroundColor == ARGB_WHITE ? DefaultRenderingColor.WHITE : DefaultRenderingColor.TRANSPARENT);
public DynamicResource getStationName(long platformId, boolean isAPG, IGui.HorizontalAlignment horizontalAlignment, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
return getResource(String.format("tjmetro_station_name_%s_%s_%s_%s_%s_%s_%s_%s", platformId, isAPG, horizontalAlignment, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), () -> RouteMapGenerator.generateStationName(platformId, isAPG, horizontalAlignment, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), transparentColor == 0 && backgroundColor == ARGB_WHITE ? DefaultRenderingColor.WHITE : DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getPSDNextStation(long platformId, int arrowDirection, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
return getResource(String.format("tjmetro_psd_next_station_%s_%s_%s_%s_%s_%s_%s", platformId, arrowDirection, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), () -> RouteMapGenerator.generatePSDNextStation(platformId, arrowDirection, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), transparentColor == 0 && backgroundColor == ARGB_WHITE ? DefaultRenderingColor.WHITE : DefaultRenderingColor.TRANSPARENT);
public DynamicResource getNextStation(long platformId, int arrowDirection, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
return getResource(String.format("tjmetro_next_station_%s_%s_%s_%s_%s_%s_%s", platformId, arrowDirection, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), () -> RouteMapGenerator.generateNextStation(platformId, arrowDirection, paddingScale, aspectRatio, backgroundColor, textColor, transparentColor), transparentColor == 0 && backgroundColor == ARGB_WHITE ? DefaultRenderingColor.WHITE : DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getRouteMap(long platformId, boolean vertical, boolean flip, float aspectRatio, boolean transparentWhite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.mtr.mapping.holder.NativeImageFormat;
import org.mtr.mapping.mapper.ResourceManagerHelper;
import org.mtr.mod.Init;
import org.mtr.mod.InitClient;
import org.mtr.mod.block.BlockRailwaySign;
import org.mtr.mod.client.MinecraftClientData;
import org.mtr.mod.config.Config;
Expand Down Expand Up @@ -152,7 +151,7 @@ public static NativeImage generateDirectionArrow(long platformId, boolean hasLef
}
}

public static NativeImage generatePSDStationName(long platformId, HorizontalAlignment horizontalAlignment, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
public static NativeImage generateStationName(long platformId, boolean isAPG, HorizontalAlignment horizontalAlignment, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
if (aspectRatio <= 0) return null;

try {
Expand All @@ -164,15 +163,14 @@ public static NativeImage generatePSDStationName(long platformId, HorizontalAlig

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


final NativeImage nativeImage = new NativeImage(NativeImageFormat.RGBA, width, height, false);
nativeImage.fillRect(0, 0, width, height, invertColor(backgroundColor));

final int tilePadding = tileSize / 4;
final int leftSize = ((leftToRight ? 1 : 0)) * (tileSize + tilePadding);
final int rightSize = ((leftToRight ? 0 : 1)) * (tileSize + tilePadding);

final DynamicTextureCache.Text destination = DynamicTextureCache.instance.getText(getStationName(platformId), width - leftSize - rightSize - padding, (int) (tileSize * LINE_HEIGHT_MULTIPLIER), tileSize * 3, tileSize * 3 / 2, tilePadding, HorizontalAlignment.CENTER);
final DynamicTextureCache.Text destination = DynamicTextureCache.instance.getText(getStationName(platformId), isAPG ? width - padding : width - leftSize - rightSize - padding, (int) (tileSize * LINE_HEIGHT_MULTIPLIER), tileSize * 3, tileSize * 3 / 2, tilePadding, HorizontalAlignment.CENTER);
drawString(nativeImage, destination, width / 2, height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, backgroundColor, textColor, false);

if (transparentColor != 0) {
Expand All @@ -187,7 +185,7 @@ public static NativeImage generatePSDStationName(long platformId, HorizontalAlig
return null;
}

public static NativeImage generatePSDNextStation(long platformId, int arrowDirection, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
public static NativeImage generateNextStation(long platformId, int arrowDirection, float paddingScale, float aspectRatio, int backgroundColor, int textColor, int transparentColor) {
if (aspectRatio <= 0) return null;

try {
Expand Down
Loading

0 comments on commit d3fe0a2

Please sign in to comment.