Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "createaddition:liquid_burning",
"burn_time": 2400,
"burn_time": 24000,
"ingredients": [
{
"type": "neoforge:tag",
Expand All @@ -10,4 +10,4 @@
],
"results": [],
"superheated": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public LiquidBlazeBurnerBlock(Properties properties) {
registerDefaultState(defaultBlockState().setValue(HEAT_LEVEL, BlazeBurnerBlock.HeatLevel.NONE));
}

public static final MapCodec<BlazeBurnerBlock> CODEC = simpleCodec(BlazeBurnerBlock::new);
public static final MapCodec<LiquidBlazeBurnerBlock> CODEC = simpleCodec(LiquidBlazeBurnerBlock::new);

@Override
protected MapCodec<? extends HorizontalDirectionalBlock> codec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Optional;

import com.mrh0.createaddition.CreateAddition;
import com.mrh0.createaddition.config.CommonConfig;
import com.mrh0.createaddition.index.CABlockEntities;
import com.mrh0.createaddition.index.CALang;
import com.mrh0.createaddition.index.CARecipes;
Expand All @@ -21,6 +22,7 @@
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
import com.simibubi.create.foundation.fluid.SmartFluidTank;

import net.createmod.catnip.animation.LerpedFloat;
Expand Down Expand Up @@ -59,7 +61,7 @@
import static com.simibubi.create.content.processing.burner.BlazeBurnerBlock.HEAT_LEVEL;

public class LiquidBlazeBurnerBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation, IObserveBlockEntity {
public static final int MAX_HEAT_CAPACITY = 10000;
public int MAX_HEAT_CAPACITY = CommonConfig.LIQUID_BLAZE_BURNER_MAX_HEAT_CAPACITY.get();

protected FuelType activeFuel;
protected int remainingBurnTime;
Expand All @@ -70,6 +72,8 @@ public class LiquidBlazeBurnerBlockEntity extends SmartBlockEntity implements IH
protected boolean hat;
public final boolean stockKeeper = false;
BlazeBurnerBlock.HeatLevel heatLevel;
private ScrollValueBehaviour HEAT_CAPACITY;
private ScrollValueBehaviour LIQUID_CAPACITY;

public LiquidBlazeBurnerBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
Expand All @@ -88,8 +92,37 @@ public LiquidBlazeBurnerBlockEntity(BlockEntityType<?> type, BlockPos pos, Block
}

@Override
public void addBehaviours(List<BlockEntityBehaviour> list) {
public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
LIQUID_CAPACITY = new LiquidBlazeScrollValueBehaviourLiquid(Component.translatable(CreateAddition.MODID + ".tooltip.liquid_burning.liquid_capacity"), this,
new LiquidBlazeScrollSlot(false)).between(0, defaultLiquidValue());
LIQUID_CAPACITY.withFormatter(this::formatLiquid);
LIQUID_CAPACITY.withCallback(v -> syncTankCapacity());
LIQUID_CAPACITY.setValue(defaultLiquidValue());
behaviours.add(LIQUID_CAPACITY);

HEAT_CAPACITY = new LiquidBlazeScrollValueBehaviourHeat(Component.translatable(CreateAddition.MODID + ".tooltip.liquid_burning.heat_capacity"), this,
new LiquidBlazeScrollSlot(true)).between(0, defaultHeatValue());
HEAT_CAPACITY.withFormatter(this::formatHeat);
HEAT_CAPACITY.withCallback(v -> MAX_HEAT_CAPACITY = v);
HEAT_CAPACITY.setValue(defaultHeatValue());
behaviours.add(HEAT_CAPACITY);
}

protected int defaultHeatValue() {
return CommonConfig.LIQUID_BLAZE_BURNER_MAX_HEAT_CAPACITY.get();
}

protected int defaultLiquidValue() {
return CommonConfig.LIQUID_BLAZE_BURNER_MAX_LIQUID_CAPACITY.get();
}

private void syncTankCapacity(){
if (tankInventory == null || LIQUID_CAPACITY == null) return;
int capacity = LIQUID_CAPACITY.getValue();
tankInventory.setCapacity(capacity);
if (tankInventory.getFluidAmount() > capacity)
tankInventory.drain(tankInventory.getFluidAmount() - capacity, IFluidHandler.FluidAction.EXECUTE);
notifyUpdate();
}

public BlazeBurnerBlock.HeatLevel getHeatLevelForRender() {
Expand All @@ -111,12 +144,12 @@ public static void registerCapability(RegisterCapabilitiesEvent event) {
}

protected SmartFluidTank createInventory() {
return new SmartFluidTank(4000, this::onFluidStackChanged);
return new SmartFluidTank(CommonConfig.LIQUID_BLAZE_BURNER_MAX_LIQUID_CAPACITY.get(), this::onFluidStackChanged);
}

protected void onFluidStackChanged(FluidStack newFluidStack) {

if (!hasLevel()) return;
syncTankCapacity();
update(newFluidStack);
}

Expand Down Expand Up @@ -187,10 +220,17 @@ public boolean isCreative() {
return isCreative;
}

private boolean firstTick = true;
@Override
public void tick() {
super.tick();

if (firstTick) {
firstTick = false;
syncTankCapacity();
if (HEAT_CAPACITY != null) MAX_HEAT_CAPACITY = HEAT_CAPACITY.getValue();
}

if (level == null) return;
if (level.isClientSide) {
tickAnimation();
Expand All @@ -209,7 +249,7 @@ public void tick() {

if (activeFuel == FuelType.SPECIAL) {
activeFuel = FuelType.NORMAL;
remainingBurnTime = MAX_HEAT_CAPACITY / 2;
remainingBurnTime = HEAT_CAPACITY.getValue() / 2;
} else activeFuel = FuelType.NONE;

updateBlockState();
Expand Down Expand Up @@ -264,18 +304,34 @@ public void write(CompoundTag tag, HolderLookup.Provider registries, boolean cli
if (goggles) tag.putBoolean("Goggles", true);
if (hat) tag.putBoolean("TrainHat", true);
tag.put("TankContent", tankInventory.writeToNBT(registries, new CompoundTag()));
tag.putInt("TankCapacity", tankInventory.getCapacity());
super.write(tag, registries, clientPacket);
}

@Override
protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) {
super.read(tag, registries, clientPacket);
activeFuel = FuelType.values()[tag.getInt("fuelLevel")];
remainingBurnTime = tag.getInt("burnTimeRemaining");
isCreative = tag.getBoolean("isCreative");
goggles = tag.contains("Goggles");
hat = tag.contains("TrainHat");
tankInventory.readFromNBT(registries, tag.getCompound("TankContent"));
super.read(tag, registries, clientPacket);
if (tag.contains("TankCapacity")) tankInventory.setCapacity(tag.getInt("TankCapacity"));
}

private String formatHeat(int value) {
if (value < 60)
return value + "t";
if (value < 20 * 60)
return (value / 20) + "s";
return (value / 20 / 60) + "m";
}

private String formatLiquid(int value) {
if (value < 1000)
return value + "mB";
return (value / 1000) + "B";
}

public BlazeBurnerBlock.HeatLevel getHeatLevelFromBlock() {
Expand Down Expand Up @@ -325,7 +381,7 @@ protected boolean tryUpdateFuel(ItemStack itemStack, boolean forceOverflow, bool
if(tryUpdateLiquid(itemStack, simulate)) return true;

if (AllItemTags.BLAZE_BURNER_FUEL_SPECIAL.matches(itemStack)) {
newBurnTime = 1000;
newBurnTime = 3200;
newFuel = FuelType.SPECIAL;
} else {
newBurnTime = itemStack.getBurnTime(null);
Expand All @@ -342,8 +398,8 @@ else if (AllItemTags.BLAZE_BURNER_FUEL_REGULAR.matches(itemStack)) {
if (activeFuel == FuelType.SPECIAL && remainingBurnTime > 20) return false;

if (newFuel == activeFuel) {
if (remainingBurnTime + newBurnTime > MAX_HEAT_CAPACITY && !forceOverflow) return false;
newBurnTime = Mth.clamp(remainingBurnTime + newBurnTime, 0, MAX_HEAT_CAPACITY);
if (remainingBurnTime + newBurnTime > HEAT_CAPACITY.getValue() && !forceOverflow) return false;
newBurnTime = Mth.clamp(remainingBurnTime + newBurnTime, 0, HEAT_CAPACITY.getValue());
}

if (simulate) return true;
Expand Down Expand Up @@ -407,7 +463,7 @@ protected BlazeBurnerBlock.HeatLevel getHeatLevelFromFuelType(FuelType fuel) {
level = BlazeBurnerBlock.HeatLevel.SEETHING;
break;
case NORMAL:
boolean lowPercent = (double) remainingBurnTime / MAX_HEAT_CAPACITY < 0.0125;
boolean lowPercent = (double) remainingBurnTime / HEAT_CAPACITY.getValue() < 0.0125;
level = lowPercent ? BlazeBurnerBlock.HeatLevel.FADING : BlazeBurnerBlock.HeatLevel.KINDLED;
break;
case NONE:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mrh0.createaddition.blocks.liquid_blaze_burner;

import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;

import dev.engine_room.flywheel.lib.transform.TransformStack;
import net.createmod.catnip.math.VecHelper;
import net.createmod.catnip.math.AngleHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.Vec3;

public class LiquidBlazeScrollSlot extends ValueBoxTransform.Dual {

public LiquidBlazeScrollSlot(boolean isHeatSlot) {
super(isHeatSlot);
}

@Override
public Vec3 getLocalOffset(LevelAccessor level, BlockPos pos, BlockState state) {
return VecHelper.voxelSpace(first ? 5 : 11, 0, 8);
}

@Override
public void rotate(LevelAccessor level, BlockPos pos, BlockState state, PoseStack ms) {
TransformStack.of(ms)
.rotateYDegrees(180)
.rotateXDegrees(270);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.mrh0.createaddition.blocks.liquid_blaze_burner;

import com.mrh0.createaddition.config.CommonConfig;

import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsBoard;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsFormatter;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.BehaviourType;
import com.simibubi.create.foundation.utility.CreateLang;

import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

public class LiquidBlazeScrollValueBehaviourHeat extends ScrollValueBehaviour {

public static final BehaviourType<LiquidBlazeScrollValueBehaviourHeat> TYPE = new BehaviourType<>();

@Override
public BehaviourType<?> getType() {
return TYPE;
}

public LiquidBlazeScrollValueBehaviourHeat(Component label, SmartBlockEntity be, ValueBoxTransform slot) {
super(label, be, slot);
}

@Override
public ValueSettingsBoard createBoard(Player player, BlockHitResult hitResult) {
int maxTicks = CommonConfig.LIQUID_BLAZE_BURNER_MAX_HEAT_CAPACITY.get();
int maxMinutes = maxTicks / (60 * 20);
return new ValueSettingsBoard(label,Math.max(maxMinutes, 60), 10,
CreateLang.translatedOptions("generic.unit", "ticks", "seconds", "minutes"),
new ValueSettingsFormatter(this::formatSettings));
}

@Override
public void write(CompoundTag nbt, HolderLookup.Provider registries, boolean clientPacket) {
nbt.putInt("HeatCapacityValue", value);
}

@Override
public void read(CompoundTag nbt, HolderLookup.Provider registries, boolean clientPacket) {
if (nbt.contains("HeatCapacityValue"))
value = nbt.getInt("HeatCapacityValue");
else
value = CommonConfig.LIQUID_BLAZE_BURNER_MAX_HEAT_CAPACITY.get();
}

@Override
public void setValueSettings(Player player, ValueSettings valueSetting, boolean ctrlHeld) {
int value = valueSetting.value();
int multiplier = switch (valueSetting.row()) {
case 0 -> 1;
case 1 -> 20;
default -> 60 * 20;
};
if (!valueSetting.equals(getValueSettings()))
playFeedbackSound(this);
setValue(Math.max(2, Math.max(1, value) * multiplier));
}

@Override
public ValueSettings getValueSettings() {
int row = 0;
int value = this.value;

if (value > 60 * 20) {
value = value / (60 * 20);
row = 2;
} else if (value > 60) {
value = value / 20;
row = 1;
}

return new ValueSettings(row, value);
}

public MutableComponent formatSettings(ValueSettings settings) {
int value = Math.max(1, settings.value());
return Component.literal(switch (settings.row()) {
case 0 -> Math.max(2, value) + "t";
case 1 -> "0:" + (value < 10 ? "0" : "") + value;
default -> value + ":00";
});
}

public int netId() {
return 1;
}
}
Loading