mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
Go to API. Go directly to API. Do not pass GO, do not collect $200.
- BoilerHeater API
This commit is contained in:
parent
381a0ae3bd
commit
8fceeb44a5
3 changed files with 72 additions and 41 deletions
|
@ -0,0 +1,51 @@
|
|||
package com.simibubi.create.api.boiler;
|
||||
|
||||
import com.simibubi.create.api.registry.SimpleRegistry;
|
||||
import com.simibubi.create.content.fluids.tank.BoilerHeaters;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/**
|
||||
* A BoilerHeater provides heat to boilers.
|
||||
* Boilers will query blocks for heaters through the registry, usually with {@link #findHeat(Level, BlockPos, BlockState) findHeat}.
|
||||
* Heaters can provide a heat level by returning any positive integer from their {@link #getHeat(Level, BlockPos, BlockState) getHeat} method.
|
||||
* Returning any negative number counts as no heat - {@link #NO_HEAT} is provided for convenience.
|
||||
* <p>
|
||||
* Returning {@link #PASSIVE_HEAT} is special - passive heat can be used to provide a small amount of heat, highly limiting
|
||||
* in its abilities. This is usually used for free sources of heat, such as fire or magma blocks.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface BoilerHeater {
|
||||
int PASSIVE_HEAT = 0;
|
||||
int NO_HEAT = -1;
|
||||
|
||||
/**
|
||||
* The heater used by common passively-heating blocks. Automatically provides
|
||||
* heat for any block in the {@code create:passive_boiler_heaters} block tag.
|
||||
*/
|
||||
BoilerHeater PASSIVE = BoilerHeaters::passive;
|
||||
/**
|
||||
* The heater used by Blaze Burners. Addons can register this to their own blocks if they use the same functionality.
|
||||
*/
|
||||
BoilerHeater BLAZE_BURNER = BoilerHeaters::blazeBurner;
|
||||
|
||||
SimpleRegistry<Block, BoilerHeater> REGISTRY = SimpleRegistry.create();
|
||||
|
||||
/**
|
||||
* Gets the heat at the given location. If a heater is present, queries it for heat. If not, returns {@link #NO_HEAT}.
|
||||
*/
|
||||
static float findHeat(Level level, BlockPos pos, BlockState state) {
|
||||
BoilerHeater heater = REGISTRY.get(state);
|
||||
return heater != null ? heater.getHeat(level, pos, state) : NO_HEAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount of heat to provide.
|
||||
* @see #NO_HEAT
|
||||
* @see #PASSIVE_HEAT
|
||||
*/
|
||||
float getHeat(Level level, BlockPos pos, BlockState state);
|
||||
}
|
|
@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllSoundEvents;
|
||||
import com.simibubi.create.api.boiler.BoilerHeater;
|
||||
import com.simibubi.create.content.decoration.steamWhistle.WhistleBlock;
|
||||
import com.simibubi.create.content.decoration.steamWhistle.WhistleBlockEntity;
|
||||
import com.simibubi.create.content.kinetics.BlockStressValues;
|
||||
|
@ -392,7 +393,7 @@ public class BoilerData {
|
|||
for (int zOffset = 0; zOffset < controller.width; zOffset++) {
|
||||
BlockPos pos = controllerPos.offset(xOffset, -1, zOffset);
|
||||
BlockState blockState = level.getBlockState(pos);
|
||||
float heat = BoilerHeaters.getActiveHeat(level, pos, blockState);
|
||||
float heat = BoilerHeater.findHeat(level, pos, blockState);
|
||||
if (heat == 0) {
|
||||
passiveHeat = true;
|
||||
} else if (heat > 0) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.fluids.tank;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllTags.AllBlockTags;
|
||||
import com.simibubi.create.api.boiler.BoilerHeater;
|
||||
import com.simibubi.create.api.registry.SimpleRegistry;
|
||||
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock;
|
||||
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock.HeatLevel;
|
||||
|
@ -9,31 +10,22 @@ import com.simibubi.create.foundation.utility.BlockHelper;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BoilerHeaters {
|
||||
public static final int PASSIVE_HEAT = 0;
|
||||
public static final int NO_HEAT = -1;
|
||||
|
||||
public static final SimpleRegistry<Block, Heater> REGISTRY = SimpleRegistry.create();
|
||||
|
||||
public static final Heater PASSIVE_HEATER = (level, pos, state) -> BlockHelper.isNotUnheated(state) ? PASSIVE_HEAT : NO_HEAT;
|
||||
|
||||
/**
|
||||
* Gets the heat at the given location. If a heater is present, queries it for heat. If not, returns {@link #NO_HEAT}.
|
||||
* @see Heater#getActiveHeat(Level, BlockPos, BlockState)
|
||||
*/
|
||||
public static float getActiveHeat(Level level, BlockPos pos, BlockState state) {
|
||||
Heater heater = REGISTRY.get(state.getBlock());
|
||||
return heater != null ? heater.getActiveHeat(level, pos, state) : NO_HEAT;
|
||||
public static void registerDefaults() {
|
||||
BoilerHeater.REGISTRY.register(AllBlocks.BLAZE_BURNER.get(), BoilerHeater.BLAZE_BURNER);
|
||||
BoilerHeater.REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(AllBlockTags.PASSIVE_BOILER_HEATERS.tag, BoilerHeater.PASSIVE));
|
||||
}
|
||||
|
||||
public static void registerDefaults() {
|
||||
REGISTRY.register(AllBlocks.BLAZE_BURNER.get(), (level, pos, state) -> {
|
||||
public static int passive(Level level, BlockPos pos, BlockState state) {
|
||||
return BlockHelper.isNotUnheated(state) ? BoilerHeater.PASSIVE_HEAT : BoilerHeater.NO_HEAT;
|
||||
}
|
||||
|
||||
public static int blazeBurner(Level level, BlockPos pos, BlockState state) {
|
||||
HeatLevel value = state.getValue(BlazeBurnerBlock.HEAT_LEVEL);
|
||||
if (value == HeatLevel.NONE) {
|
||||
return NO_HEAT;
|
||||
return BoilerHeater.NO_HEAT;
|
||||
}
|
||||
if (value == HeatLevel.SEETHING) {
|
||||
return 2;
|
||||
|
@ -41,19 +33,6 @@ public class BoilerHeaters {
|
|||
if (value.isAtLeast(HeatLevel.FADING)) {
|
||||
return 1;
|
||||
}
|
||||
return PASSIVE_HEAT;
|
||||
});
|
||||
|
||||
REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(AllBlockTags.PASSIVE_BOILER_HEATERS.tag, PASSIVE_HEATER));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Heater {
|
||||
/**
|
||||
* @return the amount of heat to provide.
|
||||
* @see #NO_HEAT
|
||||
* @see #PASSIVE_HEAT
|
||||
*/
|
||||
float getActiveHeat(Level level, BlockPos pos, BlockState state);
|
||||
return BoilerHeater.PASSIVE_HEAT;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue