Skip to content

Commit

Permalink
fixed: lava bucket did not serve as fuel in furnace (only Fabric) #49 c…
Browse files Browse the repository at this point in the history
  • Loading branch information
cech12 committed Sep 29, 2024
1 parent 6538719 commit de926dc
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Forge Recommended Versioning](https://mcforge.readthedocs.io/en/latest/conventions/versioning/).

## [1.20.4-3.2.1.6] - 2024-09-29
### Fixed
- lava bucket did not serve as fuel in furnace (Fabric & Forge) (thanks to memoharos and AvaAsUsual for the report) #49 https://github.com/cech12/CeramicBucket/issues/83

## [1.20.4-3.2.1.5] - 2024-09-07
### Fixed
- buckets could not be stacked after holding fish or axolotl (thanks to Sinhika & Blazified for the report) #46
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraft.world.item.MobBucketItem;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -169,6 +170,18 @@ public int getMaxStackSize(ItemStack stack) {
return BucketLibUtil.isEmpty(stack) ? this.properties.maxStackSize : 1;
}

//used by mixins
public int getBucketBurnTime(ItemStack stack, RecipeType<?> recipeType) {
//entity buckets should not use the burn time of its fluid
if (stack.getItem() instanceof UniversalBucketItem && !BucketLibUtil.containsEntityType(stack)) {
Fluid fluid = Services.FLUID.getContainedFluid(stack);
if (fluid != Fluids.EMPTY) {
return Services.PLATFORM.getBurnTime(new ItemStack(fluid.getBucket()), recipeType);
}
}
return 0; //don't call Services.PLATFORM.getBurnTime() to avoid recursive calls
}

@Override
public void inventoryTick(@Nonnull ItemStack itemStack, @Nonnull Level level, @Nonnull Entity entity, int position, boolean selected) {
if (!level.isClientSide) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;

/**
Expand Down Expand Up @@ -61,4 +63,11 @@ default String getEnvironmentName() {
*/
String getMilkTranslationKey();

/**
* Gets the burn time of an ItemStack.
*
* @return burn time of an ItemStack
*/
int getBurnTime(ItemStack stack, RecipeType<?> recipeType);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.cech12.bucketlib.mixin;

import de.cech12.bucketlib.api.item.UniversalBucketItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
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({AbstractFurnaceBlockEntity.class})
public abstract class AbstractFurnaceBlockEntityMixin {

@Inject(method = "getBurnDuration", at = @At("RETURN"), cancellable = true)
private void getBurnDurationProxy(ItemStack itemStack, CallbackInfoReturnable<Integer> cir) {
if (cir.getReturnValue() <= 0 && itemStack.getItem() instanceof UniversalBucketItem universalBucketItem) {
cir.setReturnValue(universalBucketItem.getBucketBurnTime(itemStack, null));
}
}

@Inject(method = "isFuel", at = @At("RETURN"), cancellable = true)
private static void isFuelProxy(ItemStack itemStack, CallbackInfoReturnable<Boolean> cir) {
if (!cir.getReturnValue() && itemStack.getItem() instanceof UniversalBucketItem universalBucketItem) {
cir.setReturnValue(universalBucketItem.getBucketBurnTime(itemStack, null) > 0);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;

/**
* The platform service implementation for Fabric.
Expand Down Expand Up @@ -43,4 +46,9 @@ public String getMilkTranslationKey() {
return "tag.fluid.c.milk";
}

@Override
public int getBurnTime(ItemStack stack, RecipeType<?> recipeType) {
return AbstractFurnaceBlockEntity.getFuel().getOrDefault(stack.getItem(), 0);
}

}
1 change: 1 addition & 0 deletions fabric/src/main/resources/bucketlib.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"MobBucketItemAccessor"
],
"client": [
"AbstractFurnaceBlockEntityMixin",
"BlockModelAccessor",
"ItemModelGeneratorAccessor"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import de.cech12.bucketlib.api.item.UniversalBucketItem;
import de.cech12.bucketlib.item.UniversalBucketFluidHandler;
import de.cech12.bucketlib.platform.Services;
import de.cech12.bucketlib.util.BucketLibUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -27,12 +24,8 @@ public ForgeUniversalBucketItemMixin(Properties properties) {

@Override
public int getBurnTime(ItemStack itemStack, @Nullable RecipeType<?> recipeType) {
//entity buckets should not use the burn time of its fluid
if (!BucketLibUtil.containsEntityType(itemStack)) {
Fluid fluid = Services.FLUID.getContainedFluid(itemStack);
if (fluid != Fluids.EMPTY) {
return new ItemStack(fluid.getBucket()).getBurnTime(recipeType);
}
if (itemStack.getItem() instanceof UniversalBucketItem universalBucketItem) {
return universalBucketItem.getBucketBurnTime(itemStack, recipeType);
}
return super.getBurnTime(itemStack, recipeType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.LogicalSidedProvider;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.ModList;
Expand Down Expand Up @@ -49,4 +52,9 @@ public String getMilkTranslationKey() {
return "fluid_type.minecraft.milk";
}

@Override
public int getBurnTime(ItemStack stack, RecipeType<?> recipeType) {
return ForgeHooks.getBurnTime(stack, recipeType);
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Project
group=de.cech12.bucketlib
mod_version=3.2.1.5
mod_version=3.2.1.6
mod_id=bucketlib
mod_name=BucketLib
mod_author=Cech12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import de.cech12.bucketlib.api.BucketLibTags;
import de.cech12.bucketlib.api.item.UniversalBucketItem;
import de.cech12.bucketlib.platform.Services;
import de.cech12.bucketlib.util.BucketLibUtil;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -25,12 +22,8 @@ public NeoforgeUniversalBucketItemMixin(Properties properties) {

@Override
public int getBurnTime(@NotNull ItemStack itemStack, @Nullable RecipeType<?> recipeType) {
//entity buckets should not use the burn time of its fluid
if (!BucketLibUtil.containsEntityType(itemStack)) {
Fluid fluid = Services.FLUID.getContainedFluid(itemStack);
if (fluid != Fluids.EMPTY) {
return new ItemStack(fluid.getBucket()).getBurnTime(recipeType);
}
if (itemStack.getItem() instanceof UniversalBucketItem universalBucketItem) {
return universalBucketItem.getBucketBurnTime(itemStack, recipeType);
}
return super.getBurnTime(itemStack, recipeType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.neoforged.fml.LogicalSide;
import net.neoforged.fml.ModList;
Expand Down Expand Up @@ -49,4 +51,9 @@ public String getMilkTranslationKey() {
return "fluid_type.minecraft.milk";
}

@Override
public int getBurnTime(ItemStack stack, RecipeType<?> recipeType) {
return stack.getBurnTime(recipeType);
}

}

0 comments on commit de926dc

Please sign in to comment.