From e52702ecad9152f811a9e73af51a97803d7b6470 Mon Sep 17 00:00:00 2001 From: Yjn024 Date: Fri, 2 Dec 2022 16:35:31 +0800 Subject: [PATCH] fabric port --- .gitignore | 41 +-- build.gradle | 274 +++++------------- gradle.properties | 38 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 0 settings.gradle | 10 + .../dragons/createdragonlib/DragonLib.java | 17 +- .../advancement/AdvancementFactory.java | 21 +- .../fluid/FluidLavaReaction.java | 28 +- .../fluid/NoTintFluidType.java | 56 ---- .../createdragonlib/gui/ComponentLabel.java | 68 +++-- .../createdragonlib/gui/GuiTexture.java | 13 +- .../init/FillCreateItemGroupEvent.java | 61 ++-- .../createdragonlib/init/SafeRegistrate.java | 46 ++- .../dragons/createdragonlib/lang/Lang.java | 7 +- .../createdragonlib/lang/LangFactory.java | 16 +- .../createdragonlib/lang/LangMerger.java | 126 ++++---- .../createdragonlib/lang/LangPartial.java | 5 +- .../mixin/CreateItemGroupBaseMixin.java | 11 +- .../mixin/FluidReactionsMixin.java | 52 ++-- src/main/resources/META-INF/mods.toml | 36 --- src/main/resources/fabric.mod.json | 24 ++ src/main/resources/pack.mcmeta | 8 - 23 files changed, 406 insertions(+), 554 deletions(-) mode change 100644 => 100755 gradlew create mode 100644 settings.gradle delete mode 100644 src/main/java/plus/dragons/createdragonlib/fluid/NoTintFluidType.java delete mode 100644 src/main/resources/META-INF/mods.toml create mode 100644 src/main/resources/fabric.mod.json delete mode 100644 src/main/resources/pack.mcmeta diff --git a/.gitignore b/.gitignore index f0f6334..09cd281 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,33 @@ +# gradle + +.gradle/ +build/ +out/ +classes/ + # eclipse -bin + *.launch -.settings -.metadata -.classpath -.project # idea -out + +.idea/ +*.iml *.ipr *.iws -*.iml -.idea -# gradle -build -.gradle +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# macos + +*.DS_Store -# other -eclipse -run +# fabric -# Files from Forge MDK -forge*changelog.txt -/local.properties +run/ diff --git a/build.gradle b/build.gradle index f4157c8..2e33ff0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,236 +1,102 @@ -buildscript { - repositories { - // These repositories are only for Gradle plugins, put any other repositories in the repository block further below - maven { url = 'https://maven.minecraftforge.net' } - mavenCentral() - maven { url = 'https://maven.parchmentmc.org' } - maven { url = 'https://repo.spongepowered.org/repository/maven-public' } - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: "${forgegradle_version}", changing: true - classpath "org.parchmentmc:librarian:${librarian_version}" - classpath "org.spongepowered:mixingradle:${mixingradle_version}" - } -} -// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'org.parchmentmc.librarian.forgegradle' -apply plugin: 'eclipse' -apply plugin: 'maven-publish' -apply plugin: 'signing' -apply plugin: 'org.spongepowered.mixin' - -version = mod_version -group = 'plus.dragons.createdragonlib' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = "create_dragon_lib-${artifact_minecraft_version}" - -// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" -minecraft { - // The mappings can be changed at any time and must be in the following format. - // Channel: Version: - // official MCVersion Official field/method names from Mojang mapping files - // parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official - // - // You must be aware of the Mojang license when using the 'official' or 'parchment' mappings. - // See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md - // - // Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge - // Additional setup is needed to use their mappings: https://github.com/ParchmentMC/Parchment/wiki/Getting-Started - // - // Use non-default mappings at your own risk. They may not always work. - // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}" - // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default. - - // Default run configurations. - // These can be tweaked, removed, or duplicated as needed. - runs { - client { - workingDirectory project.file('run') - - arg '-mixin.config=create_dragon_lib.mixins.json' - - // 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. - property '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 - property 'forge.logging.console.level', 'debug' - - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - property 'forge.enabledGameTestNamespaces', 'examplemod' - - mods { - create_dragon_lib { - source sourceSets.main - } - } - } - - server { - workingDirectory project.file('run') - - arg '-mixin.config=create_dragon_lib.mixins.json' - - property 'forge.logging.markers', 'REGISTRIES' - - property 'forge.logging.console.level', 'debug' - - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - property 'forge.enabledGameTestNamespaces', 'examplemod' - - mods { - create_dragon_lib { - source sourceSets.main - } - } - } - - data { - workingDirectory project.file('run') - - property 'forge.logging.markers', 'REGISTRIES' - - property 'forge.logging.console.level', 'debug' - - // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. - args '--mod', 'create_dragon_lib', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') - - mods { - create_dragon_lib { - source sourceSets.main - } - } - } - } +plugins { + id 'fabric-loom' version '1.0.9' + id 'maven-publish' } +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 -repositories { - // Put repositories for dependencies here - // ForgeGradle automatically adds the Forge maven and Maven Central for you +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group - // If you have mod jar dependencies in ./libs, you can declare them as a repository like so: - // flatDir { - // dir 'libs' - // } - maven { - name = 'tterrag maven' - url = 'https://maven.tterrag.com/' - } - maven { - // Location of the maven that hosts JEI files (and TiC) - name 'Progwml6 maven' - url 'https://dvs1.progwml6.com/files/maven' - } - maven { - // Location of the maven for vazkii's mods - name 'blamejared' - url 'https://maven.blamejared.com' - } +repositories { + maven { url = "https://hephaestus.dev/release" } + maven { url = "https://api.modrinth.com/maven" } + maven { url = "https://cursemaven.com" } + maven { url = "https://maven.parchmentmc.org" } + maven { url = "https://maven.fabricmc.net/" } + maven { url = "https://maven.tterrag.com/" } + maven { url = "https://storage.googleapis.com/devan-maven/" } + maven { url = "https://maven.shedaniel.me/" } + maven { url = "https://aperlambda.github.io/maven" } + maven { url = "https://ladysnake.jfrog.io/artifactory/mods" } + maven { url = "https://maven.kotlindiscord.com/repository/terraformers/" } + maven { url = "https://mvn.devos.one/releases/" } + maven { url = "https://mvn.devos.one/snapshots/" } + maven { url = "https://maven.terraformersmc.com/" } + maven { url = "https://maven.cafeteria.dev/releases/" } + maven { url = "https://jitpack.io/" } + maven { url = "https://maven.gegy.dev" } + maven { url = "https://dvs1.progwml6.com/files/maven/" } + maven { url = "https://modmaven.dev" } maven { - //location of the maven for curios api - url = "https://maven.theillusivec4.top/" + url = "https://maven.jamieswhiteshirt.com/libs-release" + content { + includeGroup("com.jamieswhiteshirt") + } } } dependencies { - // Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed - // that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied. - // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - - // Real mod deobf dependency examples - these get remapped to your current mappings - // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency - // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency - // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings (loom.officialMojangMappings()) + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Examples using mod jars from ./libs - // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}") - implementation fg.deobf("com.simibubi.create:create-${create_minecraft_version}:${create_version}:slim") { transitive = false } - implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") - implementation fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}") - - compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}-common-api:${jei_version}") - compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}-forge-api:${jei_version}") - runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}-forge:${jei_version}") + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modImplementation "com.simibubi.create:create-fabric-1.19.2:${project.create_version}+${project.minecraft_version}" +} - compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_minecraft_version}-${curios_version}:api") - runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_minecraft_version}-${curios_version}") +processResources { + inputs.property "version", project.version - // For more info... - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html - annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor" + filesMatching("fabric.mod.json") { + expand "version": project.version + } } -// Include resources generated by data generators. -sourceSets.main.resources { - srcDir'src/generated/resources' - exclude '.cache/' +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 } -mixin { - add sourceSets.main, 'create_dragon_lib.refmap.json' - config 'create_dragon_lib.mixins.json' - - debug.verbose = true - debug.export = true +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() } - -// Example for how to get properties into the manifest for reading at runtime. jar { - manifest { - attributes([ - "Specification-Title" : "create_dragon_lib", - "Specification-Vendor" : "dragons.plus", - "Specification-Version" : "1", // We are version 1 of ourselves - "Implementation-Title" : project.name, - "Implementation-Version" : project.jar.archiveVersion, - "Implementation-Vendor" : "dragons.plus", - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'MixinConfigs': 'create_dragon_lib.mixins.json' - ]) + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} } } -// Example configuration to allow publishing using the maven-publish plugin -// This is the preferred method to reobfuscate your jar file -jar.finalizedBy('reobfJar') -// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing -// publish.dependsOn('reobfJar') +sourceSets { + main { + resources { + srcDirs += [ + 'src/generated/resources' + ] + } + } +} +// configure the maven publication publishing { publications { mavenJava(MavenPublication) { - artifactId = archivesBaseName - from components.java - fg.component(it) } } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - maven { - name = "repository" - url = "https://maven.dragons.plus/Releases" - credentials(PasswordCredentials) - authentication { - basic(BasicAuthentication) - } - } + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. } -} - -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 494ccdc..eccb2f5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,28 +1,18 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. +# Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false +org.gradle.parallel=true -# mod version info -mod_version = 1.1.1 -artifact_minecraft_version = 1.19.2 -minecraft_version = 1.19.2 -forge_version = 43.1.0 +# Fabric Properties + # check these on https://fabricmc.net/develop + minecraft_version=1.19.2 + yarn_mappings=1.19.2+build.28 + loader_version=0.14.10 -# build dependency versions -forgegradle_version = 5.1.53 -mixingradle_version = 0.7-SNAPSHOT -mixin_version = 0.8.5 -librarian_version = 1.+ -parchment_version = 2022.08.10 +# Mod Properties + mod_version = 1.1.1 + maven_group = plus.dragons.createdragonlib + archives_base_name = create_dragon_lib-1.19.2 -# dependency versions -create_minecraft_version = 1.19.2 -create_version = 0.5.0.f-15 -flywheel_minecraft_version = 1.19.2 -flywheel_version = 0.6.7-8 -registrate_version = MC1.19-1.1.5 -jei_minecraft_version = 1.19.2 -jei_version = 11.2.0.254 -curios_minecraft_version = 1.19.2 -curios_version = 5.1.1.0 \ No newline at end of file +# Dependencies + fabric_version=0.67.0+1.19.2 + create_version=0.5.0g-791 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..070cb70 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..b02216b --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + mavenCentral() + gradlePluginPortal() + } +} diff --git a/src/main/java/plus/dragons/createdragonlib/DragonLib.java b/src/main/java/plus/dragons/createdragonlib/DragonLib.java index c8b83d6..8b4515f 100644 --- a/src/main/java/plus/dragons/createdragonlib/DragonLib.java +++ b/src/main/java/plus/dragons/createdragonlib/DragonLib.java @@ -1,20 +1,21 @@ package plus.dragons.createdragonlib; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -@Mod(DragonLib.ID) -public class DragonLib { +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; + +public class DragonLib implements ModInitializer { public static final String ID = "create_dragon_lib"; private static final Logger LOGGER = LogManager.getLogger(); - public DragonLib() { + @Override + public void onInitialize() { LOGGER.info("Create: Dragon Lib " + - ModLoadingContext.get().getActiveContainer().getModInfo().getVersion() + - " has initialized, ready to support your Create add-ons!" - ); + FabricLoader.getInstance().getModContainer(ID).get().getMetadata().getName() + + " has initialized, ready to support your Create add-ons!"); + } } diff --git a/src/main/java/plus/dragons/createdragonlib/advancement/AdvancementFactory.java b/src/main/java/plus/dragons/createdragonlib/advancement/AdvancementFactory.java index b8eea08..c8b681b 100644 --- a/src/main/java/plus/dragons/createdragonlib/advancement/AdvancementFactory.java +++ b/src/main/java/plus/dragons/createdragonlib/advancement/AdvancementFactory.java @@ -1,7 +1,6 @@ package plus.dragons.createdragonlib.advancement; -import net.minecraft.data.DataGenerator; -import net.minecraftforge.data.event.GatherDataEvent; +import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import plus.dragons.createdragonlib.advancement.critereon.TriggerFactory; public class AdvancementFactory { @@ -15,12 +14,13 @@ private AdvancementFactory(String name, String modid, Runnable preTask) { this.advancementGen = new AdvancementGen(name, modid); this.preTask = preTask; } - + @Deprecated(since = "1.1.1", forRemoval = true) public static AdvancementFactory create(String name, String modid) { - return new AdvancementFactory(name, modid, () -> {}); + return new AdvancementFactory(name, modid, () -> { + }); } - + public static AdvancementFactory create(String name, String modid, Runnable preTask) { return new AdvancementFactory(name, modid, preTask); } @@ -28,20 +28,19 @@ public static AdvancementFactory create(String name, String modid, Runnable preT public AdvancementHolder.Builder builder(String id) { return new AdvancementHolder.Builder(modid, id, triggerFactory); } - + public TriggerFactory getTriggerFactory() { return triggerFactory; } - - public void datagen(final GatherDataEvent event) { + + public void datagen(final FabricDataGenerator datagen) { preTask.run(); - DataGenerator datagen = event.getGenerator(); advancementGen.generator = datagen; - datagen.addProvider(event.includeServer(), advancementGen); + datagen.addProvider(advancementGen); } public void register() { triggerFactory.register(); } - + } diff --git a/src/main/java/plus/dragons/createdragonlib/fluid/FluidLavaReaction.java b/src/main/java/plus/dragons/createdragonlib/fluid/FluidLavaReaction.java index f8364d4..3a53d31 100644 --- a/src/main/java/plus/dragons/createdragonlib/fluid/FluidLavaReaction.java +++ b/src/main/java/plus/dragons/createdragonlib/fluid/FluidLavaReaction.java @@ -1,29 +1,29 @@ package plus.dragons.createdragonlib.fluid; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.ForgeMod; -import net.minecraftforge.fluids.FluidInteractionRegistry; -import net.minecraftforge.fluids.FluidType; +import java.util.IdentityHashMap; + import org.jetbrains.annotations.Nullable; -import java.util.IdentityHashMap; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.minecraft.world.level.block.state.BlockState; public record FluidLavaReaction(BlockState withLava, BlockState withFlowingLava, BlockState lavaOnSelf) { - private static final IdentityHashMap REACTIONS = new IdentityHashMap<>(); + private static final IdentityHashMap REACTIONS = new IdentityHashMap<>(); - public static void register(FluidType type, BlockState withLava, BlockState withFlowingLava, BlockState lavaOnSelf) { - FluidInteractionRegistry.addInteraction(ForgeMod.LAVA_TYPE.get(), new FluidInteractionRegistry.InteractionInformation( - type, fluidState -> fluidState.isSource() ? withLava : withFlowingLava - )); - FluidInteractionRegistry.addInteraction(type, new FluidInteractionRegistry.InteractionInformation( - ForgeMod.LAVA_TYPE.get(), lavaOnSelf - )); + public static void register(FluidVariant type, BlockState withLava, BlockState withFlowingLava, BlockState lavaOnSelf) { + // TODO + // FluidInteractionRegistry.addInteraction(ForgeMod.LAVA_TYPE.get(), new FluidInteractionRegistry.InteractionInformation( + // type, fluidState -> fluidState.isSource() ? withLava : withFlowingLava + // )); + // FluidInteractionRegistry.addInteraction(type, new FluidInteractionRegistry.InteractionInformation( + // ForgeMod.LAVA_TYPE.get(), lavaOnSelf + // )); REACTIONS.put(type, new FluidLavaReaction(withLava, withFlowingLava, lavaOnSelf)); } @Nullable - public static FluidLavaReaction get(FluidType fluid) { + public static FluidLavaReaction get(FluidVariant fluid) { return REACTIONS.get(fluid); } diff --git a/src/main/java/plus/dragons/createdragonlib/fluid/NoTintFluidType.java b/src/main/java/plus/dragons/createdragonlib/fluid/NoTintFluidType.java deleted file mode 100644 index 516b680..0000000 --- a/src/main/java/plus/dragons/createdragonlib/fluid/NoTintFluidType.java +++ /dev/null @@ -1,56 +0,0 @@ -package plus.dragons.createdragonlib.fluid; - -import com.simibubi.create.AllFluids; -import net.minecraft.core.BlockPos; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.material.FluidState; -import net.minecraftforge.fluids.FluidStack; - -/* -MIT License - -Copyright (c) 2019 simibubi - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -/** - * Removing alpha from tint prevents optifine from forcibly applying biome - * colors to modded fluids (Makes translucent fluids disappear).
- * Originated from: {@link com.simibubi.create.AllFluids.NoColorFluidAttributes} - */ -public class NoTintFluidType extends AllFluids.TintedFluidType { - - public NoTintFluidType(Properties properties, ResourceLocation stillTexture, - ResourceLocation flowingTexture) { - super(properties, stillTexture, flowingTexture); - } - - @Override - protected int getTintColor(FluidStack stack) { - return NO_TINT; - } - - @Override - public int getTintColor(FluidState state, BlockAndTintGetter world, BlockPos pos) { - return 0x00ffffff; - } - -} diff --git a/src/main/java/plus/dragons/createdragonlib/gui/ComponentLabel.java b/src/main/java/plus/dragons/createdragonlib/gui/ComponentLabel.java index 5f9c628..e560dab 100644 --- a/src/main/java/plus/dragons/createdragonlib/gui/ComponentLabel.java +++ b/src/main/java/plus/dragons/createdragonlib/gui/ComponentLabel.java @@ -1,40 +1,49 @@ package plus.dragons.createdragonlib.gui; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import javax.annotation.Nonnull; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import com.google.common.collect.AbstractIterator; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.gui.widget.Label; import com.simibubi.create.foundation.utility.Components; + import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; /** * An extension for {@link Label} which renders {@link Component} correctly. */ public class ComponentLabel extends Label { - + public ComponentLabel(int x, int y, Component text) { super(x, y, text); } - + private Iterator getComponentIterator(Component root) { return new AbstractIterator<>() { private final Deque stack = new LinkedList<>(Collections.singleton(root)); - + @Nullable @Override protected Component computeNext() { - if(stack.isEmpty()) { + if (stack.isEmpty()) { return endOfData(); } else { Component ret = stack.pop(); List siblings = new ArrayList<>(ret.getSiblings()); Collections.reverse(siblings); - for(Component c : siblings) { + for (Component c : siblings) { stack.push(c); } return ret; @@ -42,32 +51,32 @@ protected Component computeNext() { } }; } - + private MutableComponent computeTrimmedText(Component text, boolean trimFront, int maxWidthPx) { maxWidthPx -= font.width("..."); int totalWidthPx = 0; Iterator texts = getComponentIterator(text); List result = new ArrayList<>(); - collect: - while(texts.hasNext()) { - //Add components to list + collect: while (texts.hasNext()) { + // Add components to list Component component = texts.next(); String content = component.getString(); int widthPx = font.width(Components.literal(content).setStyle(text.getStyle())); - if(totalWidthPx < maxWidthPx) { + if (totalWidthPx < maxWidthPx) { result.add(component); totalWidthPx += widthPx; continue; } - //Split tail component + // Split tail component int stringLength = content.length(); - if (stringLength == 0) continue; + if (stringLength == 0) + continue; int startIndex = trimFront ? 0 : stringLength - 1; int endIndex = !trimFront ? 0 : stringLength - 1; int step; - if(startIndex > endIndex) { + if (startIndex > endIndex) { step = -1; - } else if(startIndex < endIndex) { + } else if (startIndex < endIndex) { step = 1; } else { result.add(Components.literal(content).setStyle(component.getStyle())); @@ -82,8 +91,8 @@ private MutableComponent computeTrimmedText(Component text, boolean trimFront, i } } } - //Compute result component - if(trimFront) { + // Compute result component + if (trimFront) { var trim = Components.literal("...").setStyle(result.get(0).getStyle()); result.forEach(trim::append); return trim; @@ -94,27 +103,28 @@ private MutableComponent computeTrimmedText(Component text, boolean trimFront, i return ret.append(trim); } } - + @Override public void setTextAndTrim(Component newText, boolean trimFront, int maxWidthPx) { - if(suffix != null) maxWidthPx -= font.width(suffix); + if (suffix != null) + maxWidthPx -= font.width(suffix); text = font.width(newText) <= maxWidthPx - ? newText - : computeTrimmedText(newText, trimFront, maxWidthPx); + ? newText + : computeTrimmedText(newText, trimFront, maxWidthPx); } - + @Override - public void renderButton(@NotNull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void renderButton(@NotNull @Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { if (text == null) return; RenderSystem.setShaderColor(1, 1, 1, 1); var textToRender = suffix == null - ? text - : text.copy().append(suffix); + ? text + : text.copy().append(suffix); if (hasShadow) font.drawShadow(matrixStack, textToRender, x, y, color); else font.draw(matrixStack, textToRender, x, y, color); } - + } diff --git a/src/main/java/plus/dragons/createdragonlib/gui/GuiTexture.java b/src/main/java/plus/dragons/createdragonlib/gui/GuiTexture.java index 1b93b20..0c25f71 100644 --- a/src/main/java/plus/dragons/createdragonlib/gui/GuiTexture.java +++ b/src/main/java/plus/dragons/createdragonlib/gui/GuiTexture.java @@ -5,10 +5,11 @@ import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.gui.element.ScreenElement; import com.simibubi.create.foundation.utility.Color; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiComponent; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; /* MIT License @@ -54,25 +55,25 @@ public GuiTexture(String modid, String location, int width, int height) { this(modid, location, 0, 0, width, height); } - @OnlyIn(Dist.CLIENT) + @Environment(EnvType.CLIENT) public void bind() { RenderSystem.setShaderTexture(0, location); } - @OnlyIn(Dist.CLIENT) + @Environment(EnvType.CLIENT) @Override public void render(PoseStack ms, int x, int y) { bind(); GuiComponent.blit(ms, x, y, 0, startX, startY, width, height, 256, 256); } - @OnlyIn(Dist.CLIENT) + @Environment(EnvType.CLIENT) public void render(PoseStack ms, int x, int y, GuiComponent component) { bind(); component.blit(ms, x, y, startX, startY, width, height); } - @OnlyIn(Dist.CLIENT) + @Environment(EnvType.CLIENT) public void render(PoseStack ms, int x, int y, Color c) { bind(); UIRenderHelper.drawColoredTexture(ms, c, x, y, startX, startY, width, height); diff --git a/src/main/java/plus/dragons/createdragonlib/init/FillCreateItemGroupEvent.java b/src/main/java/plus/dragons/createdragonlib/init/FillCreateItemGroupEvent.java index d99b4cf..4da3ca9 100644 --- a/src/main/java/plus/dragons/createdragonlib/init/FillCreateItemGroupEvent.java +++ b/src/main/java/plus/dragons/createdragonlib/init/FillCreateItemGroupEvent.java @@ -1,65 +1,92 @@ package plus.dragons.createdragonlib.init; +import java.util.ArrayList; +import java.util.Collection; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +import org.jetbrains.annotations.ApiStatus; + import com.simibubi.create.foundation.item.CreateItemGroupBase; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.core.NonNullList; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.eventbus.api.Event; -import org.jetbrains.annotations.ApiStatus; - -import java.util.*; /** * Event to add items to Create's creative mode tab. */ -public class FillCreateItemGroupEvent extends Event { +public class FillCreateItemGroupEvent { + + @FunctionalInterface + public static interface Callback { + void listen(FillCreateItemGroupEvent event); + } + + public static Event INSTANCE = EventFactory.createArrayBacked(Callback.class, listeners -> event -> { + for (Callback listener : listeners) + listener.listen(event); + }); + private final CreateItemGroupBase itemGroup; private final NonNullList items; private final Map> insertions = new IdentityHashMap<>(); - + public FillCreateItemGroupEvent(CreateItemGroupBase itemGroup, NonNullList items) { this.itemGroup = itemGroup; this.items = items; } - + /** - * Get the creative mod tab, so you could determine which tab are you adding into. + * Get the creative mod tab, so you could determine which tab are you adding + * into. + * * @return the creative mod tab */ public CreateItemGroupBase getItemGroup() { return itemGroup; } - + /** * Get all Create's items in the tab.
* For adding items after certain item in the tab, * use {@link FillCreateItemGroupEvent#addInsertion(ItemLike, ItemStack)} - * and {@link FillCreateItemGroupEvent#addInsertions(ItemLike, Collection)} for convenience. + * and {@link FillCreateItemGroupEvent#addInsertions(ItemLike, Collection)} for + * convenience. + * * @return a modifiable list of all Create's items in the tab */ public NonNullList getItems() { return items; } - + /** - * Add an {@link ItemStack} after an {@link Item}, should only target Create's existing items in the tab. + * Add an {@link ItemStack} after an {@link Item}, should only target Create's + * existing items in the tab. + * * @param target the item to target - * @param stack the item stack to add + * @param stack the item stack to add */ public void addInsertion(ItemLike target, ItemStack stack) { insertions.computeIfAbsent(target.asItem(), $ -> new ArrayList<>()).add(stack); } - + /** - * Add some {@link ItemStack}s after an {@link Item}, should only target Create's existing items in the tab. + * Add some {@link ItemStack}s after an {@link Item}, should only target + * Create's existing items in the tab. + * * @param target the item to target * @param stacks the item stacks to add */ public void addInsertions(ItemLike target, Collection stacks) { insertions.computeIfAbsent(target.asItem(), $ -> new ArrayList<>()).addAll(stacks); } - + @ApiStatus.Internal public void apply() { ListIterator it = items.listIterator(); @@ -73,5 +100,5 @@ public void apply() { } } } - + } diff --git a/src/main/java/plus/dragons/createdragonlib/init/SafeRegistrate.java b/src/main/java/plus/dragons/createdragonlib/init/SafeRegistrate.java index 1ee3e91..a5a7d5f 100644 --- a/src/main/java/plus/dragons/createdragonlib/init/SafeRegistrate.java +++ b/src/main/java/plus/dragons/createdragonlib/init/SafeRegistrate.java @@ -6,46 +6,40 @@ import com.tterrag.registrate.util.nullness.NonNullConsumer; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; + +import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; -import net.minecraftforge.eventbus.api.IEventBus; public class SafeRegistrate extends CreateRegistrate { - + public SafeRegistrate(String modid) { super(modid); } - - @Override - public SafeRegistrate registerEventListeners(IEventBus bus) { - super.registerEventListeners(bus); - return this; - } - + public CreateEntityBuilder entity( - String name, - EntityType.EntityFactory factory, - NonNullSupplier>> renderer, - MobCategory group, - int range, int updateFrequency, - boolean sendVelocity, boolean immuneToFire, - NonNullConsumer> propertyBuilder) - { + String name, + EntityType.EntityFactory factory, + NonNullSupplier>> renderer, + MobCategory group, + int range, int updateFrequency, + boolean sendVelocity, boolean immuneToFire, + NonNullConsumer> propertyBuilder) { String id = Lang.asId(name); var builder = this.entity(id, factory, group); builder.properties(b -> { - if (immuneToFire) - b.fireImmune(); - b.setTrackingRange(range) - .setUpdateInterval(updateFrequency) - .setShouldReceiveVelocityUpdates(sendVelocity); - propertyBuilder.accept(b); - }) - .renderer(renderer); + if (immuneToFire) + b.fireImmune(); + b.trackRangeChunks(range) + .trackedUpdateRate(updateFrequency) + .forceTrackedVelocityUpdates(sendVelocity); + propertyBuilder.accept(b); + }) + .renderer(renderer); return builder; } - + } diff --git a/src/main/java/plus/dragons/createdragonlib/lang/Lang.java b/src/main/java/plus/dragons/createdragonlib/lang/Lang.java index 998ca0a..d479ec0 100644 --- a/src/main/java/plus/dragons/createdragonlib/lang/Lang.java +++ b/src/main/java/plus/dragons/createdragonlib/lang/Lang.java @@ -1,7 +1,11 @@ package plus.dragons.createdragonlib.lang; +import java.util.Locale; + import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.LangNumberFormat; + +import io.github.fabricators_of_create.porting_lib.util.FluidStack; import net.minecraft.Util; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -9,9 +13,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fluids.FluidStack; - -import java.util.Locale; /* MIT License diff --git a/src/main/java/plus/dragons/createdragonlib/lang/LangFactory.java b/src/main/java/plus/dragons/createdragonlib/lang/LangFactory.java index 97c3085..b976e36 100644 --- a/src/main/java/plus/dragons/createdragonlib/lang/LangFactory.java +++ b/src/main/java/plus/dragons/createdragonlib/lang/LangFactory.java @@ -1,13 +1,14 @@ package plus.dragons.createdragonlib.lang; +import java.util.Collections; +import java.util.function.Supplier; + import com.google.gson.JsonObject; import com.simibubi.create.foundation.ponder.PonderLocalization; -import net.minecraft.data.DataGenerator; -import net.minecraftforge.data.event.GatherDataEvent; -import plus.dragons.createdragonlib.advancement.AdvancementHolder; +import com.tterrag.registrate.fabric.GatherDataEvent; -import java.util.Collections; -import java.util.function.Supplier; +import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; +import plus.dragons.createdragonlib.advancement.AdvancementHolder; public class LangFactory { private final String modid; @@ -26,10 +27,9 @@ public static LangFactory create(String name, String modid) { * Register the {@link LangMerger} instance to {@link GatherDataEvent}.
* Should be called in the mod's main class' constructor.
*/ - public void datagen(final GatherDataEvent event) { - DataGenerator datagen = event.getGenerator(); + public void datagen(final FabricDataGenerator datagen) { langMerger.dataGenerator = datagen; - datagen.addProvider(event.includeClient(), langMerger); + datagen.addProvider(langMerger); } /** diff --git a/src/main/java/plus/dragons/createdragonlib/lang/LangMerger.java b/src/main/java/plus/dragons/createdragonlib/lang/LangMerger.java index bfe047d..38e0679 100644 --- a/src/main/java/plus/dragons/createdragonlib/lang/LangMerger.java +++ b/src/main/java/plus/dragons/createdragonlib/lang/LangMerger.java @@ -1,5 +1,31 @@ package plus.dragons.createdragonlib.lang; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.apache.commons.lang3.mutable.MutableBoolean; +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.lang3.mutable.MutableObject; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.ApiStatus; + import com.google.common.hash.Hashing; import com.google.common.hash.HashingOutputStream; import com.google.gson.Gson; @@ -8,24 +34,11 @@ import com.google.gson.JsonObject; import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.utility.FilesHelper; + import net.minecraft.data.CachedOutput; import net.minecraft.data.DataGenerator; import net.minecraft.data.DataProvider; import net.minecraft.util.GsonHelper; -import org.apache.commons.lang3.mutable.MutableBoolean; -import org.apache.commons.lang3.mutable.MutableInt; -import org.apache.commons.lang3.mutable.MutableObject; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.ApiStatus; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.*; -import java.util.Map.Entry; /* MIT License @@ -52,7 +65,8 @@ of this software and associated documentation files (the "Software"), to deal */ /** - * A useful {@link DataProvider} which can merge handwritten localization files and generated ones into one.
+ * A useful {@link DataProvider} which can merge handwritten localization files + * and generated ones into one.
* Originated from {@link com.simibubi.create.foundation.data.LangMerger}
*/ @SuppressWarnings("UnstableApiUsage") @@ -60,18 +74,18 @@ of this software and associated documentation files (the "Software"), to deal class LangMerger implements DataProvider { private static final Logger LOGGER = LogManager.getLogger(); private static final Gson GSON = new GsonBuilder() - .setPrettyPrinting() - .disableHtmlEscaping() - .create(); + .setPrettyPrinting() + .disableHtmlEscaping() + .create(); private static final String CATEGORY_HEADER = "\t\"_\": \"->------------------------] %s [------------------------<-\","; private final String modid; private final String name; - + private final List mergedLangData = new ArrayList<>(); private final Map> populatedLangData = new HashMap<>(); private final Map> allLocalizedEntries = new HashMap<>(); private final Map missingTranslationTally = new HashMap<>(); - + final List partials = new ArrayList<>(); DataGenerator dataGenerator; List ignore = new ArrayList<>(); @@ -89,44 +103,44 @@ public String getName() { @Override public void run(CachedOutput cache) throws IOException { Path path = this.dataGenerator.getOutputFolder() - .resolve("assets/" + modid + "/lang/" + "en_us.json"); - - for(Pair pair : getAllLocalizationFiles()) { - if(!pair.getRight().isJsonObject()) + .resolve("assets/" + modid + "/lang/" + "en_us.json"); + + for (Pair pair : getAllLocalizationFiles()) { + if (!pair.getRight().isJsonObject()) continue; Map localizedEntries = new HashMap<>(); JsonObject jsonObject = pair.getRight().getAsJsonObject(); jsonObject.entrySet() - .stream() - .forEachOrdered(entry -> { - String key = entry.getKey(); - if(key.startsWith("_")) - return; - String value = entry.getValue() - .getAsString(); - localizedEntries.put(key, value); - }); + .stream() + .forEachOrdered(entry -> { + String key = entry.getKey(); + if (key.startsWith("_")) + return; + String value = entry.getValue() + .getAsString(); + localizedEntries.put(key, value); + }); String key = pair.getKey(); allLocalizedEntries.put(key, localizedEntries); populatedLangData.put(key, new ArrayList<>()); missingTranslationTally.put(key, new MutableInt(0)); } - + collectExistingEntries(path); collectEntries(); - if(mergedLangData.isEmpty()) + if (mergedLangData.isEmpty()) return; - + save(cache, mergedLangData, -1, path, "Merging en_us.json with hand-written lang entries..."); - for(Entry> localization : populatedLangData.entrySet()) { + for (Entry> localization : populatedLangData.entrySet()) { String key = localization.getKey(); Path populatedLangPath = this.dataGenerator.getOutputFolder() - .resolve("assets/" + modid + "/lang/unfinished/" + key); + .resolve("assets/" + modid + "/lang/unfinished/" + key); save(cache, localization.getValue(), missingTranslationTally.get(key) - .intValue(), populatedLangPath, "Populating " + key + " with missing entries..."); + .intValue(), populatedLangPath, "Populating " + key + " with missing entries..."); } } - + private boolean shouldIgnore(String key) { for (String string : ignore) if (key.startsWith(string)) @@ -176,19 +190,19 @@ private void addAll(String header, JsonObject jsonObject) { MutableObject previousKey = new MutableObject<>(""); jsonObject.entrySet() - .stream() - .forEachOrdered(entry -> { - String key = entry.getKey(); - if (shouldIgnore(key)) - return; - String value = entry.getValue() - .getAsString(); - if (!previousKey.getValue() - .isEmpty() && shouldAddLineBreak(key, previousKey.getValue())) - writeData("\n"); - writeEntry(key, value); - previousKey.setValue(key); - }); + .stream() + .forEachOrdered(entry -> { + String key = entry.getKey(); + if (shouldIgnore(key)) + return; + String value = entry.getValue() + .getAsString(); + if (!previousKey.getValue() + .isEmpty() && shouldAddLineBreak(key, previousKey.getValue())) + writeData("\n"); + writeEntry(key, value); + previousKey.setValue(key); + }); writeData("\n"); } @@ -196,7 +210,7 @@ private void addAll(String header, JsonObject jsonObject) { private void writeData(String data) { mergedLangData.add(data); populatedLangData.values() - .forEach(l -> l.add(data)); + .forEach(l -> l.add(data)); } private void writeEntry(String key, String value) { @@ -205,7 +219,7 @@ private void writeEntry(String key, String value) { ForeignLangEntry entry = new ForeignLangEntry(key, value, allLocalizedEntries.get(k)); if (entry.isMissing()) missingTranslationTally.get(k) - .increment(); + .increment(); l.add(entry); }); } @@ -253,7 +267,7 @@ private List> getAllLocalizationFiles() { } private void collectEntries() { - for (LangPartial partial : partials){ + for (LangPartial partial : partials) { addAll(partial.getDisplay(), partial.provide().getAsJsonObject()); } } diff --git a/src/main/java/plus/dragons/createdragonlib/lang/LangPartial.java b/src/main/java/plus/dragons/createdragonlib/lang/LangPartial.java index 63bf804..bf7cb7f 100644 --- a/src/main/java/plus/dragons/createdragonlib/lang/LangPartial.java +++ b/src/main/java/plus/dragons/createdragonlib/lang/LangPartial.java @@ -1,11 +1,10 @@ package plus.dragons.createdragonlib.lang; +import java.util.function.Supplier; + import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.simibubi.create.foundation.utility.FilesHelper; -import org.jetbrains.annotations.ApiStatus; - -import java.util.function.Supplier; abstract class LangPartial { protected final String modid; diff --git a/src/main/java/plus/dragons/createdragonlib/mixin/CreateItemGroupBaseMixin.java b/src/main/java/plus/dragons/createdragonlib/mixin/CreateItemGroupBaseMixin.java index e8a8bfb..a13daef 100644 --- a/src/main/java/plus/dragons/createdragonlib/mixin/CreateItemGroupBaseMixin.java +++ b/src/main/java/plus/dragons/createdragonlib/mixin/CreateItemGroupBaseMixin.java @@ -1,13 +1,14 @@ package plus.dragons.createdragonlib.mixin; -import com.simibubi.create.foundation.item.CreateItemGroupBase; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.simibubi.create.foundation.item.CreateItemGroupBase; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; import plus.dragons.createdragonlib.init.FillCreateItemGroupEvent; @Mixin(CreateItemGroupBase.class) @@ -16,7 +17,7 @@ public class CreateItemGroupBaseMixin { @Inject(method = "fillItemList", at = @At("TAIL")) private void postFillCreateItemGroupEvent(NonNullList items, CallbackInfo ci) { var event = new FillCreateItemGroupEvent((CreateItemGroupBase) (Object) this, items); - MinecraftForge.EVENT_BUS.post(event); + FillCreateItemGroupEvent.INSTANCE.invoker().listen(event); event.apply(); } diff --git a/src/main/java/plus/dragons/createdragonlib/mixin/FluidReactionsMixin.java b/src/main/java/plus/dragons/createdragonlib/mixin/FluidReactionsMixin.java index 7257464..60c10bf 100644 --- a/src/main/java/plus/dragons/createdragonlib/mixin/FluidReactionsMixin.java +++ b/src/main/java/plus/dragons/createdragonlib/mixin/FluidReactionsMixin.java @@ -1,34 +1,38 @@ package plus.dragons.createdragonlib.mixin; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + import com.simibubi.create.content.contraptions.fluids.FluidReactions; import com.simibubi.create.foundation.advancement.AdvancementBehaviour; import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.utility.BlockHelper; + +import io.github.fabricators_of_create.porting_lib.util.FluidStack; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; -import net.minecraftforge.common.ForgeMod; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.world.level.material.Fluids; import plus.dragons.createdragonlib.fluid.FluidLavaReaction; @Mixin(value = FluidReactions.class, remap = false) public class FluidReactionsMixin { - + @Inject(method = "handlePipeFlowCollision", at = @At("HEAD"), cancellable = true) - private static void createDragonLib$handlePipeFlowCollision(Level world, BlockPos pos, FluidStack fluid, FluidStack fluid2, CallbackInfo ci) { - FluidType type = fluid.getFluid().getFluidType(); - FluidType type2 = fluid2.getFluid().getFluidType(); + private static void createDragonLib$handlePipeFlowCollision(Level world, BlockPos pos, FluidStack fluid, + FluidStack fluid2, CallbackInfo ci) { + FluidVariant type = fluid.getType(); + FluidVariant type2 = fluid2.getType(); FluidLavaReaction reaction = null; - if (type == ForgeMod.LAVA_TYPE.get()) + if (type.getFluid() == Fluids.LAVA) reaction = FluidLavaReaction.get(type2); - else if (type2 == ForgeMod.LAVA_TYPE.get()) + else if (type2.getFluid() == Fluids.LAVA) reaction = FluidLavaReaction.get(type); if (reaction != null) { AdvancementBehaviour.tryAward(world, pos, AllAdvancements.CROSS_STREAMS); @@ -37,23 +41,27 @@ else if (type2 == ForgeMod.LAVA_TYPE.get()) ci.cancel(); } } - + @Inject(method = "handlePipeSpillCollision", at = @At("HEAD"), cancellable = true) - private static void createDragonLib$handleSpillCollision(Level world, BlockPos pos, Fluid pipeFluid, FluidState worldFluid, CallbackInfo ci) { - FluidType typeP = pipeFluid.getFluidType(); - FluidType typeW = worldFluid.getFluidType(); + private static void createDragonLib$handleSpillCollision(Level world, BlockPos pos, Fluid pipeFluid, + FluidState worldFluid, CallbackInfo ci) { + FluidVariant typeP = FluidVariant.of(pipeFluid); + FluidVariant typeW = FluidVariant + .of(worldFluid.getType() instanceof FlowingFluid flow ? flow.getSource() : worldFluid.getType()); BlockState blockState = null; - if (typeW == ForgeMod.LAVA_TYPE.get()) { + if (typeW.getFluid() == Fluids.LAVA) { FluidLavaReaction reaction = FluidLavaReaction.get(typeP); - if (reaction != null) blockState = worldFluid.isSource() ? reaction.withLava() : reaction.withFlowingLava(); - } else if (typeP == ForgeMod.LAVA_TYPE.get()) { + if (reaction != null) + blockState = worldFluid.isSource() ? reaction.withLava() : reaction.withFlowingLava(); + } else if (typeP.getFluid() == Fluids.LAVA) { FluidLavaReaction reaction = FluidLavaReaction.get(typeW); - if (reaction != null) blockState = reaction.lavaOnSelf(); + if (reaction != null) + blockState = reaction.lavaOnSelf(); } if (blockState != null) { world.setBlockAndUpdate(pos, blockState); ci.cancel(); } } - + } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml deleted file mode 100644 index a67df7a..0000000 --- a/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,36 +0,0 @@ -modLoader="javafml" -loaderVersion="[43,)" -license="MIT" - -[[mods]] -modId="create_dragon_lib" -version="${file.jarVersion}" -displayName="Create: Dragon Lib" -#updateJSONURL="https://change.me.example.invalid/updates.json" -#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" -#logoFile="examplemod.png" -#credits="Thanks for this example mod goes to Java" -authors="LimonBlaze & MarbleGateKeeper" -description=''' -A library for Create addons. -''' - -[[dependencies.create_dragon_lib]] - modId="forge" - mandatory=true - versionRange="[43,)" - ordering="NONE" - side="BOTH" - -[[dependencies.create_dragon_lib]] - modId="minecraft" - mandatory=true - versionRange="[1.19.2,1.20)" - ordering="NONE" - side="BOTH" -[[dependencies.create_dragon_lib]] - modId="create" - mandatory=true - versionRange="[0.5.0.f,)" - ordering="NONE" - side="BOTH" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..a5131d3 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,24 @@ +{ + "schemaVersion": 1, + "id": "create_dragon_lib", + "version": "${version}", + "name": "Create: Dragon Lib", + "description": "A library for Create addons.", + "authors": ["LimonBlaze", "MarbleGateKeeper"], + "license": "MIT", + "environment": "*", + "entrypoints": { + "main": ["plus.dragons.createdragonlib.DragonLib"] + }, + "mixins": ["create_dragon_lib.mixins.json"], + "depends": { + "fabricloader": ">=0.14.6", + "fabric": "*", + "minecraft": "~1.19.2", + "java": ">=17", + "create": "*" + }, + "suggests": { + "quilt_loader": "*" + } +} diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta deleted file mode 100644 index 1be1907..0000000 --- a/src/main/resources/pack.mcmeta +++ /dev/null @@ -1,8 +0,0 @@ -{ - "pack": { - "description": "create_dragon_lib resources", - "pack_format": 9, - "forge:resource_pack_format": 9, - "forge:data_pack_format": 10 - } -}