From 9262a797ebbe64415788e7e71b3e2be26506bcab Mon Sep 17 00:00:00 2001 From: thepigcat Date: Thu, 2 May 2024 18:02:43 +0200 Subject: [PATCH] port to 1.20.6 --- build.gradle | 70 ++----------------- gradle.properties | 36 ++++------ .../invertedbed/IBClientEvents.java | 3 +- .../invertedbed/IBServerEvents.java | 3 +- .../invertedbed/block/InvertedBedBlock.java | 12 +++- .../{mods.toml => neoforge.mods.toml} | 2 +- .../assets/invertedbed/lang/en_us.json | 2 + 7 files changed, 37 insertions(+), 91 deletions(-) rename src/main/resources/META-INF/{mods.toml => neoforge.mods.toml} (98%) diff --git a/build.gradle b/build.gradle index 8bd9e19..75a676e 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.97' + id 'net.neoforged.gradle.userdev' version '7.0.105' } version = mod_version @@ -17,34 +17,18 @@ base { archivesName = mod_id } -// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) -//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') -//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager - -// Default run configurations. -// These can be tweaked, removed, or duplicated as needed. runs { - // applies to all the run configs below configureEach { - // Recommended logging data for a userdev environment - // The markers can be added/remove as needed separated by commas. - // "SCAN": For mods scan. - // "REGISTRIES": For firing of registry events. - // "REGISTRYDUMP": For getting the contents of all registries. systemProperty 'forge.logging.markers', 'REGISTRIES' - // Recommended logging level for the console - // You can set various levels here. - // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels systemProperty 'forge.logging.console.level', 'debug' modSource project.sourceSets.main } client { - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. systemProperty 'forge.enabledGameTestNamespaces', project.mod_id } @@ -53,69 +37,25 @@ runs { programArgument '--nogui' } - // This run config launches GameTestServer and runs all registered gametests, then exits. - // By default, the server will crash when no gametests are provided. - // The gametest system is also enabled by default for other run configs under the /test command. gameTestServer { systemProperty 'forge.enabledGameTestNamespaces', project.mod_id } data { - // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it - // workingDirectory project.file('run-data') - - // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } } -// Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } -// Sets up a dependency configuration called 'localRuntime'. -// This configuration should be used instead of 'runtimeOnly' to declare -// a dependency that will be present for runtime testing but that is -// "optional", meaning it will not be pulled by dependents of this mod. configurations { runtimeClasspath.extendsFrom localRuntime } dependencies { - // Specify the version of Minecraft to use. - // Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above. - // The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version. - // You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader. - // And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version. - // For all intends and purposes: You can treat this dependency as if it is a normal library you would use. implementation "net.neoforged:neoforge:${neo_version}" - - // Example optional mod dependency with JEI - // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime - // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" - // compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}" - // We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it - // localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}" - - // Example mod dependency using a mod jar from ./libs with a flat dir repository - // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar - // The group id is ignored when searching -- in this case, it is "blank" - // implementation "blank:coolmod-${mc_version}:${coolmod_version}" - - // Example mod dependency using a file as dependency - // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") - - // Example project dependency using a sister or child project: - // implementation project(":myproject") - - // For more info: - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html } -// This block of code expands all declared replace properties in the specified resource targets. -// A missing property will result in an error. Properties are expanded using ${} Groovy notation. -// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. -// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.withType(ProcessResources).configureEach { var replaceProperties = [ minecraft_version : minecraft_version, @@ -132,12 +72,11 @@ tasks.withType(ProcessResources).configureEach { ] inputs.properties replaceProperties - filesMatching(['META-INF/mods.toml']) { + filesMatching(['META-INF/neoforge.mods.toml']) { expand replaceProperties } } -// Example configuration to allow publishing using the maven-publish plugin publishing { publications { register('mavenJava', MavenPublication) { @@ -152,10 +91,9 @@ publishing { } tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation + options.encoding = 'UTF-8' } -// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. idea { module { downloadSources = true diff --git a/gradle.properties b/gradle.properties index ee61d51..c68185c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,34 +10,28 @@ neogradle.subsystems.parchment.mappingsVersion=2024.04.14 # Environment Properties # You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge # The Minecraft version must agree with the Neo version to get a valid artifact -minecraft_version=1.20.4 -# The Minecraft version range can use any release version of Minecraft as bounds. -# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly -# as they do not follow standard versioning conventions. -minecraft_version_range=[1.20.4,1.21) -# The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=20.4.233 -# The Neo version range can use any version of Neo as bounds +minecraft_version=1.20.6 + +minecraft_version_range=[1.20.6,1.21) + +neo_version=20.6.18-beta + neo_version_range=[20.4,) -# The loader version range can only use the major version of FML as bounds + loader_version_range=[2,) ## Mod Properties -# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} -# Must match the String constant located in the main mod class annotated with @Mod. mod_id=invertedbed -# The human-readable display name for the mod. + mod_name=Inverted Bed -# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. + mod_license=MIT -# The mod version. See https://semver.org/ -mod_version=1.0.0 -# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. -# This should match the base package used for the mod sources. -# See https://maven.apache.org/guides/mini/guide-naming-conventions.html + +mod_version=1.0.1 + mod_group_id=com.leclowndu93150.invertedbed -# The authors of the mod. This is a simple text string that is used for display purposes in the mod list. + mod_authors=Leclowndu93150, Buzz135 -# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. -mod_description=Adds a bed that skips the day \ No newline at end of file + +mod_description=Adds a bed that skips the day diff --git a/src/main/java/com/leclowndu93150/invertedbed/IBClientEvents.java b/src/main/java/com/leclowndu93150/invertedbed/IBClientEvents.java index 02f9660..5f688d8 100644 --- a/src/main/java/com/leclowndu93150/invertedbed/IBClientEvents.java +++ b/src/main/java/com/leclowndu93150/invertedbed/IBClientEvents.java @@ -3,12 +3,13 @@ import com.leclowndu93150.invertedbed.block.InvertedBedRenderer; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.client.event.EntityRenderersEvent; import static com.leclowndu93150.invertedbed.Main.*; -@Mod.EventBusSubscriber(modid = Main.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) +@EventBusSubscriber(modid = Main.MODID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) public class IBClientEvents { @SubscribeEvent diff --git a/src/main/java/com/leclowndu93150/invertedbed/IBServerEvents.java b/src/main/java/com/leclowndu93150/invertedbed/IBServerEvents.java index 918cd26..e84f66a 100644 --- a/src/main/java/com/leclowndu93150/invertedbed/IBServerEvents.java +++ b/src/main/java/com/leclowndu93150/invertedbed/IBServerEvents.java @@ -6,6 +6,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.neoforged.bus.api.Event; import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.event.entity.player.PlayerWakeUpEvent; import net.neoforged.neoforge.event.entity.player.SleepingLocationCheckEvent; @@ -13,7 +14,7 @@ import static com.leclowndu93150.invertedbed.Main.MODID; -@Mod.EventBusSubscriber(modid = MODID) +@EventBusSubscriber(modid = MODID) public class IBServerEvents { @SubscribeEvent public static void onTrySleep(PlayerWakeUpEvent event) { diff --git a/src/main/java/com/leclowndu93150/invertedbed/block/InvertedBedBlock.java b/src/main/java/com/leclowndu93150/invertedbed/block/InvertedBedBlock.java index 7d4a625..31d8604 100644 --- a/src/main/java/com/leclowndu93150/invertedbed/block/InvertedBedBlock.java +++ b/src/main/java/com/leclowndu93150/invertedbed/block/InvertedBedBlock.java @@ -1,6 +1,7 @@ package com.leclowndu93150.invertedbed.block; +import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -10,6 +11,9 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -67,7 +71,7 @@ public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) { } @Override - public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) { + protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult p_49520_) { if (pLevel.isClientSide) { return InteractionResult.CONSUME; } else { @@ -119,4 +123,10 @@ private boolean kickVillagerOutOfBed(Level pLevel, BlockPos pPos) { return true; } } + + @Override + public void appendHoverText(ItemStack p_49816_, Item.TooltipContext p_339606_, List pTooltip, TooltipFlag p_49819_) { + pTooltip.add(Component.translatable("block.invertedbed.inverted_bed.tooltip0").withStyle(ChatFormatting.DARK_GRAY)); + pTooltip.add(Component.translatable("block.invertedbed.inverted_bed.tooltip1").withStyle(ChatFormatting.DARK_GRAY)); + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 98% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml index 587cef0..49ba37c 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -1,4 +1,4 @@ -# This is an example mods.toml file. It contains the data relating to the loading mods. +# This is an example neoforge.mods.toml file. It contains the data relating to the loading mods. # There are several mandatory fields (#mandatory), and many more that are optional (#optional). # The overall format is standard TOML format, v0.5.0. # Note that there are a couple of TOML lists in this file. diff --git a/src/main/resources/assets/invertedbed/lang/en_us.json b/src/main/resources/assets/invertedbed/lang/en_us.json index 698c0f1..fceb8a0 100644 --- a/src/main/resources/assets/invertedbed/lang/en_us.json +++ b/src/main/resources/assets/invertedbed/lang/en_us.json @@ -16,5 +16,7 @@ "block.invertedbed.green_inverted_bed":"Green Inverted Bed", "block.invertedbed.black_inverted_bed":"Black Inverted Bed", "block.invertedbed.bed.not_possible_now": "You can sleep only at day", + "block.invertedbed.inverted_bed.tooltip0": "Allows sleeping on the day", + "block.invertedbed.inverted_bed.tooltip1": "Can be placed on the ceiling", "itemGroup.invertedbed":"Inverted Bed" } \ No newline at end of file