diff --git a/build.gradle b/build.gradle index 2d6aa9ac..fc36dcbc 100644 --- a/build.gradle +++ b/build.gradle @@ -19,12 +19,13 @@ int minecraft_main_version = minecraft_version.split("\\.")[1] as int String minecraft_version_int = minecraft_version.split("\\.")[0] + minecraft_version.split("\\.")[1].padLeft(2, '0') + (minecraft_version.split("\\.").length > 2 ? minecraft_version.split("\\.")[2].padLeft(2, '0') : "00") +boolean parchment_not_avail = false +String parchment_version = parchment_not_avail ? "N/A" : new XmlSlurper().parse("https://ldtteam.jfrog.io/artifactory/parchmentmc-internal/org/parchmentmc/data/parchment-${minecraft_version}/maven-metadata.xml").versioning.release def is_1_19_3 = minecraft_version == "1.19.3" || minecraft_version == "1.19.4" -String parchment_version = new XmlSlurper().parse("https://ldtteam.jfrog.io/artifactory/parchmentmc-internal/org/parchmentmc/data/parchment-${is_1_19_3 ? "1.19.3" : minecraft_version}/maven-metadata.xml").versioning.release - +def is_1_20 = minecraft_version == "1.20" || minecraft_version == "1.20.1" rootProject.ext.fabric_loader_version = new JsonSlurper().parse(("https://meta.fabricmc.net/v2/versions/loader/" + minecraft_version).toURL())[0]["loader"]["version"] -rootProject.ext.forge_version = minecraft_version + "-" + new JsonSlurper().parse(("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json").toURL())["promos"][minecraft_version + "-latest"] +rootProject.ext.forge_version = minecraft_version + "-" + new JsonSlurper().parse(("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json").toURL())["promos"][minecraft_version + "-recommended"] rootProject.ext.fabric_api_version = getModrinthVersion("fabric", minecraft_version, "fabric-api") rootProject.ext.mod_menu_version = getModrinthVersion("fabric", minecraft_version, "modmenu") rootProject.ext.architectury_version = getModrinthVersion("forge", minecraft_version, "architectury-api").split("\\+")[0] @@ -63,7 +64,7 @@ subprojects { dependencies { annotationProcessor 'systems.manifold:manifold-preprocessor:2023.1.10' minecraft "com.mojang:minecraft:${minecraft_version}" - mappings is_1_19_3 ? loom.officialMojangMappings() : loom.layered() { + mappings parchment_not_avail ? loom.officialMojangMappings() : loom.layered() { officialMojangMappings() parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") } @@ -80,27 +81,32 @@ subprojects { task setupLibrary() { doLast { + + String baseURL = is_1_20 ? "https://storage.zbx1425.cn/mtr-artifacts/libs/" : "https://www.minecrafttransitrailway.com/libs/" + download { - src "https://www.minecrafttransitrailway.com/libs/${rootProject.mtr_version}/MTR-common-${minecraft_version}-${rootProject.mtr_version}-dev.jar" + src "${baseURL}${rootProject.mtr_version}/MTR-common-${minecraft_version}-${rootProject.mtr_version}-dev.jar" dest "checkouts/mtr-common.jar" overwrite true } download { - src "https://www.minecrafttransitrailway.com/libs/${rootProject.mtr_version}/MTR-fabric-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar" + src "${baseURL}${rootProject.mtr_version}/MTR-fabric-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar" dest "checkouts/mtr-fabric.jar" overwrite true } download { - src "https://www.minecrafttransitrailway.com/libs/${rootProject.mtr_version}/MTR-forge-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar" + src "${baseURL}${rootProject.mtr_version}/MTR-forge-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar" dest "checkouts/mtr-forge.jar" overwrite true } } + String minecraftMappingsBaseURL = is_1_20 ? "https://storage.zbx1425.cn/mtr-artifacts/Minecraft-Mappings/" : "https://github.com/jonafanho/Minecraft-Mappings/archive/refs/heads/" + download { - src "https://github.com/jonafanho/Minecraft-Mappings/archive/refs/heads/1.${minecraft_main_version}${is_1_19_3 ? ".3" : ""}.zip" + src "${minecraftMappingsBaseURL}${is_1_19_3 ? minecraft_version : "1." + minecraft_main_version}.zip" dest "common/src/main/java/cn/zbx1425/mtrsteamloco/mappings/files.zip" overwrite true } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/Main.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/Main.java index 118ae33e..55ca80e9 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/Main.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/Main.java @@ -2,8 +2,6 @@ import cn.zbx1425.mtrsteamloco.block.BlockDepartureBell; import cn.zbx1425.mtrsteamloco.block.BlockEyeCandy; -import cn.zbx1425.mtrsteamloco.block.BlockFeedbackBox; -import cn.zbx1425.mtrsteamloco.block.BlockStatisticTurnstile; import cn.zbx1425.mtrsteamloco.network.PacketUpdateBlockEntity; import cn.zbx1425.mtrsteamloco.network.PacketUpdateHoldingItem; import cn.zbx1425.mtrsteamloco.network.PacketUpdateRail; @@ -56,20 +54,6 @@ public class Main { BlockEyeCandy.BlockEntityEyeCandy::new, BLOCK_EYE_CANDY.get() )); - public static final RegistryObject BLOCK_STATISTIC_TURNSTILE = new RegistryObject<>(BlockStatisticTurnstile::new); - public static final RegistryObject> - BLOCK_ENTITY_TYPE_STATISTIC_TURNSTILE = new RegistryObject<>(() -> - RegistryUtilities.getBlockEntityType( - BlockStatisticTurnstile.BlockEntityStatisticTurnstile::new, - BLOCK_STATISTIC_TURNSTILE.get() - )); - public static final RegistryObject BLOCK_FEEDBACK_BOX = new RegistryObject<>(BlockFeedbackBox::new); - public static final RegistryObject> - BLOCK_ENTITY_TYPE_FEEDBACK_BOX = new RegistryObject<>(() -> - RegistryUtilities.getBlockEntityType( - BlockFeedbackBox.BlockEntityFeedbackBox::new, - BLOCK_FEEDBACK_BOX.get() - )); public static final SoundEvent SOUND_EVENT_BELL = RegistryUtilities.createSoundEvent(new ResourceLocation("mtrsteamloco:bell")); @@ -84,10 +68,6 @@ public static void init( + DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.systemDefault()).format(BuildConfig.BUILD_TIME)); if (enableRegistry) { registerBlockItem.accept("departure_bell", BLOCK_DEPARTURE_BELL, CreativeModeTabs.RAILWAY_FACILITIES); - // registerBlockItem.accept("statistic_turnstile", BLOCK_STATISTIC_TURNSTILE, ItemGroups.RAILWAY_FACILITIES); - // registerBlockEntityType.accept("statistic_turnstile", BLOCK_ENTITY_TYPE_STATISTIC_TURNSTILE); - // registerBlockItem.accept("feedback_box", BLOCK_FEEDBACK_BOX, ItemGroups.RAILWAY_FACILITIES); - // registerBlockEntityType.accept("feedback_box", BLOCK_ENTITY_TYPE_FEEDBACK_BOX); registerBlockItem.accept("eye_candy", BLOCK_EYE_CANDY, CreativeModeTabs.STATION_BUILDING_BLOCKS); registerBlockEntityType.accept("eye_candy", BLOCK_ENTITY_TYPE_EYE_CANDY); registerSoundEvent.accept("bell", SOUND_EVENT_BELL); diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockDepartureBell.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockDepartureBell.java index c33efc3a..5dcf05d9 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockDepartureBell.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockDepartureBell.java @@ -16,8 +16,10 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +#if MC_VERSION < "12000" import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; +#endif import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; @@ -25,7 +27,14 @@ public class BlockDepartureBell extends BlockDirectionalMapper { public BlockDepartureBell() { - super(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_GRAY).strength(2)); + super( +#if MC_VERSION < "12000" + BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_GRAY) +#else + BlockBehaviour.Properties.of() +#endif + .strength(2) + ); } @Override diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockEyeCandy.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockEyeCandy.java index 9bb7229a..41ad4933 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockEyeCandy.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockEyeCandy.java @@ -19,8 +19,10 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +#if MC_VERSION < "12000" import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; +#endif import net.minecraft.world.phys.BlockHitResult; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; @@ -29,7 +31,11 @@ public class BlockEyeCandy extends BlockDirectionalMapper implements EntityBlock public BlockEyeCandy() { super( +#if MC_VERSION < "12000" BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_GRAY) +#else + BlockBehaviour.Properties.of() +#endif .strength(2) .noCollission() ); diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockFeedbackBox.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockFeedbackBox.java deleted file mode 100644 index 01d78e2b..00000000 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockFeedbackBox.java +++ /dev/null @@ -1,95 +0,0 @@ -package cn.zbx1425.mtrsteamloco.block; - -import cn.zbx1425.mtrsteamloco.Main; -import mtr.block.IBlock; -import mtr.mappings.BlockDirectionalMapper; -import mtr.mappings.BlockEntityClientSerializableMapper; -import mtr.mappings.BlockEntityMapper; -import mtr.mappings.EntityBlockMapper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.inventory.BookEditScreen; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.IntTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -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.block.state.StateDefinition; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.apache.commons.lang3.StringUtils; - -public class BlockFeedbackBox extends BlockDirectionalMapper implements EntityBlockMapper { - - public BlockFeedbackBox() { - super(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_GRAY).strength(2)); - } - - @Override - public BlockState getStateForPlacement(BlockPlaceContext ctx) { - return defaultBlockState().setValue(FACING, ctx.getHorizontalDirection()); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(FACING); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext collisionContext) { - return IBlock.getVoxelShapeByDirection(2, 0, 0, 12, 13, 4, IBlock.getStatePropertySafe(state, FACING)); - } - - public final static String DUMMY_BOOK_IDENTIFY_TAG = "ZBX_FEEDBACK_DUMMY_BOOK"; - - @Override - public BlockEntityMapper createBlockEntity(BlockPos blockPos, BlockState blockState) { - return new BlockEntityFeedbackBox(blockPos, blockState); - } - - - public static class BlockEntityFeedbackBox extends BlockEntityClientSerializableMapper { - - public String counterName; - - public BlockEntityFeedbackBox(BlockPos pos, BlockState state) { - super(Main.BLOCK_ENTITY_TYPE_FEEDBACK_BOX.get(), pos, state); - } - - @Override - public void readCompoundTag(CompoundTag compoundTag) { - counterName = compoundTag.getString("counterName"); - if (StringUtils.isEmpty(counterName)) counterName = null; - } - - @Override - public void writeCompoundTag(CompoundTag compoundTag) { - compoundTag.putString("counterName", counterName == null ? "" : counterName); - } - } - - public static class ClientFunctions { - - public static void openDummyBookEditScreen(Player player, String counterName) { - ItemStack dummyBookItemStack = new ItemStack(Items.WRITABLE_BOOK); - dummyBookItemStack.addTagElement("counterName", StringTag.valueOf(counterName)); - dummyBookItemStack.addTagElement(DUMMY_BOOK_IDENTIFY_TAG, IntTag.valueOf(0)); - BookEditScreen bookEditScreen = new BookEditScreen(player, dummyBookItemStack, InteractionHand.MAIN_HAND); - Minecraft.getInstance().setScreen(bookEditScreen); - } - } -} diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockStatisticTurnstile.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockStatisticTurnstile.java deleted file mode 100644 index c8822e46..00000000 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/block/BlockStatisticTurnstile.java +++ /dev/null @@ -1,128 +0,0 @@ -package cn.zbx1425.mtrsteamloco.block; - -import cn.zbx1425.mtrsteamloco.Main; -import mtr.block.IBlock; -import mtr.mappings.*; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -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.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.Vec3; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.apache.commons.lang3.StringUtils; - -public class BlockStatisticTurnstile extends BlockDirectionalMapper implements EntityBlockMapper { - - public static final BooleanProperty OPEN = BooleanProperty.create("open"); - - public BlockStatisticTurnstile() { - super(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.COLOR_GRAY).strength(2).noOcclusion()); - } - - @Override - public void entityInside(BlockState state, Level level, BlockPos blockPos, Entity entity) { - if (!level.isClientSide && entity instanceof Player) { - final Direction facing = IBlock.getStatePropertySafe(state, FACING); - final Vec3 playerPosRotated = entity.position().subtract(blockPos.getX() + 0.5, 0, blockPos.getZ() + 0.5).yRot((float) Math.toRadians(facing.toYRot())); - final boolean open = IBlock.getStatePropertySafe(state, OPEN); - - if (open && playerPosRotated.z > 0) { - level.setBlockAndUpdate(blockPos, state.setValue(OPEN, false)); - } else if (!open && playerPosRotated.z < 0) { - BlockPos mainBlockPos = searchMainBlock(level, blockPos); - BlockEntityStatisticTurnstile blockEntity = (BlockEntityStatisticTurnstile) level.getBlockEntity(mainBlockPos); - assert blockEntity != null; - - level.playSound(null, blockPos, mtr.SoundEvents.TICKET_BARRIER, SoundSource.BLOCKS, 1.0F, 1.0F); - level.setBlockAndUpdate(blockPos, state.setValue(OPEN, true)); - if (!level.getBlockTicks().hasScheduledTick(blockPos, this)) { - Utilities.scheduleBlockTick(level, blockPos, this, 40); - } - } - } - } - - @Override - public void tick(BlockState state, ServerLevel world, BlockPos pos) { - world.setBlockAndUpdate(pos, state.setValue(OPEN, false)); - } - - @Override - public BlockState getStateForPlacement(BlockPlaceContext ctx) { - return defaultBlockState().setValue(FACING, ctx.getHorizontalDirection()).setValue(OPEN, false); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos pos, CollisionContext collisionContext) { - final Direction facing = IBlock.getStatePropertySafe(state, FACING); - return IBlock.getVoxelShapeByDirection(12, 0, 0, 16, 15, 16, facing); - } - - @Override - public VoxelShape getCollisionShape(BlockState state, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) { - final Direction facing = IBlock.getStatePropertySafe(state, FACING); - final boolean open = IBlock.getStatePropertySafe(state, OPEN); - final VoxelShape base = IBlock.getVoxelShapeByDirection(15, 0, 0, 16, 24, 16, facing); - return open ? base : Shapes.or(IBlock.getVoxelShapeByDirection(0, 0, 7, 16, 24, 9, facing), base); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(FACING, OPEN); - } - - public BlockPos searchMainBlock(Level level, BlockPos start) { - BlockPos cursor = new BlockPos(start); - while (level.getBlockState(cursor.west()).is(this)) cursor = cursor.west(); - while (level.getBlockState(cursor.north()).is(this)) cursor = cursor.north(); - return cursor; - } - - @Override - public BlockEntityMapper createBlockEntity(BlockPos blockPos, BlockState blockState) { - return new BlockEntityStatisticTurnstile(blockPos, blockState); - } - - public static class BlockEntityStatisticTurnstile extends BlockEntityMapper { - - public String counterName; - - public boolean isActive() { - return counterName != null; - } - - public BlockEntityStatisticTurnstile(BlockPos pos, BlockState state) { - super(Main.BLOCK_ENTITY_TYPE_STATISTIC_TURNSTILE.get(), pos, state); - } - - @Override - public void readCompoundTag(CompoundTag compoundTag) { - counterName = compoundTag.getString("counterName"); - if (StringUtils.isEmpty(counterName)) counterName = null; - } - - @Override - public void writeCompoundTag(CompoundTag compoundTag) { - compoundTag.putString("counterName", counterName == null ? "" : counterName); - } - } -} diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/AbstractScrollWidget.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/AbstractScrollWidget.java index c1f1737c..c92994df 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/AbstractScrollWidget.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/AbstractScrollWidget.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; @@ -65,19 +66,24 @@ public boolean mouseScrolled(double mouseX, double mouseY, double delta) { } @Override -#if MC_VERSION >= "11904" - public void renderWidget(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { +#if MC_VERSION >= "12000" + public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + PoseStack poseStack = guiGraphics.pose(); +#elif MC_VERSION >= "11904" + public void renderWidget(PoseStack guiGraphics, int mouseX, int mouseY, float partialTick) { + PoseStack poseStack = guiGraphics; #else - public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + public void renderButton(PoseStack guiGraphics, int mouseX, int mouseY, float partialTick) { + PoseStack poseStack = guiGraphics; #endif if (!this.visible) { return; } - this.renderBackground(poseStack); + this.renderBackground(guiGraphics); vcEnableScissor(this.getX() + 1, this.getY() + 1, this.getX() + this.width - 1, this.getY() + this.height - 1); poseStack.pushPose(); poseStack.translate(0.0, -this.offset, 0.0); - this.renderContents(poseStack, mouseX, mouseY, partialTick); + this.renderContents(guiGraphics, mouseX, mouseY, partialTick); poseStack.popPose(); RenderSystem.disableScissor(); if (this.getScrollBarVisible()) { @@ -112,10 +118,17 @@ protected int getMaxOffset() { return Math.max(0, this.getContentHeight() - this.height); } +#if MC_VERSION >= "12000" + private void renderBackground(GuiGraphics guiGraphics) { + guiGraphics.fill(this.getX(), this.getY() + 1, this.getX() + this.width, this.getY() + this.height - 1, this.isFocused() ? 0xffffffff : 0xffa0a0a0); + guiGraphics.fill(this.getX() + 1, this.getY() + 1, this.getX() + this.width - 1, this.getY() + this.height - 1, 0xff555555); + } +#else private void renderBackground(PoseStack poseStack) { fill(poseStack, this.getX(), this.getY() + 1, this.getX() + this.width, this.getY() + this.height - 1, this.isFocused() ? 0xffffffff : 0xffa0a0a0); fill(poseStack, this.getX() + 1, this.getY() + 1, this.getX() + this.width - 1, this.getY() + this.height - 1, 0xff555555); } +#endif private void renderScrollBar() { int i = this.getScrollBarHeight(); @@ -148,7 +161,11 @@ protected boolean isMouseInside(double x, double y) { protected abstract double getScrollInterval(); +#if MC_VERSION >= "12000" + protected abstract void renderContents(GuiGraphics var1, int var2, int var3, float var4); +#else protected abstract void renderContents(PoseStack var1, int var2, int var3, float var4); +#endif #if MC_VERSION < "11903" protected int getX() { diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/BrushEditRailScreen.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/BrushEditRailScreen.java index c2a39df9..9985bb59 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/BrushEditRailScreen.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/BrushEditRailScreen.java @@ -14,6 +14,7 @@ import mtr.screen.WidgetBetterTextField; import net.minecraft.Util; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.ConfirmLinkScreen; import net.minecraft.core.BlockPos; @@ -267,12 +268,18 @@ public static void applyBrushToPickedRail(CompoundTag railBrushProp, boolean isB } @Override +#if MC_VERSION >= "12000" + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + this.renderBackground(guiGraphics); + super.render(guiGraphics, mouseX, mouseY, partialTick); +#else public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { this.renderBackground(poseStack); super.render(poseStack, mouseX, mouseY, partialTick); +#endif if (isSelectingModel) { - renderSelectPage(poseStack); + renderSelectPage(guiGraphics); } } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ConfigScreen.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ConfigScreen.java index 4eeb2072..ad061e88 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ConfigScreen.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ConfigScreen.java @@ -8,6 +8,7 @@ import mtr.mappings.UtilitiesClient; import mtr.screen.WidgetBetterCheckbox; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; @@ -117,14 +118,22 @@ protected void init() { } @Override - public void render(PoseStack matrixStack, - int mouseX, int mouseY, float partialTicks) { - this.renderBackground(matrixStack); +#if MC_VERSION >= "12000" + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { +#else + public void render(PoseStack guiGraphics, int mouseX, int mouseY, float partialTicks) { +#endif + this.renderBackground(guiGraphics); // Options row list must be rendered here, // otherwise the GUI will be broken - drawCenteredString(matrixStack, this.font, this.title.getString(), +#if MC_VERSION >= "12000" + guiGraphics.drawCenteredString(this.font, this.title.getString(), this.width / 2, TITLE_HEIGHT, 0xFFFFFF); - super.render(matrixStack, mouseX, mouseY, partialTicks); +#else + drawCenteredString(guiGraphics, this.font, this.title.getString(), + this.width / 2, TITLE_HEIGHT, 0xFFFFFF); +#endif + super.render(guiGraphics, mouseX, mouseY, partialTicks); } @Override diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ErrorScreen.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ErrorScreen.java index 1460f1be..22c23f8e 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ErrorScreen.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ErrorScreen.java @@ -6,6 +6,7 @@ import mtr.mappings.Text; import mtr.mappings.UtilitiesClient; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.FormattedText; @@ -61,16 +62,34 @@ protected void init() { } @Override - public void render(PoseStack poseStack, int i, int j, float f) { - this.fillGradient(poseStack, 0, 0, this.width, this.height, 0xFF03458C, 0xFF001A3B); - super.render(poseStack, i, j, f); - - drawCenteredString(poseStack, font, Integer.toString(offset + 1), (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 2.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); - drawCenteredString(poseStack, font, "/", (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 3.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); - drawCenteredString(poseStack, font, Integer.toString(pages), (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 4.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); +#if MC_VERSION >= "12000" + public void render(GuiGraphics guiGraphics, int i, int j, float f) { +#else + public void render(PoseStack guiGraphics, int i, int j, float f) { +#endif +#if MC_VERSION >= "12000" + guiGraphics.fillGradient(0, 0, this.width, this.height, 0xFF03458C, 0xFF001A3B); +#else + fillGradient(guiGraphics, 0, 0, this.width, this.height, 0xFF03458C, 0xFF001A3B); +#endif + super.render(guiGraphics, i, j, f); + +#if MC_VERSION >= "12000" + guiGraphics.drawCenteredString(font, Integer.toString(offset + 1), (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 2.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); + guiGraphics.drawCenteredString(font, "/", (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 3.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); + guiGraphics.drawCenteredString(font, Integer.toString(pages), (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 4.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); +#else + drawCenteredString(guiGraphics, font, Integer.toString(offset + 1), (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 2.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); + drawCenteredString(guiGraphics, font, "/", (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 3.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); + drawCenteredString(guiGraphics, font, Integer.toString(pages), (int)(width - SQUARE_SIZE * 1.5F), (int)(SQUARE_SIZE * 4.5F - TEXT_HEIGHT * 0.5F), 0xFFFFFFFF); +#endif for (int n = offset * pageLines; n < Math.min(splitErrorList.length, (offset + 1) * pageLines); n++) { - drawString(poseStack, font, splitErrorList[n], SQUARE_SIZE, (n - offset * pageLines) * (TEXT_HEIGHT + 1) + SQUARE_SIZE, 0xFFFFFFFF); +#if MC_VERSION >= "12000" + guiGraphics.drawString(font, splitErrorList[n], SQUARE_SIZE, (n - offset * pageLines) * (TEXT_HEIGHT + 1) + SQUARE_SIZE, 0xFFFFFFFF); +#else + drawString(guiGraphics, font, splitErrorList[n], SQUARE_SIZE, (n - offset * pageLines) * (TEXT_HEIGHT + 1) + SQUARE_SIZE, 0xFFFFFFFF); +#endif } } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/EyeCandyScreen.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/EyeCandyScreen.java index a30b8b8b..7882e4d9 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/EyeCandyScreen.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/EyeCandyScreen.java @@ -13,6 +13,7 @@ import mtr.screen.WidgetBetterCheckbox; import net.minecraft.Util; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.ConfirmLinkScreen; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; @@ -50,12 +51,16 @@ protected void init() { } @Override - public void render(@NotNull PoseStack poseStack, int i, int j, float f) { - this.renderBackground(poseStack); - super.render(poseStack, i, j, f); +#if MC_VERSION >= "12000" + public void render(@NotNull GuiGraphics guiGraphics, int i, int j, float f) { +#else + public void render(@NotNull PoseStack guiGraphics, int i, int j, float f) { +#endif + this.renderBackground(guiGraphics); + super.render(guiGraphics, i, j, f); if (isSelectingModel) { - super.renderSelectPage(poseStack); + super.renderSelectPage(guiGraphics); } } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/SelectListScreen.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/SelectListScreen.java index 94bc4101..5b9c3836 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/SelectListScreen.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/SelectListScreen.java @@ -8,6 +8,7 @@ import mtr.mappings.UtilitiesClient; import mtr.screen.WidgetBetterTextField; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; @@ -89,7 +90,11 @@ public void tick() { protected abstract List> getRegistryEntries(); - protected void renderSelectPage(PoseStack poseStack) { +#if MC_VERSION >= "12000" + protected void renderSelectPage(GuiGraphics guiGraphics) { +#else + protected void renderSelectPage(PoseStack guiGraphics) { +#endif } @@ -112,9 +117,13 @@ protected void loadSelectPage(Function btnActivePredicate) { } @Override - public void renderBackground(PoseStack poseStack) { +#if MC_VERSION >= "12000" + public void renderBackground(GuiGraphics guiGraphics) { +#else + public void renderBackground(PoseStack guiGraphics) { +#endif if (scrollList.visible) return; - super.renderBackground(poseStack); + super.renderBackground(guiGraphics); } public boolean isSelecting() { diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetLabel.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetLabel.java index 0152b1cd..7520ff11 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetLabel.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetLabel.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; #if MC_VERSION >= "11700" import net.minecraft.client.gui.narration.NarrationElementOutput; @@ -26,11 +27,12 @@ public WidgetLabel(int x, int y, int width, Component text, Runnable onClick) { this.onClick = onClick; } -#if MC_VERSION >= "11904" @Override +#if MC_VERSION >= "12000" + public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { +#elif MC_VERSION >= "11904" public void renderWidget(PoseStack matrices, int mouseX, int mouseY, float delta) { #else - @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { #endif if (!visible) return; @@ -48,14 +50,27 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { if (textWidth > this.width) { int offset = (int)(System.currentTimeMillis() / 25 % (textWidth + 40)); AbstractScrollWidget.vcEnableScissor(this.getX(), this.getY(), this.getX() + this.width, this.getY() + this.height); +#if MC_VERSION >= "12000" + guiGraphics.drawString(Minecraft.getInstance().font, lines[i], x - offset, y, -1); + guiGraphics.drawString(Minecraft.getInstance().font, lines[i], x + textWidth + 40 - offset, y, -1); +#else drawString(matrices, Minecraft.getInstance().font, lines[i], x - offset, y, -1); drawString(matrices, Minecraft.getInstance().font, lines[i], x + textWidth + 40 - offset, y, -1); +#endif RenderSystem.disableScissor(); } else { - drawString(matrices, Minecraft.getInstance().font, lines[i], x, y, -1); +#if MC_VERSION >= "12000" + guiGraphics.drawString(Minecraft.getInstance().font, lines[i], x, y, -1); +#else + drawString(matrices, Minecraft.getInstance().font, "▶", x - 8, y, 0xffff0000); +#endif } if (!isActive()) { +#if MC_VERSION >= "12000" + guiGraphics.drawString(Minecraft.getInstance().font, "▶", x - 8, y, 0xffff0000); +#else drawString(matrices, Minecraft.getInstance().font, "▶", x - 8, y, 0xffff0000); +#endif } } } diff --git a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetScrollList.java b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetScrollList.java index f189fe78..588f8de6 100644 --- a/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetScrollList.java +++ b/common/src/main/java/cn/zbx1425/mtrsteamloco/gui/WidgetScrollList.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import mtr.mappings.Text; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; @@ -16,10 +17,16 @@ public WidgetScrollList(int x, int y, int w, int h) { } @Override - protected void renderContents(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { +#if MC_VERSION >= "12000" + protected void renderContents(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + PoseStack poseStack = guiGraphics.pose(); +#else + protected void renderContents(PoseStack guiGraphics, int mouseX, int mouseY, float partialTick) { + PoseStack postStack = guiGraphics; +#endif poseStack.translate(this.getX(), this.getY(), 0.0); for (AbstractWidget widget : children) { - widget.render(poseStack, mouseX - this.getX(), (int) (mouseY + getOffset()) - this.getY(), partialTick); + widget.render(guiGraphics, mouseX - this.getX(), (int) (mouseY + getOffset()) - this.getY(), partialTick); } }