Skip to content

Commit

Permalink
adding the processing of remainingTime and cooldownTime
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Dec 17, 2024
1 parent 1919d23 commit bc5da9b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Save any unused detla/elapsed time (remainingDeltaTime) to the next tick
- Save any unused delta/elapsed time (remainingTime) to the next tick
in order to process against any inputted cook items, ie provided by hopper.
if none is found then remainingDeltaTime is reset to 0.
if none is found then remainingDeltaTime is reset to 0. this process is repeated
for up to a hopper cycle (8 ticks).
- Refactored to use Accessors and Invokers instead of accesstransformer.cfg
- Refactored to use mixin best practices to rename properties. this can cause a
one-time loss of elapsed time on first load of furnace.

### Added

- Saving new data -> remainingDeltaTime
- Saving new data -> remainingDeltaTime, cooldownTime

## [1.0.1] - 2024-12-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -99,7 +100,8 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
blockEntityMixin.setEverfurnace$lastGameTime(blockEntity.getWorld().getTime());

// if not burning - no fuel left - then exit
if (!everFurnaceBlockEntity.callIsBurning()){
if (!everFurnaceBlockEntity.callIsBurning()) {
blockEntityMixin.everfurnace$ClearTimes();
return;
}

Expand All @@ -109,26 +111,36 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
int remainingTime = blockEntityMixin.getEverfurnace$remainingTime();
int cooldownTime = blockEntityMixin.getEverfurnace$Cooldown();

// TODO if delta < 20 && remaining == 0 then return
// TODO use HopperBlockEntity.TRANSFER_COOLDOWN for the max cooldown

// exit if not enough time has passed
if (deltaTime < 20) {
if (deltaTime < 20 && remainingTime == 0) {
return;
}
deltaTime += remainingTime;

/*
* //////////////////////
* validations
* //////////////////////
*/
ItemStack cookStack = everFurnaceBlockEntity.getInventory().get(INPUT_SLOT);
if (cookStack.isEmpty()) return;
if (cookStack.isEmpty()) {
blockEntityMixin.setEverfurnace$Cooldown(--cooldownTime);
if (cooldownTime <= 0) {
blockEntityMixin.setEverfurnace$remainingTime(0);
}
return;
}

// get the output stack
ItemStack outputStack = everFurnaceBlockEntity.getInventory().get(OUTPUT_SLOT);
// return if it is already maxed out
if (!outputStack.isEmpty() && outputStack.getCount() == blockEntity.getMaxCountPerStack()) return;
if (!outputStack.isEmpty() && outputStack.getCount() == blockEntity.getMaxCountPerStack()) {
blockEntityMixin.setEverfurnace$Cooldown(--cooldownTime);
if (cooldownTime <= 0) {
blockEntityMixin.setEverfurnace$remainingTime(0);
}
return;
}

// test if can accept recipe output
SingleStackRecipeInput singleStackRecipeInput = new SingleStackRecipeInput(cookStack);
Expand All @@ -154,7 +166,7 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
+ everFurnaceBlockEntity.getLitTimeRemaining();

// calculate totalCookTimeRemaining
long totalCookTimeRemaining = (long) (cookStack.getCount() -1) * everFurnaceBlockEntity.getCookingTotalTime()
long totalCookTimeRemaining = (long) (cookStack.getCount() - 1) * everFurnaceBlockEntity.getCookingTotalTime()
+ (everFurnaceBlockEntity.getCookingTotalTime() - everFurnaceBlockEntity.getCookingTimeSpent());

// determine the max amount of time that can be used before one or both input run out.
Expand All @@ -166,10 +178,17 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
*/
long actualAppliedTime = Math.min(deltaTime, maxInputTime);

// calculate and save the remaining time
if (deltaTime > actualAppliedTime) {
blockEntityMixin.setEverfurnace$remainingTime((int) (deltaTime - actualAppliedTime));
} else {
blockEntityMixin.setEverfurnace$remainingTime(0);
}

if (actualAppliedTime < everFurnaceBlockEntity.getLitTotalTime()) {
// reduce burn time
everFurnaceBlockEntity.setLitTimeRemaining(everFurnaceBlockEntity.getLitTimeRemaining()
- (int) actualAppliedTime);
- (int) actualAppliedTime);

if (everFurnaceBlockEntity.getLitTimeRemaining() <= 0) {
Item fuelItem = fuelStack.getItem();
Expand All @@ -179,13 +198,12 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
everFurnaceBlockEntity.setLitTimeRemaining(0);
everFurnaceBlockEntity.getInventory().set(1, fuelItem.getRecipeRemainder());
} else {
everFurnaceBlockEntity.setLitTimeRemaining(everFurnaceBlockEntity.getLitTimeRemaining()
- everFurnaceBlockEntity.getLitTotalTime());
everFurnaceBlockEntity.setLitTimeRemaining(
everFurnaceBlockEntity.getLitTimeRemaining() - everFurnaceBlockEntity.getLitTotalTime());
}
}
} else {
int quotient = (int) (Math.floorDivExact(actualAppliedTime, everFurnaceBlockEntity.getLitTotalTime()
));
int quotient = (int) (Math.floorDivExact(actualAppliedTime, everFurnaceBlockEntity.getLitTotalTime()));
long remainder = actualAppliedTime % everFurnaceBlockEntity.getLitTotalTime();
// reduced stack by quotient
Item fuelItem = fuelStack.getItem();
Expand Down Expand Up @@ -221,8 +239,8 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
}
}
}
// actual applied time is greated that cook time total,
// there, need to apply a factor of
// actual applied time is greater than cook time total,
// then, need to apply a factor of
else {
int quotient = (int) (Math.floorDivExact(actualAppliedTime, everFurnaceBlockEntity.getCookingTotalTime()));
long remainder = actualAppliedTime % everFurnaceBlockEntity.getCookingTotalTime();
Expand Down Expand Up @@ -251,13 +269,23 @@ private static void onTick(ServerWorld world, BlockPos pos, BlockState state, Ab
}
}

// reset cooldown time
blockEntityMixin.setEverfurnace$Cooldown(HopperBlockEntity.TRANSFER_COOLDOWN);

// update block state
if(!everFurnaceBlockEntity.callIsBurning()) {
state = state.with(AbstractFurnaceBlock.LIT, Boolean.valueOf(everFurnaceBlockEntity.callIsBurning()));
world.setBlockState(pos, state, Block.NOTIFY_ALL);
AbstractFurnaceBlockEntity.markDirty(world, pos, state);
}
}

@Unique
public void everfurnace$ClearTimes() {
setEverfurnace$Cooldown(HopperBlockEntity.TRANSFER_COOLDOWN);
setEverfurnace$remainingTime(0);
}

@Unique
public long getEverfurnace$lastGameTime() {
return this.everfurnace$lastGameTime;
Expand Down

0 comments on commit bc5da9b

Please sign in to comment.