diff --git a/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenBottomBlockEntity.java b/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenBottomBlockEntity.java index 43043aed..ac86d054 100644 --- a/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenBottomBlockEntity.java +++ b/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenBottomBlockEntity.java @@ -3,7 +3,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -14,11 +13,8 @@ import com.eerussianguy.firmalife.common.FLHelpers; import com.eerussianguy.firmalife.common.FLTags; -import com.eerussianguy.firmalife.common.blocks.AbstractOvenBlock; -import com.eerussianguy.firmalife.common.blocks.FLStateProperties; import com.eerussianguy.firmalife.common.blocks.ICure; import com.eerussianguy.firmalife.common.blocks.OvenBottomBlock; -import com.eerussianguy.firmalife.config.FLConfig; import net.dries007.tfc.common.blockentities.TickableInventoryBlockEntity; import net.dries007.tfc.common.capabilities.heat.HeatCapability; import net.dries007.tfc.util.Fuel; @@ -29,7 +25,7 @@ /** * Consumes fuel like a charcoal forge but has no other functionality (like, executing recipes) */ -public class OvenBottomBlockEntity extends TickableInventoryBlockEntity implements ICalendarTickable +public class OvenBottomBlockEntity extends TickableInventoryBlockEntity implements ICalendarTickable, OvenLike { public static void cure(Level level, BlockState oldState, BlockState newState, BlockPos pos) { @@ -69,30 +65,11 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, OvenB oven.checkForCalendarUpdate(); final int updateInterval = 40; + final boolean cured = state.getBlock() instanceof ICure cure && cure.isCured(); if (level.getGameTime() % updateInterval == 0) { - if (state.hasProperty(FLStateProperties.HAS_CHIMNEY)) - { - final boolean chimney = state.getValue(FLStateProperties.HAS_CHIMNEY); - final BlockPos chimneyPos = AbstractOvenBlock.locateChimney(level, pos, state); - final boolean chimneyNow = chimneyPos != null; - if (chimneyNow != chimney) - { - level.setBlockAndUpdate(pos, state.setValue(FLStateProperties.HAS_CHIMNEY, chimneyNow)); - } - if (!chimneyNow && level.random.nextInt(4) == 0 && level instanceof ServerLevel server) - { - Helpers.fireSpreaderTick(server, pos, level.random, 2); - } - } - - final boolean cured = state.getBlock() instanceof ICure cure && cure.isCured(); - if (oven.cureTicks <= FLConfig.SERVER.ovenCureTicks.get()) oven.cureTicks += updateInterval; - if (oven.temperature > (float) FLConfig.SERVER.ovenCureTemperature.get() && oven.cureTicks > FLConfig.SERVER.ovenCureTicks.get()) - { - AbstractOvenBlock.cureAllAround(level, pos, !cured); - } - oven.updateLogs(); + OvenLike.regularBlockUpdate(level, pos, state, oven, cured, updateInterval); + oven.updateLogs(); } if (state.getValue(BlockStateProperties.LIT)) @@ -156,16 +133,24 @@ public OvenBottomBlockEntity(BlockPos pos, BlockState state) lastPlayerTick = Calendars.SERVER.getTicks(); } + @Override public float getTemperature() { return temperature; } + @Override public int getCureTicks() { return cureTicks; } + @Override + public void addCureTicks(int ticks) + { + cureTicks += ticks; + } + @Override public void onCalendarUpdate(long ticks) { diff --git a/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenLike.java b/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenLike.java new file mode 100644 index 00000000..414d6814 --- /dev/null +++ b/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenLike.java @@ -0,0 +1,44 @@ +package com.eerussianguy.firmalife.common.blockentities; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; + +import com.eerussianguy.firmalife.common.blocks.AbstractOvenBlock; +import com.eerussianguy.firmalife.common.blocks.FLStateProperties; +import com.eerussianguy.firmalife.config.FLConfig; +import net.dries007.tfc.util.Helpers; + +public interface OvenLike +{ + static void regularBlockUpdate(Level level, BlockPos pos, BlockState state, OvenLike oven, boolean cured, int updateInterval) + { + if (state.hasProperty(FLStateProperties.HAS_CHIMNEY)) + { + final boolean chimney = state.getValue(FLStateProperties.HAS_CHIMNEY); + final BlockPos chimneyPos = AbstractOvenBlock.locateChimney(level, pos, state); + final boolean chimneyNow = chimneyPos != null; + if (chimneyNow != chimney) + { + level.setBlockAndUpdate(pos, state.setValue(FLStateProperties.HAS_CHIMNEY, chimneyNow)); + } + if (!chimneyNow && level.random.nextInt(4) == 0 && level instanceof ServerLevel server && oven.getTemperature() > 0f) + { + Helpers.fireSpreaderTick(server, pos, level.random, 2); + } + } + if (oven.getCureTicks() <= FLConfig.SERVER.ovenCureTicks.get()) oven.addCureTicks(updateInterval); + if (oven.getTemperature() > (float) FLConfig.SERVER.ovenCureTemperature.get() && oven.getCureTicks() > FLConfig.SERVER.ovenCureTicks.get()) + { + AbstractOvenBlock.cureAllAround(level, pos, !cured); + } + } + + float getTemperature(); + + int getCureTicks(); + + void addCureTicks(int ticks); + +} diff --git a/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenTopBlockEntity.java b/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenTopBlockEntity.java index f978a9cf..9ad11e05 100644 --- a/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenTopBlockEntity.java +++ b/src/main/java/com/eerussianguy/firmalife/common/blockentities/OvenTopBlockEntity.java @@ -4,7 +4,6 @@ import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -14,13 +13,10 @@ import net.minecraftforge.items.IItemHandlerModifiable; import com.eerussianguy.firmalife.common.FLHelpers; -import com.eerussianguy.firmalife.common.blocks.AbstractOvenBlock; -import com.eerussianguy.firmalife.common.blocks.FLStateProperties; import com.eerussianguy.firmalife.common.blocks.ICure; import com.eerussianguy.firmalife.common.blocks.OvenBottomBlock; import com.eerussianguy.firmalife.common.items.FLFoodTraits; import com.eerussianguy.firmalife.common.recipes.OvenRecipe; -import com.eerussianguy.firmalife.config.FLConfig; import net.dries007.tfc.common.blockentities.InventoryBlockEntity; import net.dries007.tfc.common.blockentities.TickableInventoryBlockEntity; import net.dries007.tfc.common.capabilities.DelegateItemHandler; @@ -39,7 +35,7 @@ /** * Works like a crucible but with a delay on producing the heating recipes. */ -public class OvenTopBlockEntity extends TickableInventoryBlockEntity implements ICalendarTickable +public class OvenTopBlockEntity extends TickableInventoryBlockEntity implements ICalendarTickable, OvenLike { public static void cure(Level level, BlockState oldState, BlockState newState, BlockPos pos) { @@ -92,26 +88,7 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, OvenT final int updateInterval = 40; if (level.getGameTime() % updateInterval == 0) { - if (state.hasProperty(FLStateProperties.HAS_CHIMNEY)) - { - final boolean chimney = state.getValue(FLStateProperties.HAS_CHIMNEY); - final BlockPos chimneyPos = AbstractOvenBlock.locateChimney(level, pos, state); - final boolean chimneyNow = chimneyPos != null; - if (chimneyNow != chimney) - { - level.setBlockAndUpdate(pos, state.setValue(FLStateProperties.HAS_CHIMNEY, chimneyNow)); - } - if (!chimneyNow && level.random.nextInt(4) == 0 && level instanceof ServerLevel server) - { - Helpers.fireSpreaderTick(server, pos, level.random, 2); - } - } - - if (oven.cureTicks <= FLConfig.SERVER.ovenCureTicks.get()) oven.cureTicks += updateInterval; - if (oven.temperature > (float) FLConfig.SERVER.ovenCureTemperature.get() && oven.cureTicks > FLConfig.SERVER.ovenCureTicks.get()) - { - AbstractOvenBlock.cureAllAround(level, pos, !cured); - } + OvenLike.regularBlockUpdate(level, pos, state, oven, cured, updateInterval); } if (oven.targetTemperatureStabilityTicks > 0) @@ -191,11 +168,6 @@ public OvenTopBlockEntity(BlockPos pos, BlockState state) sidedHeat = new SidedHandler.Noop<>(inventory); } - public int getCureTicks() - { - return cureTicks; - } - @Override public void loadAdditional(CompoundTag nbt) { @@ -219,11 +191,24 @@ public void saveAdditional(CompoundTag nbt) super.saveAdditional(nbt); } + @Override public float getTemperature() { return temperature; } + @Override + public int getCureTicks() + { + return cureTicks; + } + + @Override + public void addCureTicks(int ticks) + { + cureTicks += ticks; + } + @NotNull @Override public LazyOptional getCapability(Capability cap, @Nullable Direction side) diff --git a/src/main/java/com/eerussianguy/firmalife/compat/tooltip/FLTooltips.java b/src/main/java/com/eerussianguy/firmalife/compat/tooltip/FLTooltips.java index 73f66f36..af0d0314 100644 --- a/src/main/java/com/eerussianguy/firmalife/compat/tooltip/FLTooltips.java +++ b/src/main/java/com/eerussianguy/firmalife/compat/tooltip/FLTooltips.java @@ -35,8 +35,8 @@ public static void register(BiConsumer { @@ -98,8 +98,8 @@ else if (traits != null) } }; - public static final BlockEntityTooltip OVEN_BOTTOM = (level, state, pos, entity, tooltip) -> { - if (state.getBlock() instanceof OvenBottomBlock block && entity instanceof OvenBottomBlockEntity oven) + public static final BlockEntityTooltip OVEN = (level, state, pos, entity, tooltip) -> { + if (entity instanceof OvenLike oven) { BlockEntityTooltips.heat(tooltip, oven.getTemperature()); if (state.getBlock() instanceof ICure cure && !cure.isCured()) @@ -115,25 +115,6 @@ else if (traits != null) } } }; - - public static final BlockEntityTooltip OVEN_TOP = (level, state, pos, entity, tooltip) -> { - if (state.getBlock() instanceof OvenTopBlock block && entity instanceof OvenTopBlockEntity oven) - { - BlockEntityTooltips.heat(tooltip, oven.getTemperature()); - if (state.getBlock() instanceof ICure cure && !cure.isCured()) - { - if (oven.getTemperature() < FLConfig.SERVER.ovenCureTemperature.get()) - { - tooltip.accept(Helpers.translatable("firmalife.jade.cannot_cure")); - } - else - { - tooltip.accept(Helpers.translatable("firmalife.jade.cure_time_left", delta(level, FLConfig.SERVER.ovenCureTicks.get() - oven.getCureTicks()))); - } - } - } - }; - } public static final class Entities