Skip to content

Commit

Permalink
Metal Pole (Line 9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Aug 6, 2024
1 parent 3d00e90 commit 1ddf09f
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ 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<BlockMetalPoleBMT.BlockEntity> METAL_POLE_BMT = Registry.registerBlockEntityType("metal_pole_bmt", BlockMetalPoleBMT.BlockEntity::new, BlockList.METAL_POLE_BMT::get);

static void registerBlockEntities() {
// Calling this class to initialize constants
Expand Down
2 changes: 2 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.mtr.mapping.holder.Block;
import org.mtr.mapping.holder.Blocks;
import org.mtr.mapping.mapper.BlockHelper;
import org.mtr.mapping.mapper.BlockItemExtension;
import org.mtr.mapping.mapper.SlabBlockExtension;
import org.mtr.mapping.registry.BlockRegistryObject;
import org.mtr.mod.block.BlockCeiling;
Expand Down Expand Up @@ -113,6 +114,7 @@ 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 METAL_POLE_BMT = Registry.registerBlockWithBlockItem("metal_pole_bmt", () -> new Block(new BlockMetalPoleBMT()), BlockItemExtension::new, DECORATION);

static void registerBlocks() {
// Calling this class to initialize constants
Expand Down
16 changes: 10 additions & 6 deletions fabric/src/main/java/ziyue/tjmetro/mod/RegistryClient.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ziyue.tjmetro.mod;

import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import org.mtr.mapping.holder.Identifier;
import org.mtr.mapping.holder.Item;
import org.mtr.mapping.holder.ItemConvertible;
import org.mtr.mapping.holder.RenderLayer;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mapping.mapper.BlockEntityRenderer;
import org.mtr.mapping.mapper.EntityExtension;
import org.mtr.mapping.mapper.EntityRenderer;
import org.mtr.mapping.registry.BlockEntityTypeRegistryObject;
import org.mtr.mapping.registry.BlockRegistryObject;
import org.mtr.mapping.registry.EntityTypeRegistryObject;
import org.mtr.mapping.registry.PacketHandler;
import org.mtr.mapping.registry.*;
import org.mtr.mod.InitClient;
import ziyue.tjmetro.mod.block.base.BlockCustomColorBase;

Expand All @@ -27,17 +27,21 @@ public static void registerBlockStationColor(BlockRegistryObject... blocks) {
REGISTRY_CLIENT.registerBlockColors((state, world, pos, tintIndex) -> InitClient.getStationColor(pos), blocks);
}

public static void registerItemCustomColor(int color, Item item) {
ColorProviderRegistry.ITEM.register((stack, index) -> color, item.data);
}

public static void registerBlockCustomColor(BlockRegistryObject... blocks) {
for (BlockRegistryObject block : blocks) {
REGISTRY_CLIENT.registerBlockColors((state, world, pos, tintIndex) -> {
try {
if (world.getBlockEntity(pos).data instanceof BlockCustomColorBase.BlockEntityBase) {
final BlockCustomColorBase.BlockEntityBase entity = (BlockCustomColorBase.BlockEntityBase) world.getBlockEntity(pos).data;
if (entity.color != -1) return entity.color;
return entity.color == -1 ? entity.getDefaultColor(pos) : entity.color;
}
} catch (Exception ignored) {
}
return InitClient.getStationColor(pos);
return 8355711;
}, block);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public static void init() {
RegistryClient.registerBlockStationColor(BlockList.STATION_COLOR_CEILING, BlockList.STATION_COLOR_CEILING_LIGHT, BlockList.STATION_COLOR_CEILING_NO_LIGHT, BlockList.STATION_COLOR_CEILING_NOT_LIT);
RegistryClient.registerBlockStationColor(BlockList.STATION_NAME_SIGN_1);
RegistryClient.registerBlockCustomColor(BlockList.CUSTOM_COLOR_CONCRETE, BlockList.CUSTOM_COLOR_CONCRETE_SLAB, BlockList.CUSTOM_COLOR_CONCRETE_STAIRS);
RegistryClient.registerBlockCustomColor(BlockList.METAL_POLE_BMT);
RegistryClient.registerItemCustomColor(0xfff100, BlockList.METAL_POLE_BMT.get().asItem());

RegistryClient.setupPackets("packet");

Expand Down
121 changes: 121 additions & 0 deletions fabric/src/main/java/ziyue/tjmetro/mod/block/BlockMetalPoleBMT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package ziyue.tjmetro.mod.block;

import org.jetbrains.annotations.NotNull;
import org.mtr.mapping.holder.*;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mapping.mapper.BlockExtension;
import org.mtr.mapping.mapper.BlockHelper;
import org.mtr.mapping.mapper.DirectionHelper;
import org.mtr.mapping.tool.HolderBase;
import org.mtr.mod.block.IBlock;
import ziyue.tjmetro.mod.BlockEntityTypes;
import ziyue.tjmetro.mod.BlockList;
import ziyue.tjmetro.mod.block.base.BlockCustomColorBase;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public class BlockMetalPoleBMT extends BlockCustomColorBase implements DirectionHelper
{
public static final BooleanProperty NORTH = BooleanProperty.of("north");
public static final BooleanProperty EAST = BooleanProperty.of("east");
public static final BooleanProperty SOUTH = BooleanProperty.of("south");
public static final BooleanProperty WEST = BooleanProperty.of("west");

public BlockMetalPoleBMT() {
this(BlockHelper.createBlockSettings(false).nonOpaque());
}

public BlockMetalPoleBMT(BlockSettings blockSettings) {
super(blockSettings);
}

@Nullable
@Override
public BlockState getPlacementState2(ItemPlacementContext ctx) {
final Direction direction = ctx.getSide();
return getDefaultState2().with(new Property<>(NORTH.data), false).with(new Property<>(EAST.data), false).with(new Property<>(SOUTH.data), false).with(new Property<>(WEST.data), false)
.with(new Property<>(FACING_NORMAL.data), direction == Direction.UP ? Direction.DOWN.data : direction.data);
}

@Nonnull
@Override
public BlockState getStateForNeighborUpdate2(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (IBlock.getStatePropertySafe(state, FACING_NORMAL) != Direction.DOWN) return state;

boolean shouldConnect = false;
if (IBlockExtension.isBlock(neighborState, BlockList.METAL_POLE_BMT.get())) {
if (IBlock.getStatePropertySafe(neighborState, FACING_NORMAL) != Direction.DOWN) {
shouldConnect = true;
}
}
switch (direction) {
case NORTH:
return state.with(new Property<>(NORTH.data), shouldConnect);
case EAST:
return state.with(new Property<>(EAST.data), shouldConnect);
case SOUTH:
return state.with(new Property<>(SOUTH.data), shouldConnect);
case WEST:
return state.with(new Property<>(WEST.data), shouldConnect);
}
return state;
}

@Nonnull
@Override
public VoxelShape getOutlineShape2(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
final Direction direction = IBlock.getStatePropertySafe(state, FACING_NORMAL);
if (direction == Direction.DOWN) {
final VoxelShape pole = Block.createCuboidShape(6.0, 0.0, 6.0, 10.0, 16.0, 10.0);
VoxelShape connect = Block.createCuboidShape(0, 0, 0, 0, 0, 0);
if (IBlock.getStatePropertySafe(state, NORTH)) {
connect = VoxelShapes.union(connect, IBlock.getVoxelShapeByDirection(6, 0, 0, 10, 4, 6, Direction.NORTH));
}
if (IBlock.getStatePropertySafe(state, EAST)) {
connect = VoxelShapes.union(connect, IBlock.getVoxelShapeByDirection(6, 0, 0, 10, 4, 6, Direction.EAST));
}
if (IBlock.getStatePropertySafe(state, SOUTH)) {
connect = VoxelShapes.union(connect, IBlock.getVoxelShapeByDirection(6, 0, 0, 10, 4, 6, Direction.SOUTH));
}
if (IBlock.getStatePropertySafe(state, WEST)) {
connect = VoxelShapes.union(connect, IBlock.getVoxelShapeByDirection(6, 0, 0, 10, 4, 6, Direction.WEST));
}
return VoxelShapes.union(pole, connect);
}
return IBlock.getVoxelShapeByDirection(6, 0, 0, 10, 4, 16, direction);
}

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

@Nonnull
@Override
public String getTranslationKey2() {
return "block.tjmetro.metal_pole_bmt";
}

@Override
public void addBlockProperties(List<HolderBase<?>> properties) {
properties.add(FACING_NORMAL);
properties.add(NORTH);
properties.add(EAST);
properties.add(SOUTH);
properties.add(WEST);
}

public static class BlockEntity extends BlockEntityBase
{
public BlockEntity(BlockPos blockPos, BlockState blockState) {
super(BlockEntityTypes.METAL_POLE_BMT.get(), blockPos, blockState);
}

@Override
public int getDefaultColor(BlockPos pos) {
return 0xfff100;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.mtr.mapping.mapper.BlockExtension;
import org.mtr.mapping.mapper.BlockWithEntity;
import org.mtr.mapping.mapper.TextHelper;
import org.mtr.mod.InitClient;
import ziyue.tjmetro.mod.Registry;
import ziyue.tjmetro.mod.block.IBlockExtension;
import ziyue.tjmetro.mod.packet.PacketOpenBlockEntityScreen;
Expand Down Expand Up @@ -45,6 +46,10 @@ public BlockEntityBase(BlockEntityType<?> type, BlockPos blockPos, BlockState bl
super(type, blockPos, blockState);
}

public int getDefaultColor(BlockPos pos) {
return InitClient.getStationColor(pos);
}

@Override
public void readCompoundTag(CompoundTag compoundTag) {
color = compoundTag.getInt(COLOR_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void openBlockEntityScreen(BlockPos blockPos) {
openScreen(new RoadblockContentScreen(blockPos, entity.content), screen -> screen instanceof RoadblockContentScreen);
} else if (blockEntity.data instanceof BlockCustomColorBase.BlockEntityBase) {
final BlockCustomColorBase.BlockEntityBase entity = (BlockCustomColorBase.BlockEntityBase) blockEntity.data;
openScreen(new ColorPickerScreen(blockPos, entity.color), screen -> screen instanceof ColorPickerScreen);
openScreen(new ColorPickerScreen(blockPos, entity), screen -> screen instanceof ColorPickerScreen);
} else if (blockEntity.data instanceof BlockRailwaySignWallDouble.BlockEntity) {
openScreen(new RailwaySignDoubleScreen(blockPos), screen -> screen instanceof RailwaySignDoubleScreen);
} else if (blockEntity.data instanceof BlockRailwaySignBase.BlockEntityBase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mtr.mod.client.IDrawing;
import org.mtr.mod.data.IGui;
import ziyue.tjmetro.mod.RegistryClient;
import ziyue.tjmetro.mod.block.base.BlockCustomColorBase;
import ziyue.tjmetro.mod.packet.PacketUpdateCustomColor;

import java.awt.*;
Expand All @@ -24,6 +25,7 @@ public class ColorPickerScreen extends ScreenExtension implements IGui

protected final BlockPos pos;
protected final int oldColor;
protected final BlockCustomColorBase.BlockEntityBase entity;
protected final TextFieldWidgetExtension textFieldColor;
protected final TextFieldWidgetExtension textFieldRed;
protected final TextFieldWidgetExtension textFieldGreen;
Expand All @@ -33,17 +35,18 @@ public class ColorPickerScreen extends ScreenExtension implements IGui

protected static final int RIGHT_WIDTH = 60;

public ColorPickerScreen(BlockPos pos, int oldColor) {
public ColorPickerScreen(BlockPos pos, BlockCustomColorBase.BlockEntityBase entity) {
super();
this.pos = pos;
this.oldColor = oldColor;
this.oldColor = entity.color;
this.entity = entity;
textFieldColor = new TextFieldWidgetExtension(0, 0, 0, SQUARE_SIZE, 6, TextCase.UPPER, "[^\\dA-F]", TextHelper.literal(Integer.toHexString(oldColor).toUpperCase(Locale.ENGLISH)).getString());
textFieldRed = new TextFieldWidgetExtension(0, 0, 0, SQUARE_SIZE, 3, TextCase.DEFAULT, "\\D", TextHelper.literal(String.valueOf((oldColor >> 16) & 0xFF)).getString());
textFieldGreen = new TextFieldWidgetExtension(0, 0, 0, SQUARE_SIZE, 3, TextCase.DEFAULT, "\\D", TextHelper.literal(String.valueOf((oldColor >> 8) & 0xFF)).getString());
textFieldBlue = new TextFieldWidgetExtension(0, 0, 0, SQUARE_SIZE, 3, TextCase.DEFAULT, "\\D", TextHelper.literal(String.valueOf(oldColor & 0xFF)).getString());
checkboxDefaultColor = new CheckboxWidgetExtension(0, 0, 0, 20, TextHelper.translatable("gui.tjmetro.default_color"), true, checked -> {
if (checked) {
setHsb(InitClient.getStationColor(pos), true);
setHsb(entity.getDefaultColor(pos), true);
}
});
checkboxDefaultColor.setChecked(oldColor == -1);
Expand All @@ -67,7 +70,7 @@ protected void init2() {
IDrawing.setPositionAndWidth(checkboxDefaultColor, SQUARE_SIZE * 4 + getMainWidth() + 3, SQUARE_SIZE, RIGHT_WIDTH - TEXT_FIELD_PADDING);
IDrawing.setPositionAndWidth(buttonReset, startX, getMainHeight(), RIGHT_WIDTH);

setHsb(oldColor == -1 ? InitClient.getStationColor(pos) : oldColor, true);
setHsb(oldColor == -1 ? entity.getDefaultColor(pos) : oldColor, true);

textFieldColor.setChangedListener2(text -> textCallback(text, -1));
textFieldRed.setChangedListener2(text -> textCallback(text, 16));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"multipart": [
{
"when": {
"facing": "north"
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_horizontal"
}
},
{
"when": {
"facing": "east"
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_horizontal",
"y": 90
}
},
{
"when": {
"facing": "south"
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_horizontal",
"y": 180
}
},
{
"when": {
"facing": "west"
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_horizontal",
"y": 270
}
},
{
"when": {
"facing": "down"
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_vertical"
}
},
{
"when": {
"north": true
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_connect"
}
},
{
"when": {
"east": true
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_connect",
"y": 90
}
},
{
"when": {
"south": true
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_connect",
"y": 180
}
},
{
"when": {
"west": true
},
"apply": {
"model": "tjmetro:block/metal_pole_bmt_connect",
"y": 270
}
}
]
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/assets/tjmetro/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"block.tjmetro.station_name_entrance_tianjin_bmt_pinyin": "Station Name (Entrance, Tianjin, Line 9, Pinyin)",
"block.tjmetro.station_name_plate": "Station Name Plate (Line 9)",
"block.tjmetro.apg_tianjin": "Automatic Platform Gates (Tianjin)",
"block.tjmetro.metal_pole_bmt": "Metal Pole (Line 9)",

"gui.tjmetro.service_corridor_sign_cjk": "暖行服务连廊",
"gui.tjmetro.contact_station_for_help_cjk": "如需帮助请联系车站",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"parent": "block/block",
"textures": {
"particle": "mtr:block/metal"
},
"elements": [
{
"from": [ 6, 0, 0 ],
"to": [ 10, 4, 6 ],
"faces": {
"down": { "texture": "#particle", "tintindex": 0, "cullface": "down" },
"up": { "texture": "#particle", "tintindex": 0, "cullface": "up" },
"east": { "texture": "#particle", "tintindex": 0 },
"west": { "texture": "#particle", "tintindex": 0 },
"north": { "texture": "#particle", "tintindex": 0 },
"south": { "texture": "#particle", "tintindex": 0 }
}
}
]
}
Loading

0 comments on commit 1ddf09f

Please sign in to comment.