Skip to content

Commit

Permalink
fix ovens lighting stuff on fire when not lit
Browse files Browse the repository at this point in the history
  • Loading branch information
eerussianguy committed Sep 29, 2022
1 parent 86566ee commit a56bc17
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -29,7 +25,7 @@
/**
* Consumes fuel like a charcoal forge but has no other functionality (like, executing recipes)
*/
public class OvenBottomBlockEntity extends TickableInventoryBlockEntity<ItemStackHandler> implements ICalendarTickable
public class OvenBottomBlockEntity extends TickableInventoryBlockEntity<ItemStackHandler> implements ICalendarTickable, OvenLike
{
public static void cure(Level level, BlockState oldState, BlockState newState, BlockPos pos)
{
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,7 +35,7 @@
/**
* Works like a crucible but with a delay on producing the heating recipes.
*/
public class OvenTopBlockEntity extends TickableInventoryBlockEntity<OvenTopBlockEntity.OvenInventory> implements ICalendarTickable
public class OvenTopBlockEntity extends TickableInventoryBlockEntity<OvenTopBlockEntity.OvenInventory> implements ICalendarTickable, OvenLike
{
public static void cure(Level level, BlockState oldState, BlockState newState, BlockPos pos)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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 <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable Direction side)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static void register(BiConsumer<BlockEntityTooltip, Class<? extends Block
r.accept(DRYING_MAT, SolarDrierBlock.class);
r.accept(STRING, StringBlock.class);
r.accept(CHEESE, CheeseWheelBlock.class);
r.accept(OVEN_BOTTOM, OvenBottomBlock.class);
r.accept(OVEN_TOP, OvenTopBlock.class);
r.accept(OVEN, OvenBottomBlock.class);
r.accept(OVEN, OvenTopBlock.class);
}

public static final BlockEntityTooltip DRYING_MAT = (level, state, pos, entity, tooltip) -> {
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit a56bc17

Please sign in to comment.