Skip to content

Commit

Permalink
Add Potion of Small recipe, fix custom containers
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-makes committed Jun 22, 2024
1 parent 5f96e66 commit 2764367
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/main/java/dev/schmarrn/BeegSmol.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.schmarrn;

import dev.schmarrn.brewing.CustomBrewingRecipes;
import dev.schmarrn.components.MyComponents;
import dev.schmarrn.items.MyItems;
import net.fabricmc.api.ModInitializer;
Expand All @@ -21,6 +22,8 @@ public void onInitialize() {
MyMobEffects.init();
MyComponents.init();

CustomBrewingRecipes.init();

MyItems.init();
}
}
6 changes: 5 additions & 1 deletion src/main/java/dev/schmarrn/MyMobEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public class MyMobEffects {
public static final Holder<MobEffect> BEEG = Registry.registerForHolder(BuiltInRegistries.MOB_EFFECT, BeegSmol.rl("beeg"), new MyMobEffect(MobEffectCategory.NEUTRAL, 0xFF00FF).addAttributeModifier(Attributes.SCALE, BeegSmol.rl("effect.beeg"), 0.5, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
public static final Holder<MobEffect> SMOL = Registry.registerForHolder(BuiltInRegistries.MOB_EFFECT, BeegSmol.rl("smol"), new MyMobEffect(MobEffectCategory.NEUTRAL, 0xFF00FF).addAttributeModifier(Attributes.SCALE, BeegSmol.rl("effect.smol"), -0.5, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));

public static MobEffectInstance getMobEffectInstance(Holder<MobEffect> effect, int amplifier) {
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;
boolean ambient = false;
boolean visible = false;
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/dev/schmarrn/brewing/CustomBrewingRecipes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.schmarrn.brewing;

import dev.schmarrn.MyMobEffects;
import dev.schmarrn.components.MobEffectInstancesComponent;
import dev.schmarrn.components.MyComponents;
import dev.schmarrn.items.Vial;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
Expand All @@ -18,6 +20,7 @@ public class CustomBrewingRecipes {
public static final List<IBrewingRecipe> RECIPES = new ArrayList<>();

static {
// Potion of Beeg
register(new IBrewingRecipe() {
@Override
public boolean isBase(ItemStack base) {
Expand All @@ -32,7 +35,26 @@ public boolean isIngredient(ItemStack itemStack) {

@Override
public ItemStack getOutput(ItemStack base, ItemStack ingredient) {
return Vial.getWithEffect(MyMobEffects.getMobEffectInstance(MyMobEffects.BEEG, 0));
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);
}

@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);
}
});
}
Expand All @@ -59,4 +81,8 @@ public static boolean isBasis(ItemStack stack) {
private static void register(IBrewingRecipe recipe) {
RECIPES.add(recipe);
}

public static void init() {
// no-op
}
}
2 changes: 1 addition & 1 deletion src/main/java/dev/schmarrn/brewing/IBrewingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Inspired by neoforge: https://github.com/neoforged/NeoForge/blob/f923568cc0595b90034739ecc96af367ecacbdd5/src/main/java/net/neoforged/neoforge/common/brewing/IBrewingRecipe.java
*/
public interface IBrewingRecipe {
boolean isBase(ItemStack itemStack);
boolean isBase(ItemStack base);
boolean isIngredient(ItemStack itemStack);
ItemStack getOutput(ItemStack base, ItemStack ingredient);
}
2 changes: 1 addition & 1 deletion src/main/java/dev/schmarrn/items/MyItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.world.item.Item;

public class MyItems {
public static final Item POTION = Registry.register(BuiltInRegistries.ITEM, BeegSmol.rl("vial"), new Vial(new Item.Properties()));
public static final Item POTION = Registry.register(BuiltInRegistries.ITEM, BeegSmol.rl("vial"), new Vial(new Item.Properties().stacksTo(1)));

public static void init() {
// no-op
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/dev/schmarrn/mixin/BrewingStandBlockEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.schmarrn.mixin;

import dev.schmarrn.BeegSmol;
import dev.schmarrn.brewing.CustomBrewingRecipes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
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.CallbackInfoReturnable;

@Mixin(BrewingStandBlockEntity.class)
public class BrewingStandBlockEntityMixin {
@Inject(
method = "canPlaceItem",
at = @At(value="HEAD"),
cancellable = true
)
private void bs$canPlaceItem(int i, ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
BeegSmol.LOGGER.info("Is basis? {}, {}", stack, CustomBrewingRecipes.isBasis(stack));

if (i != 3 && i != 4 && CustomBrewingRecipes.isBasis(stack)) {
cir.setReturnValue(true);
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/dev/schmarrn/mixin/BrewingStandMenuMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.schmarrn.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.schmarrn.brewing.CustomBrewingRecipes;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(targets = "net.minecraft.world.inventory.BrewingStandMenu$PotionSlot")
public class BrewingStandMenuMixin {
@ModifyReturnValue(
method = "mayPlaceItem",
at = @At("RETURN")
)
private static boolean bs$mayPlaceItem(boolean original, ItemStack stack) {
return original || CustomBrewingRecipes.isBasis(stack);
}
}
14 changes: 8 additions & 6 deletions src/main/java/dev/schmarrn/mixin/PotionBrewingMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

import dev.schmarrn.brewing.IBrewingRecipe;
import dev.schmarrn.brewing.CustomBrewingRecipes;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.alchemy.PotionContents;

import java.util.Optional;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -26,6 +20,14 @@ public class PotionBrewingMixin {
return original || CustomBrewingRecipes.isIngredient(ingredient);
}

@ModifyReturnValue(
method = "isContainer",
at = @At("RETURN")
)
private boolean bs$isContainer(boolean original, ItemStack ingredient) {
return original || CustomBrewingRecipes.isBasis(ingredient);
}

@ModifyReturnValue(
method = "hasPotionMix",
at = @At("RETURN")
Expand Down
18 changes: 10 additions & 8 deletions src/main/resources/beeg-smol.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"required": true,
"package": "dev.schmarrn.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"PotionBrewingMixin"
],
"injectors": {
"defaultRequire": 1
"required": true,
"package": "dev.schmarrn.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"BrewingStandBlockEntityMixin",
"BrewingStandMenuMixin",
"PotionBrewingMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 2764367

Please sign in to comment.