Skip to content

Commit

Permalink
Update to 1.20.6 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli authored Jul 30, 2024
1 parent d33925d commit 3465815
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 183 deletions.
17 changes: 12 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import com.github.minecraftschurlimods.helperplugin.version

plugins {
idea
id("net.neoforged.gradle.userdev")
id ("com.github.minecraftschurlimods.helperplugin")
}

helper.withTestSourceSet()

repositories {
maven {
name = "blamejared Maven"
Expand All @@ -14,21 +19,23 @@ repositories {
}
}

val jei = helper.dependencies.jei()

dependencies {
implementation(helper.neoforge())
compileOnly("mezz.jei:jei-1.20.4-common-api:${project.properties["dependency.jei.version"]}")
runtimeOnly("mezz.jei:jei-1.20.4-neoforge:${project.properties["dependency.jei.version"]}")
val jeiApiDep = helper.minecraftVersion.zip(jei.version) { mc, version -> "mezz.jei:jei-${mc}-common-api:${version}" }
val jeiDep = helper.minecraftVersion.zip(jei.version) { mc, version -> "mezz.jei:jei-${mc}-neoforge:${version}" }
compileOnly(jeiApiDep)
runtimeOnly(jeiDep)
implementation("org.jetbrains:annotations:23.0.0")
"testCompileOnly"("org.jetbrains:annotations:23.0.0")
}

helper.withTestSourceSet()
helper.withCommonRuns()
helper.withGameTestRuns()
helper.modproperties.put(
"catalogueItemIcon", helper.projectId.map { "$it:potion_bundle{Potion:\"minecraft:water\"}" }
"catalogueItemIcon", helper.projectId.map { "$it:potion_bundle[minecraft:potion_contents=\"minecraft:water\"]" }
)
helper.dependencies.jei()

helper.publication.pom {
organization {
Expand Down
3 changes: 1 addition & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Changes
- Fixed a rare compatibility issue
# Updated to 1.20.6
22 changes: 12 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.caching=true

neogradle.subsystems.conventions.runs.create-default-run-per-type=false

mod.group=com.github.minecraftschurlimods
mod.id=potionbundles
mod.version=1.8
Expand All @@ -12,7 +14,7 @@ mod.authors=IchHabeHunger54, Minecraftschurli
mod.description=Potions can now be bound into bundles, to save inventory space.
mod.url=https://www.curseforge.com/minecraft/mc-mods/potion-bundles

java_version=17
java_version=21

github.owner=MinecraftschurliMods
github.repo=PotionBundles
Expand All @@ -21,19 +23,19 @@ license.name=GPLv3
license.url=https://www.gnu.org/licenses/gpl-3.0.en.html
license.file=LICENSE

neogradle.subsystems.parchment.minecraftVersion=1.20.3
neogradle.subsystems.parchment.mappingsVersion=2023.12.31
neogradle.subsystems.parchment.minecraftVersion=1.20.6
neogradle.subsystems.parchment.mappingsVersion=2024.06.16

mc_version=1.20.4
mc_version_range=[1.20.4,1.20.5)
mc_version=1.20.6
mc_version_range=[1.20.6,1.21)

neo_version=20.4.80-beta
neo_version_range=[20.4.80-beta,20.5)
neo_version=20.6.119
neo_version_range=[20.6.115,21)

dependency.jei.version=17.3.0.49
dependency.jei.version.range=[17.3,18)
dependency.jei.version=18.0.0.65
dependency.jei.version.range=[18,19)

loader.version=[1,)
loader.version=[3,)

mc-publish.curseforge=382836
mc-publish.modrinth=ZZLWU8jS
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pluginManagement {
plugins {
id("net.neoforged.gradle.userdev") version "7.0.80"
id("com.github.minecraftschurlimods.helperplugin") version "1.7"
id("net.neoforged.gradle.userdev") version "7.0.154"
id("com.github.minecraftschurlimods.helperplugin") version "1.14"
}
repositories {
mavenLocal()
Expand All @@ -12,7 +12,7 @@ pluginManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}

rootProject.name = "PotionBundles"
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package com.github.minecraftschurlimods.potionbundles;

import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.PotionItem;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.alchemy.PotionContents;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.List;
import java.util.Optional;

public abstract class AbstractPotionBundle extends PotionItem {
public AbstractPotionBundle() {
super(new Item.Properties().stacksTo(1));
}

@Override
public ItemStack getDefaultInstance() {
ItemStack itemstack = super.getDefaultInstance();
itemstack.set(PotionBundles.USES, getMaxUses());
return itemstack;
}

@VisibleForTesting
public int getMaxUses() {
return PotionBundles.POTION_BUNDLE_SIZE;
Expand All @@ -32,7 +40,7 @@ public int getBarWidth(ItemStack stack) {
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag flag) {
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(Component.translatable(getDescriptionId() + ".uses", PotionBundleUtils.getUses(stack)));
}

Expand All @@ -48,15 +56,18 @@ public boolean isBarVisible(ItemStack stack) {

@Override
public Component getName(ItemStack stack) {
return Component.translatable(getDescriptionId(), Items.POTION.getName(stack));
return Component.translatable(getDescriptionId(), PotionBundleUtils.getPotionForBundle(this).getName(stack));
}

@VisibleForTesting
public ItemStack createStack(@Nullable PotionBundleString string, Holder<Potion> potion, List<MobEffectInstance> customEffects, @Nullable Integer customColor) {
return createStack(string, new PotionContents(Optional.of(potion), Optional.ofNullable(customColor), customEffects));
}

@VisibleForTesting
public ItemStack createStack(ItemStack string, Potion potion, List<MobEffectInstance> customEffects, @Nullable Integer customColor) {
public ItemStack createStack(@Nullable PotionBundleString string, PotionContents potionContents) {
ItemStack stack = new ItemStack(this);
PotionUtils.setPotion(stack, potion);
PotionUtils.setCustomEffects(stack, customEffects);
if (customColor != null) stack.getOrCreateTag().putInt("CustomPotionColor", customColor);
stack.set(DataComponents.POTION_CONTENTS, potionContents);
PotionBundleUtils.setUses(stack, getMaxUses());
PotionBundleUtils.setString(stack, string);
return stack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.minecraftschurlimods.potionbundles;

import net.minecraft.core.component.DataComponents;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.level.Level;

public abstract class AbstractThrowablePotionBundle extends AbstractPotionBundle {
Expand All @@ -16,17 +16,20 @@ public InteractionResultHolder<ItemStack> use(Level world, Player player, Intera
playThrowSound(world, player);
if (!world.isClientSide) {
ThrownPotion thrownpotion = new ThrownPotion(world, player);
ItemStack fake = new ItemStack(PotionBundleUtils.getPotionForBundle(world, this));
PotionUtils.setPotion(fake, PotionUtils.getPotion(itemstack));
PotionUtils.setCustomEffects(fake, PotionUtils.getCustomEffects(itemstack));
ItemStack fake = new ItemStack(PotionBundleUtils.getPotionForBundle(this));
fake.set(DataComponents.POTION_CONTENTS, itemstack.get(DataComponents.POTION_CONTENTS));
thrownpotion.setItem(fake);
thrownpotion.shootFromRotation(player, player.getXRot(), player.getYRot(), -20F, 0.5F, 1F);
thrownpotion.shootFromRotation(player, player.getXRot(), player.getYRot(), -20.0F, 0.5F, 1.0F);
world.addFreshEntity(thrownpotion);
}
PotionBundleUtils.decrementUses(itemstack);
if (!player.hasInfiniteMaterials()) {
PotionBundleUtils.decrementUses(itemstack);
}
player.awardStat(Stats.ITEM_USED.get(this));
if (PotionBundleUtils.getUses(itemstack) == 0) itemstack = Config.SERVER.returnString.get() ? PotionBundleUtils.getString(itemstack) : ItemStack.EMPTY;
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
if (PotionBundleUtils.getUses(itemstack) != 0) {
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
return InteractionResultHolder.sidedSuccess(Config.SERVER.returnString.get() ? PotionBundleUtils.getString(itemstack) : ItemStack.EMPTY, world.isClientSide());
}

protected abstract void playThrowSound(Level world, Player player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.client.renderer.item.ItemPropertyFunction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.alchemy.PotionContents;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.registries.DeferredHolder;

@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD, modid = PotionBundles.MODID)
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD, modid = PotionBundles.MODID)
public class ClientHandler {
@SubscribeEvent
public static void clientSetup(FMLClientSetupEvent e) {
e.enqueueWork(() -> {
@SuppressWarnings("deprecation")
ItemPropertyFunction propertyFunction = (stack, world, living, seed) -> !stack.hasTag() || !stack.getOrCreateTag().contains(PotionBundleUtils.USES_KEY) ? 0 : PotionBundleUtils.getUses(stack);
ItemPropertyFunction propertyFunction = (stack, world, living, seed) -> stack.getOrDefault(PotionBundles.USES, 0);
ResourceLocation uses = new ResourceLocation(PotionBundles.MODID, "uses");
for (DeferredHolder<Item, ?> item : PotionBundles.ITEMS.getEntries()) {
ItemProperties.register(item.get(), uses, propertyFunction);
Expand All @@ -28,6 +29,6 @@ public static void clientSetup(FMLClientSetupEvent e) {

@SubscribeEvent
public static void registerItemColorHandler(RegisterColorHandlersEvent.Item e) {
e.register((stack, index) -> index > 0 ? -1 : PotionUtils.getColor(stack), PotionBundles.ITEMS.getEntries().stream().map(DeferredHolder::get).toArray(Item[]::new));
e.register((stack, index) -> index > 0 ? -1 : stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).getColor(), PotionBundles.ITEMS.getEntries().stream().map(DeferredHolder::get).toArray(Item[]::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
import mezz.jei.api.registration.ISubtypeRegistration;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import net.neoforged.neoforge.common.crafting.DataComponentIngredient;

import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;

@JeiPlugin
Expand All @@ -38,35 +50,38 @@ public void registerRecipes(final IRecipeRegistration registration) {
.map(RecipeHolder::value)
.filter(PotionBundleRecipe.class::isInstance)
.map(PotionBundleRecipe.class::cast)
.flatMap(this::mapRecipes)
.flatMap(recipe -> mapRecipes(recipe, level.registryAccess()))
.toList();
registration.addRecipes(RecipeTypes.CRAFTING, recipes);
}

private Stream<RecipeHolder<CraftingRecipe>> mapRecipes(final PotionBundleRecipe recipe) {
private Stream<RecipeHolder<CraftingRecipe>> mapRecipes(final PotionBundleRecipe recipe, HolderLookup.Provider registries) {
String group = "jei.potionbundle";
AbstractPotionBundle bundleItem = recipe.getBundleItem();
int maxUses = bundleItem.getMaxUses();
Item potionItem = recipe.getPotionItem();
return BuiltInRegistries.POTION
return registries
.lookup(Registries.POTION)
.stream()
.flatMap(HolderLookup::listElements)
.map(potion -> {
Ingredient potionIngredient = Ingredient.of(PotionUtils.setPotion(new ItemStack(potionItem), potion));
PotionContents potionContents = new PotionContents(potion);
Ingredient potionIngredient = DataComponentIngredient.of(false, DataComponents.POTION_CONTENTS, potionContents, potionItem);
NonNullList<Ingredient> inputs = NonNullList.withSize(maxUses + 1, Ingredient.EMPTY);
for (int i = 0; i < maxUses; i++) {
inputs.set(i, potionIngredient);
}
inputs.set(maxUses, recipe.getString());
ItemStack output = PotionUtils.setPotion(new ItemStack(bundleItem), potion);
ItemStack output = PotionContents.createItemStack(bundleItem, potion);
PotionBundleUtils.setUses(output, maxUses);
ResourceLocation id = new ResourceLocation(ModIds.MINECRAFT_ID, group + "." + output.getDescriptionId() + "." + potion.getName(""));
ResourceLocation id = new ResourceLocation(ModIds.MINECRAFT_ID, group + "." + output.getDescriptionId() + "." + Potion.getName(Optional.of(potion), ""));
return new RecipeHolder<>(id, new ShapelessRecipe(group, CraftingBookCategory.EQUIPMENT, output, inputs));
});
}

@Override
public void registerItemSubtypes(ISubtypeRegistration r) {
IIngredientSubtypeInterpreter<ItemStack> byPotion = (ingredient, context) -> String.valueOf(BuiltInRegistries.POTION.getKey(PotionUtils.getPotion(ingredient)));
IIngredientSubtypeInterpreter<ItemStack> byPotion = (ingredient, context) -> ingredient.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion().map(Holder::getRegisteredName).orElse("unknown");
r.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, PotionBundles.POTION_BUNDLE.get(), byPotion);
r.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, PotionBundles.SPLASH_POTION_BUNDLE.get(), byPotion);
r.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, PotionBundles.LINGERING_POTION_BUNDLE.get(), byPotion);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.github.minecraftschurlimods.potionbundles;

import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class LingeringPotionBundle extends AbstractThrowablePotionBundle {
@Override
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag flag) {
PotionUtils.addPotionTooltip(stack, tooltip, 0.25F, world == null ? 20.0F : world.tickRateManager().tickrate());
super.appendHoverText(stack, world, tooltip, flag);
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltip, TooltipFlag flag) {
stack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).addPotionTooltip(tooltip::add, 0.25F, context.tickRate());
super.appendHoverText(stack, context, tooltip, flag);
}

@Override
Expand Down
Loading

0 comments on commit 3465815

Please sign in to comment.