Skip to content

Commit

Permalink
beta complete
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Dec 8, 2024
1 parent ba326c6 commit d74993d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand Down Expand Up @@ -90,7 +88,7 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
long deltaTime = blockEntity.getWorld().getTime() - localLastGameTime;

// if less than 1 second (20 ticks) has elapsed then return
if (deltaTime < 20) {
if (deltaTime < 20) { // TODO this could be a config setting
return;
}
EverFurnace.LOGGER.debug("delta time -> {}", deltaTime);
Expand Down Expand Up @@ -134,12 +132,9 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
*/
long actualAppliedTime = Math.min(deltaTime, maxInputTime);

// TODO 2 use cases a) applyTime < cookTimeTotal (may or may not cook item) and b) applyTime > cookTimeTotal
if (actualAppliedTime < blockEntity.fuelTime) {
// TODO this may be incorrect... because fuelTime could be less than cookTimeTotal
// TODO it isn't a given that fuel time is always longer than cook time.
// reduce burn time
blockEntity.burnTime = -(int) actualAppliedTime;
blockEntity.burnTime =- (int) actualAppliedTime;
if (blockEntity.burnTime <= 0) {
Item fuelItem = fuelStack.getItem();
// reduce the size of the fuel stack
Expand All @@ -149,16 +144,33 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
Item fuelItemRecipeRemainder = fuelItem.getRecipeRemainder();
blockEntity.inventory.set(1, fuelItemRecipeRemainder == null ? ItemStack.EMPTY : new ItemStack(fuelItemRecipeRemainder));
} else {
blockEntity.burnTime += blockEntity.fuelTime;
blockEntity.burnTime =+ blockEntity.fuelTime;
}
}
} else {
quotient
int quotient = (int) (Math.floorDivExact(actualAppliedTime, blockEntity.fuelTime));
long remainder = actualAppliedTime % blockEntity.fuelTime;
// reduced stack by quotient
Item fuelItem = fuelStack.getItem();
fuelStack.decrement(quotient);
// reduce burnTime by remainder
blockEntity.burnTime =- (int)remainder;
if (blockEntity.burnTime <= 0) {
// reduce the size of the fuel stack
fuelStack.decrement(1);
}
if (fuelStack.isEmpty()) {
blockEntity.burnTime = 0;
Item fuelItemRecipeRemainder = fuelItem.getRecipeRemainder();
blockEntity.inventory.set(1, fuelItemRecipeRemainder == null ? ItemStack.EMPTY : new ItemStack(fuelItemRecipeRemainder));
} else {
blockEntity.burnTime =+ blockEntity.fuelTime;
}
}

if (actualAppliedTime < blockEntity.cookTimeTotal) {
// increment cook time
blockEntity.cookTime += (int) actualAppliedTime;
blockEntity.cookTime =+ (int) actualAppliedTime;
if (blockEntity.cookTime >= blockEntity.cookTimeTotal) {
if (AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, blockEntity.inventory, blockEntity.getMaxCountPerStack())) {
blockEntity.setLastRecipe(recipeEntry);
Expand All @@ -174,19 +186,37 @@ private static void onTick(World world, BlockPos pos, BlockState state, Abstract
// actual applied time is greated that cook time total,
// there, need to apply a factor of
else {
//
int quotient = (int) (Math.floorDivExact(actualAppliedTime, blockEntity.cookTimeTotal));
long remainder = actualAppliedTime % blockEntity.cookTimeTotal;
// TODO could write a more efficient method for craftRecipe for this for loop
// reduced stack by quotient
boolean isSuccessful = false;
for (int iterations = 0; iterations < quotient; iterations++) {
isSuccessful |= AbstractFurnaceBlockEntity.craftRecipe(world.getRegistryManager(), recipeEntry, 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())) {
blockEntity.setLastRecipe(recipeEntry);
}
if (cookStack.isEmpty()) {
blockEntity.cookTime = 0;
blockEntity.cookTimeTotal = 0;
} else {
blockEntity.cookTimeTotal -= blockEntity.cookTimeTotal;
}
}
}

if(!blockEntity.isBurning()) {
state = state.with(AbstractFurnaceBlock.LIT, Boolean.valueOf(blockEntity.isBurning()));
world.setBlockState(pos, state, Block.NOTIFY_ALL);
AbstractFurnaceBlockEntity.markDirty(world, pos, state);
}


// NOTE getCookTime() gets the cook time for the current slotted item
// EverFurnace.LOGGER.debug("updating lastGameTime to {}", ((AbstractFurnaceBlockEntity)(Object)blockEntity).getWorld().getTime());
}

@Unique
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"gottsch"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
"homepage": "https://www.curseforge.com/minecraft/mc-mods/everfurnace",
"sources": "https://github.com/gottsch/gottsch-minecraft-fabric-EverFurnace"
},
"license": "GNU GPL v3",
"icon": "assets/everfurnace/icon.png",
Expand Down

0 comments on commit d74993d

Please sign in to comment.