From f70072860ee60896263fdd15a9caa171b2994929 Mon Sep 17 00:00:00 2001 From: SkyNotTheLimit <159592458+ekulxam@users.noreply.github.com> Date: Sun, 30 Jun 2024 15:07:35 -0700 Subject: [PATCH 1/2] Add EMI compat What am I even doing --- src/main/java/dev/schmarrn/MyMobEffects.java | 1 - .../brewing/CustomBrewingRecipes.java | 70 +++++++++---------- .../schmarrn/compat/BeegSmolEMIPlugin.java | 29 ++++++++ src/main/java/dev/schmarrn/items/MyItems.java | 8 +++ src/main/java/dev/schmarrn/items/Vial.java | 21 ++++-- src/main/resources/fabric.mod.json | 3 + 6 files changed, 89 insertions(+), 43 deletions(-) create mode 100644 src/main/java/dev/schmarrn/compat/BeegSmolEMIPlugin.java diff --git a/src/main/java/dev/schmarrn/MyMobEffects.java b/src/main/java/dev/schmarrn/MyMobEffects.java index fefa01a..43a47cf 100644 --- a/src/main/java/dev/schmarrn/MyMobEffects.java +++ b/src/main/java/dev/schmarrn/MyMobEffects.java @@ -15,7 +15,6 @@ public class MyMobEffects { public static final MobEffectInstance BIG_INSTANCE = getMobEffectInstance(BEEG, 0); public static final MobEffectInstance SMALL_INSTANCE = getMobEffectInstance(SMOL, 0); - public static final MobEffectInstance SMOL_INSTANCE = getMobEffectInstance(SMOL, 1); private static MobEffectInstance getMobEffectInstance(Holder effect, int amplifier) { int duration = -1; diff --git a/src/main/java/dev/schmarrn/brewing/CustomBrewingRecipes.java b/src/main/java/dev/schmarrn/brewing/CustomBrewingRecipes.java index 872928d..b91c437 100644 --- a/src/main/java/dev/schmarrn/brewing/CustomBrewingRecipes.java +++ b/src/main/java/dev/schmarrn/brewing/CustomBrewingRecipes.java @@ -6,7 +6,6 @@ import dev.schmarrn.items.Vial; import net.minecraft.core.Holder; import net.minecraft.core.component.DataComponents; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.Potion; @@ -19,45 +18,46 @@ public class CustomBrewingRecipes { public static final List RECIPES = new ArrayList<>(); + public static final IBrewingRecipe BEEG = new IBrewingRecipe() { + @Override + public boolean isBase(ItemStack base) { + Optional> basePotion = base.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion(); + return basePotion.filter(Potions.THICK::is).isPresent(); + } - static { - // Potion of Beeg - register(new IBrewingRecipe() { - @Override - public boolean isBase(ItemStack base) { - Optional> basePotion = base.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion(); - return basePotion.filter(Potions.THICK::is).isPresent(); - } + @Override + public boolean isIngredient(ItemStack itemStack) { + return itemStack.is(Items.RED_MUSHROOM); + } - @Override - public boolean isIngredient(ItemStack itemStack) { - return itemStack.is(Items.RED_MUSHROOM); - } + @Override + public ItemStack getOutput(ItemStack base, ItemStack ingredient) { + return Vial.getWithEffect(MyMobEffects.BIG_INSTANCE); + } + }; - @Override - public ItemStack getOutput(ItemStack base, ItemStack ingredient) { - return Vial.getWithEffect(MyMobEffects.BIG_INSTANCE); - } - }); - - // Potion of small - register(new IBrewingRecipe() { - @Override - public boolean isBase(ItemStack base) { - var mobEffects = base.getOrDefault(MyComponents.MOB_EFFECTS, MobEffectInstancesComponent.EMPTY).effectInstances(); - return mobEffects.size() == 1 && mobEffects.getFirst().equals(MyMobEffects.BIG_INSTANCE); - } + public static final IBrewingRecipe SMOL = new IBrewingRecipe() { + @Override + public boolean isBase(ItemStack base) { + var mobEffects = base.getOrDefault(MyComponents.MOB_EFFECTS, MobEffectInstancesComponent.EMPTY).effectInstances(); + return mobEffects.size() == 1 && mobEffects.getFirst().equals(MyMobEffects.BIG_INSTANCE); + } - @Override - public boolean isIngredient(ItemStack itemStack) { - return itemStack.is(Items.FERMENTED_SPIDER_EYE); - } + @Override + public boolean isIngredient(ItemStack itemStack) { + return itemStack.is(Items.FERMENTED_SPIDER_EYE); + } - @Override - public ItemStack getOutput(ItemStack base, ItemStack ingredient) { - return Vial.getWithEffect(MyMobEffects.SMALL_INSTANCE); - } - }); + @Override + public ItemStack getOutput(ItemStack base, ItemStack ingredient) { + return Vial.getWithEffect(MyMobEffects.SMALL_INSTANCE); + } + }; + + + static { + register(BEEG); + register(SMOL); } public static boolean isRecipe(ItemStack base, ItemStack ingredient) { diff --git a/src/main/java/dev/schmarrn/compat/BeegSmolEMIPlugin.java b/src/main/java/dev/schmarrn/compat/BeegSmolEMIPlugin.java new file mode 100644 index 0000000..ee4ef22 --- /dev/null +++ b/src/main/java/dev/schmarrn/compat/BeegSmolEMIPlugin.java @@ -0,0 +1,29 @@ +package dev.schmarrn.compat; + +import dev.emi.emi.api.EmiPlugin; +import dev.emi.emi.api.EmiRegistry; +import dev.emi.emi.api.stack.EmiIngredient; +import dev.emi.emi.api.stack.EmiStack; +import dev.emi.emi.recipe.EmiBrewingRecipe; +import dev.schmarrn.BeegSmol; +import dev.schmarrn.MyMobEffects; +import dev.schmarrn.items.Vial; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.alchemy.PotionContents; +import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.item.crafting.Ingredient; + +import java.util.List; +import java.util.Optional; + +public class BeegSmolEMIPlugin implements EmiPlugin { + @Override + public void register(EmiRegistry registry) { + ItemStack thickPotionStack = Items.POTION.getDefaultInstance(); + thickPotionStack.set(DataComponents.POTION_CONTENTS, new PotionContents(Optional.of(Potions.THICK), Optional.empty(), List.of())); + registry.addRecipe(new EmiBrewingRecipe(EmiStack.of(thickPotionStack), EmiIngredient.of(Ingredient.of(Items.RED_MUSHROOM)), EmiStack.of(Vial.getWithEffect(MyMobEffects.BIG_INSTANCE)), BeegSmol.rl("beeg_vial_brewing_recipe"))); + registry.addRecipe(new EmiBrewingRecipe(EmiStack.of(Vial.getWithEffect(MyMobEffects.BIG_INSTANCE)), EmiIngredient.of(Ingredient.of(Items.FERMENTED_SPIDER_EYE)), EmiStack.of(Vial.getWithEffect(MyMobEffects.SMALL_INSTANCE)), BeegSmol.rl("smol_vial_brewing_recipe"))); + } +} diff --git a/src/main/java/dev/schmarrn/items/MyItems.java b/src/main/java/dev/schmarrn/items/MyItems.java index cd26ee1..31184d3 100644 --- a/src/main/java/dev/schmarrn/items/MyItems.java +++ b/src/main/java/dev/schmarrn/items/MyItems.java @@ -1,8 +1,12 @@ package dev.schmarrn.items; import dev.schmarrn.BeegSmol; +import dev.schmarrn.MyMobEffects; +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; public class MyItems { @@ -10,5 +14,9 @@ public class MyItems { public static void init() { // no-op + ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.FOOD_AND_DRINKS).register(entries -> { + entries.accept(Vial.getWithEffect(MyMobEffects.BIG_INSTANCE)); + entries.accept(Vial.getWithEffect(MyMobEffects.SMALL_INSTANCE)); + }); } } diff --git a/src/main/java/dev/schmarrn/items/Vial.java b/src/main/java/dev/schmarrn/items/Vial.java index b4ea41a..76b7ce8 100644 --- a/src/main/java/dev/schmarrn/items/Vial.java +++ b/src/main/java/dev/schmarrn/items/Vial.java @@ -4,7 +4,7 @@ import dev.schmarrn.components.MyComponents; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.stats.Stats; import net.minecraft.world.InteractionHand; @@ -17,7 +17,6 @@ import net.minecraft.world.level.gameevent.GameEvent; import org.jetbrains.annotations.NotNull; -import java.util.Arrays; import java.util.List; public class Vial extends Item { @@ -88,12 +87,20 @@ public int getUseDuration(ItemStack itemStack, LivingEntity livingEntity) { } @Override - public String getDescriptionId(ItemStack itemStack) { - String effect = BuiltInRegistries.MOB_EFFECT.getKey(itemStack.getOrDefault(MyComponents.MOB_EFFECTS, MobEffectInstancesComponent.EMPTY) - .effectInstances() + public @NotNull String getDescriptionId(ItemStack itemStack) { + String descriptionId = this.getDescriptionId(); + List mobEffectInstances = itemStack.getOrDefault(MyComponents.MOB_EFFECTS, MobEffectInstancesComponent.EMPTY).effectInstances(); + if (mobEffectInstances.isEmpty()) { + return descriptionId; + } + ResourceLocation location = BuiltInRegistries.MOB_EFFECT.getKey(mobEffectInstances .getFirst() .getEffect() - .value()).getPath(); - return this.getDescriptionId() + ".effect." + effect; + .value()); + if (location == null) { + return descriptionId; + } + String effect = location.getPath(); + return descriptionId + ".effect." + effect; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f0f28f5..1f5249f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,6 +19,9 @@ ], "client": [ "dev.schmarrn.BeegSmolClient" + ], + "emi": [ + "dev.schmarrn.compat.BeegSmolEMIPlugin" ] }, "mixins": [ From fdab9bd6c2424d20bdd2b0a88b70a0931b48686d Mon Sep 17 00:00:00 2001 From: SkyNotTheLimit <159592458+ekulxam@users.noreply.github.com> Date: Sun, 30 Jun 2024 15:08:51 -0700 Subject: [PATCH 2/2] GRADLE --- build.gradle | 8 +- gradle.properties | 4 +- gradlew.bat | 184 +++++++++++++++++++++++----------------------- 3 files changed, 102 insertions(+), 94 deletions(-) diff --git a/build.gradle b/build.gradle index 8cbd3c3..22e6d76 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,10 @@ repositories { // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. + maven { + name "terraformersmc" + url "https://maven.terraformersmc.com" + } } loom { @@ -38,7 +42,9 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - + + modCompileOnly "dev.emi:emi-fabric:${project.emi_version}" + modRuntimeOnly "dev.emi:emi-fabric:${project.emi_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 279a50e..7054c7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,4 +13,6 @@ maven_group=dev.schmarrn archives_base_name=beeg-smol # Dependencies -fabric_version=0.100.1+1.21 \ No newline at end of file +fabric_version=0.100.1+1.21 + +emi_version=1.1.8+1.21 \ No newline at end of file diff --git a/gradlew.bat b/gradlew.bat index 25da30d..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega