-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add api to add custom conductors to trains (#7030)
- Loading branch information
1 parent
4ba5e98
commit e2b65fd
Showing
5 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/simibubi/create/api/contraption/train/TrainConductorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.simibubi.create.api.contraption.train; | ||
|
||
import com.simibubi.create.AllBlocks; | ||
import com.simibubi.create.AllInteractionBehaviours; | ||
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock; | ||
|
||
import com.simibubi.create.content.processing.burner.BlockBasedTrainConductorInteractionBehaviour; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
|
||
/** | ||
* All required methods to make your block a train conductor similar to the blaze burner | ||
*/ | ||
public interface TrainConductorHandler { | ||
|
||
@ApiStatus.Internal | ||
List<TrainConductorHandler> CONDUCTOR_HANDLERS = new ArrayList<>(); | ||
|
||
|
||
|
||
boolean isValidConductor(BlockState state); | ||
|
||
private static void registerHandler(TrainConductorHandler handler) { | ||
CONDUCTOR_HANDLERS.add(handler); | ||
} | ||
|
||
static void registerConductor(ResourceLocation blockRl, Predicate<BlockState> isValidConductor, UpdateScheduleCallback updateScheduleCallback) { | ||
AllInteractionBehaviours.registerBehaviour(blockRl, new BlockBasedTrainConductorInteractionBehaviour(isValidConductor, updateScheduleCallback)); | ||
registerHandler(isValidConductor::test); | ||
} | ||
|
||
@ApiStatus.Internal | ||
static void registerBlazeBurner() { | ||
registerConductor(AllBlocks.BLAZE_BURNER.getId(), blockState -> AllBlocks.BLAZE_BURNER.has(blockState) | ||
&& blockState.getValue(BlazeBurnerBlock.HEAT_LEVEL) != BlazeBurnerBlock.HeatLevel.NONE, UpdateScheduleCallback.EMPTY); | ||
} | ||
|
||
interface UpdateScheduleCallback { | ||
|
||
UpdateScheduleCallback EMPTY = (hasSchedule, blockState, blockStateSetter) -> {}; | ||
|
||
void update(boolean hasSchedule, BlockState currentBlockState, Consumer<BlockState> blockStateSetter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters