Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EMI compat and add vials to the Food and Drinks tab #1

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ maven_group=dev.schmarrn
archives_base_name=beeg-smol

# Dependencies
fabric_version=0.100.1+1.21
fabric_version=0.100.1+1.21

emi_version=1.1.8+1.21
184 changes: 92 additions & 92 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion src/main/java/dev/schmarrn/MyMobEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MobEffect> effect, int amplifier) {
int duration = -1;
Expand Down
70 changes: 35 additions & 35 deletions src/main/java/dev/schmarrn/brewing/CustomBrewingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,45 +18,46 @@

public class CustomBrewingRecipes {
public static final List<IBrewingRecipe> RECIPES = new ArrayList<>();
public static final IBrewingRecipe BEEG = new IBrewingRecipe() {
@Override
public boolean isBase(ItemStack base) {
Optional<Holder<Potion>> 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<Holder<Potion>> 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) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/dev/schmarrn/compat/BeegSmolEMIPlugin.java
Original file line number Diff line number Diff line change
@@ -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")));
}
}
8 changes: 8 additions & 0 deletions src/main/java/dev/schmarrn/items/MyItems.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
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 {
public static final Item VIAL = Registry.register(BuiltInRegistries.ITEM, BeegSmol.rl("vial"), new Vial(new Item.Properties().stacksTo(1)));

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));
});
}
}
Loading