Skip to content

Commit

Permalink
port from 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Dec 9, 2024
1 parent 605db2c commit 6639be3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog for EverFurnace 1.21.2

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2024-12-08
- Initial release.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// option dependencies
modImplementation "curse.maven:modmenu-308702:5810603"
}

processResources {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.9

# Mod Properties
Expand All @@ -14,4 +14,4 @@ maven_group=gottsch
archives_base_name=everfurnace

# Dependencies
fabric_version=0.110.0+1.21.1
fabric_version=0.106.1+1.21.2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package mod.gottsch.fabric.everfurnace.core.mixin;

import mod.gottsch.fabric.everfurnace.core.EverFurnace;
import net.minecraft.block.AbstractFurnaceBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -28,13 +27,14 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.AbstractCookingRecipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.recipe.RecipeInputProvider;
import net.minecraft.recipe.RecipeUnlocker;
import net.minecraft.recipe.input.SingleStackRecipeInput;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -73,7 +73,7 @@ private void onLoad(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLooku
* @param ci
*/
@Inject(method = "tick", at = @At("HEAD")) // target more specifically somewhere closer to the actual calculations?
private static void onTick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
private static void onTick(ServerWorld world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
// cast block entity as a mixin block entity
ModFurnaceBlockEntityMixin blockEntityMixin = (ModFurnaceBlockEntityMixin)(Object) blockEntity;

Expand Down Expand Up @@ -107,8 +107,11 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
if (!outputStack.isEmpty() && outputStack.getCount() == blockEntity.getMaxCountPerStack()) return;

// test if can accept recipe output
RecipeEntry<?> recipeEntry = (RecipeEntry<?>)blockEntity.matchGetter.getFirstMatch(new SingleStackRecipeInput(cookStack), world).orElse(null);
if (!AbstractFurnaceBlockEntity.canAcceptRecipeOutput(blockEntity.getWorld().getRegistryManager(), recipeEntry, blockEntity.inventory, blockEntity.getMaxCountPerStack())) return;
SingleStackRecipeInput singleStackRecipeInput = new SingleStackRecipeInput(cookStack);
RecipeEntry<? extends AbstractCookingRecipe> recipeEntry;
recipeEntry = (RecipeEntry)blockEntity.matchGetter.getFirstMatch(singleStackRecipeInput, world).orElse(null);

if (!AbstractFurnaceBlockEntity.canAcceptRecipeOutput(blockEntity.getWorld().getRegistryManager(), recipeEntry, singleStackRecipeInput, blockEntity.inventory, blockEntity.getMaxCountPerStack())) return;
/////////////////////////

/*
Expand All @@ -131,6 +134,10 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
*/
long actualAppliedTime = Math.min(deltaTime, maxInputTime);

// have to calculate fuel time as it is no longer calculated during readNbt() as in 1.21.1
if (blockEntity.fuelTime == 0) {
blockEntity.fuelTime = blockEntity.getFuelTime(blockEntity.getWorld().getFuelRegistry(), fuelStack);
}
if (actualAppliedTime < blockEntity.fuelTime) {
// reduce burn time
blockEntity.burnTime =- (int) actualAppliedTime;
Expand All @@ -140,8 +147,7 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
fuelStack.decrement(1);
if (fuelStack.isEmpty()) {
blockEntity.burnTime = 0;
Item fuelItemRecipeRemainder = fuelItem.getRecipeRemainder();
blockEntity.inventory.set(1, fuelItemRecipeRemainder == null ? ItemStack.EMPTY : new ItemStack(fuelItemRecipeRemainder));
blockEntity.inventory.set(1, fuelItem.getRecipeRemainder());
} else {
blockEntity.burnTime =+ blockEntity.fuelTime;
}
Expand All @@ -160,8 +166,7 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
}
if (fuelStack.isEmpty()) {
blockEntity.burnTime = 0;
Item fuelItemRecipeRemainder = fuelItem.getRecipeRemainder();
blockEntity.inventory.set(1, fuelItemRecipeRemainder == null ? ItemStack.EMPTY : new ItemStack(fuelItemRecipeRemainder));
blockEntity.inventory.set(1, fuelItem.getRecipeRemainder());
} else {
blockEntity.burnTime =+ blockEntity.fuelTime;
}
Expand All @@ -171,7 +176,7 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
// increment cook time
blockEntity.cookTime =+ (int) actualAppliedTime;
if (blockEntity.cookTime >= blockEntity.cookTimeTotal) {
if (AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, blockEntity.inventory, blockEntity.getMaxCountPerStack())) {
if (AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, singleStackRecipeInput, blockEntity.inventory, blockEntity.getMaxCountPerStack())) {
blockEntity.setLastRecipe(recipeEntry);
}
if (cookStack.isEmpty()) {
Expand All @@ -190,15 +195,15 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
// reduced stack by quotient
boolean isSuccessful = false;
for (int iterations = 0; iterations < quotient; iterations++) {
isSuccessful |= AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, blockEntity.inventory, blockEntity.getMaxCountPerStack());
isSuccessful |= AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, singleStackRecipeInput, blockEntity.inventory, blockEntity.getMaxCountPerStack());
}
// update last recipe
if (isSuccessful) blockEntity.setLastRecipe(recipeEntry);

// increment cook time
blockEntity.cookTime =+ (int) remainder;
if (blockEntity.cookTime >= blockEntity.cookTimeTotal) {
if (AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, blockEntity.inventory, blockEntity.getMaxCountPerStack())) {
if (AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, singleStackRecipeInput, blockEntity.inventory, blockEntity.getMaxCountPerStack())) {
blockEntity.setLastRecipe(recipeEntry);
}
if (cookStack.isEmpty()) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/everfurnace.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ accessible field net/minecraft/block/entity/AbstractFurnaceBlockEntity burnTime
accessible field net/minecraft/block/entity/AbstractFurnaceBlockEntity cookTime I
accessible field net/minecraft/block/entity/AbstractFurnaceBlockEntity fuelTime I
accessible field net/minecraft/block/entity/AbstractFurnaceBlockEntity cookTimeTotal I
accessible field net/minecraft/block/entity/AbstractFurnaceBlockEntity matchGetter Lnet/minecraft/recipe/RecipeManager$MatchGetter;
accessible field net/minecraft/block/entity/AbstractFurnaceBlockEntity matchGetter Lnet/minecraft/recipe/ServerRecipeManager$MatchGetter;
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity isBurning ()Z
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity canAcceptRecipeOutput (Lnet/minecraft/registry/DynamicRegistryManager;Lnet/minecraft/recipe/RecipeEntry;Lnet/minecraft/util/collection/DefaultedList;I)Z
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity craftRecipe (Lnet/minecraft/registry/DynamicRegistryManager;Lnet/minecraft/recipe/RecipeEntry;Lnet/minecraft/util/collection/DefaultedList;I)Z
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity canAcceptRecipeOutput (Lnet/minecraft/registry/DynamicRegistryManager;Lnet/minecraft/recipe/RecipeEntry;Lnet/minecraft/recipe/input/SingleStackRecipeInput;Lnet/minecraft/util/collection/DefaultedList;I)Z
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity craftRecipe (Lnet/minecraft/registry/DynamicRegistryManager;Lnet/minecraft/recipe/RecipeEntry;Lnet/minecraft/recipe/input/SingleStackRecipeInput;Lnet/minecraft/util/collection/DefaultedList;I)Z
accessible method net/minecraft/block/entity/AbstractFurnaceBlockEntity getFuelTime (Lnet/minecraft/item/FuelRegistry;Lnet/minecraft/item/ItemStack;)I

0 comments on commit 6639be3

Please sign in to comment.