Skip to content

Commit

Permalink
⬆ Updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed May 12, 2024
1 parent df062b3 commit 72b2161
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 272 deletions.
4 changes: 3 additions & 1 deletion common/src/main/java/ziyue/tjmetro/IDrawingExtends.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.function.Function;
import java.util.function.UnaryOperator;

import static mtr.data.IGui.MAX_LIGHT_GLOWING;

/**
* Some methods similar to methods in <b>IDrawing</b>.
*
Expand Down Expand Up @@ -135,7 +137,7 @@ static void drawStringWithFont(PoseStack matrices, Font textRenderer, MultiBuffe

final float xOffset = horizontalAlignment.getOffset(xAlignment.getOffset(x * scaleX, totalWidth), textRenderer.width(orderedTexts.get(i)) * extraScale - totalWidth);

final float shade = light == IGui.MAX_LIGHT_GLOWING ? 1 : Math.min(LightTexture.block(light) / 16F * 0.1F + 0.7F, 1);
final float shade = light == MAX_LIGHT_GLOWING ? 1 : Math.min(LightTexture.block(light) / 16F * 0.1F + 0.7F, 1);
final int a = (textColor >> 24) & 0xFF;
final int r = (int) (((textColor >> 16) & 0xFF) * shade);
final int g = (int) (((textColor >> 8) & 0xFF) * shade);
Expand Down
6 changes: 1 addition & 5 deletions common/src/main/java/ziyue/tjmetro/TianjinMetroClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import mtr.RegistryClient;
import mtr.render.RenderPSDAPGDoor;
import mtr.render.RenderPSDTop;
import mtr.render.RenderStationNameTiled;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import ziyue.tjmetro.client.ClientCache;
import ziyue.tjmetro.client.RouteMapGenerator;
import ziyue.tjmetro.packet.IPacket;
import ziyue.tjmetro.packet.PacketGuiClient;
import ziyue.tjmetro.render.*;
Expand Down Expand Up @@ -90,6 +86,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));
RegistryClient.registerNetworkReceiver(IPacket.PACKET_OPEN_RAILWAY_SIGN_DOUBLE_SCREEN, packet -> PacketGuiClient.openRailwaySignDoubleScreenS2C(Minecraft.getInstance(), packet));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ public BlockState updateShape(BlockState state, Direction direction, BlockState

@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_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);
IRailwaySign.setPlacedBy(world, pos, state, BlockList.RAILWAY_SIGN_TIANJIN_MIDDLE.get(), getMiddleLength());
}

@Override
Expand Down Expand Up @@ -91,11 +84,10 @@ public String getDescriptionId() {

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

public static class TileEntityRailwaySignTianjin extends TileEntityRailwaySign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
final BlockPos checkPos = findEndWithDirection(world, pos, facing, false);
return IBlockExtends.checkHoldingBrushOrWrench(world, player, () -> {
if (checkPos != null) {
PacketGuiServer.openRailwaySignWallDoubleScreenS2C((ServerPlayer) player, checkPos);
PacketGuiServer.openRailwaySignDoubleScreenS2C((ServerPlayer) player, checkPos);
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/ziyue/tjmetro/client/ClientCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public DynamicResource getRouteSquare(int color, String routeName, IGui.Horizont
return getResource(String.format("tjmetro_route_square_%s_%s_%s", color, routeName, horizontalAlignment), () -> RouteMapGenerator.generateRouteSquare(color, routeName, horizontalAlignment), DefaultRenderingColor.TRANSPARENT);
}

public DynamicResource getExitSignLetter(String exitLetter, String exitNumber, int backgroundColor) {
return getResource(String.format("tjmetro_exit_sign_letter_%s_%s", exitLetter, exitNumber), () -> RouteMapGenerator.generateExitSignLetter(exitLetter, exitNumber, backgroundColor), 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);
}
Expand Down
35 changes: 30 additions & 5 deletions common/src/main/java/ziyue/tjmetro/client/RouteMapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class RouteMapGenerator implements IGui
protected static int fontSizeBig;
protected static int fontSizeSmall;

protected static final int MIN_VERTICAL_SIZE = 5;
protected static final String TEMP_CIRCULAR_MARKER = "temp_circular_marker";
protected static final ResourceLocation TRAIN_LOGO_RESOURCE = new ResourceLocation(Reference.MOD_ID, "textures/sign/train.png");
protected static final ResourceLocation ARROW_RESOURCE = new ResourceLocation(MTR.MOD_ID, "textures/block/sign/arrow.png");
protected static final ResourceLocation CIRCLE_RESOURCE = new ResourceLocation(MTR.MOD_ID, "textures/block/sign/circle.png");
public static final int MIN_VERTICAL_SIZE = 5;
public static final String TEMP_CIRCULAR_MARKER = "temp_circular_marker";
public static final ResourceLocation TRAIN_LOGO_RESOURCE = new ResourceLocation(Reference.MOD_ID, "textures/sign/train.png");
public static final ResourceLocation EXIT_RESOURCE = new ResourceLocation(MTR.MOD_ID, "textures/block/sign/exit_letter_blank.png");
public static final ResourceLocation ARROW_RESOURCE = new ResourceLocation(MTR.MOD_ID, "textures/block/sign/arrow.png");
public static final ResourceLocation CIRCLE_RESOURCE = new ResourceLocation(MTR.MOD_ID, "textures/block/sign/circle.png");

public static void setConstants() {
scale = (int) Math.pow(2, Config.dynamicTextureResolution() + 5);
Expand Down Expand Up @@ -434,6 +435,30 @@ public static NativeImage generateRouteSquare(int color, String routeName, Horiz
return null;
}

public static NativeImage generateExitSignLetter(String exitLetter, String exitNumber, int backgroundColor) {
try {
final int size = scale / 2;
final boolean noNumber = exitNumber.isEmpty();
final int textSize = size * 7 / 8;
final ClientCache.Text letter = ClientCache.DATA_CACHE.getText(exitLetter, noNumber ? textSize : textSize * 2 / 3, textSize, textSize, size, size, HorizontalAlignment.CENTER);
final ClientCache.Text number = noNumber ? null : ClientCache.DATA_CACHE.getText(exitNumber, textSize / 3, textSize, textSize / 2, textSize / 2, size, HorizontalAlignment.CENTER);

final NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, size, size, false);
nativeImage.fillRect(0, 0, size, size, backgroundColor);
drawResource(nativeImage, EXIT_RESOURCE, 0, 0, size, size, false, 0, 1, 0, true);
drawString(nativeImage, letter, size / 2 - (noNumber ? 0 : textSize / 6 - size / 32), size / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, ARGB_WHITE, false);
if (!noNumber) {
drawString(nativeImage, number, size / 2 + textSize / 3 - size / 32, size / 2 + textSize / 8, 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;
Expand Down
3 changes: 1 addition & 2 deletions common/src/main/java/ziyue/tjmetro/packet/IPacket.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ziyue.tjmetro.packet;

import mtr.MTR;
import net.minecraft.resources.ResourceLocation;
import ziyue.tjmetro.Reference;

Expand All @@ -15,7 +14,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_OPEN_RAILWAY_SIGN_DOUBLE_SCREEN = new ResourceLocation(Reference.MOD_ID, "packet_open_railway_sign_double_screen");
ResourceLocation PACKET_SIGN_TYPES = new ResourceLocation(Reference.MOD_ID, "packet_sign_types");
ResourceLocation PACKET_SIGN_TYPES_DOUBLE = new ResourceLocation(Reference.MOD_ID, "packet_sign_types_double");
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void openRailwaySignScreenS2C(Minecraft minecraftClient, FriendlyB
});
}

public static void openRailwaySignWallDoubleScreenS2C(Minecraft minecraftClient, FriendlyByteBuf packet) {
public static void openRailwaySignDoubleScreenS2C(Minecraft minecraftClient, FriendlyByteBuf packet) {
final BlockPos pos = packet.readBlockPos();
minecraftClient.execute(() -> {
if (!(minecraftClient.screen instanceof RailwaySignScreen)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public static void receiveSignIdsC2S(MinecraftServer minecraftServer, ServerPlay
});
}

public static void openRailwaySignWallDoubleScreenS2C(ServerPlayer player, BlockPos signPos) {
public static void openRailwaySignDoubleScreenS2C(ServerPlayer player, BlockPos signPos) {
final FriendlyByteBuf packet = new FriendlyByteBuf(Unpooled.buffer());
packet.writeBlockPos(signPos);
Registry.sendToPlayer(player, PACKET_OPEN_RAILWAY_SIGN_WALL_DOUBLE_SCREEN, packet);
Registry.sendToPlayer(player, PACKET_OPEN_RAILWAY_SIGN_DOUBLE_SCREEN, packet);
}

public static void sendSignIdsDoubleC2S(BlockPos signPos, List<Set<Long>> selectedIds, String[][] signIds) {
Expand Down
Loading

0 comments on commit 72b2161

Please sign in to comment.