2021-08-09 07:21:48 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
import java.util.ArrayList;
|
2021-10-21 20:46:26 +02:00
|
|
|
import java.util.HashMap;
|
2022-07-09 01:15:19 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2021-10-21 20:46:26 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-10-21 20:46:26 +02:00
|
|
|
|
2021-08-09 07:21:48 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.MovingInteractionBehaviour;
|
2021-10-21 20:46:26 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.DoorMovingInteraction;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.LeverMovingInteraction;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.TrapdoorMovingInteraction;
|
2022-02-06 04:17:18 +01:00
|
|
|
import com.tterrag.registrate.util.nullness.NonNullConsumer;
|
2021-08-09 07:21:48 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
import net.minecraft.tags.BlockTags;
|
2021-11-02 00:08:20 +01:00
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
2022-07-09 01:15:19 +02:00
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraftforge.registries.IRegistryDelegate;
|
2021-08-09 07:21:48 +02:00
|
|
|
|
|
|
|
public class AllInteractionBehaviours {
|
2022-07-09 01:15:19 +02:00
|
|
|
private static final Map<IRegistryDelegate<Block>, MovingInteractionBehaviour> BLOCK_BEHAVIOURS = new HashMap<>();
|
|
|
|
private static final List<BehaviourProvider> GLOBAL_BEHAVIOURS = new ArrayList<>();
|
2021-08-09 07:21:48 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public static void registerBehaviour(IRegistryDelegate<Block> block, MovingInteractionBehaviour provider) {
|
|
|
|
BLOCK_BEHAVIOURS.put(block, provider);
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public static void registerBehaviourProvider(BehaviourProvider provider) {
|
|
|
|
GLOBAL_BEHAVIOURS.add(provider);
|
2022-02-06 04:17:18 +01:00
|
|
|
}
|
|
|
|
|
2021-08-09 07:21:48 +02:00
|
|
|
@Nullable
|
2022-07-09 01:15:19 +02:00
|
|
|
public static MovingInteractionBehaviour getBehaviour(BlockState state) {
|
|
|
|
MovingInteractionBehaviour behaviour = BLOCK_BEHAVIOURS.get(state.getBlock().delegate);
|
|
|
|
if (behaviour != null) {
|
|
|
|
return behaviour;
|
|
|
|
}
|
2021-08-09 07:21:48 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
for (BehaviourProvider provider : GLOBAL_BEHAVIOURS) {
|
|
|
|
behaviour = provider.getBehaviour(state);
|
|
|
|
if (behaviour != null) {
|
|
|
|
return behaviour;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public static <B extends Block> NonNullConsumer<? super B> interactionBehaviour(
|
|
|
|
MovingInteractionBehaviour behaviour) {
|
|
|
|
return b -> registerBehaviour(b.delegate, behaviour);
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
static void registerDefaults() {
|
|
|
|
registerBehaviour(Blocks.LEVER.delegate, new LeverMovingInteraction());
|
2021-10-21 20:46:26 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
DoorMovingInteraction doorBehaviour = new DoorMovingInteraction();
|
|
|
|
registerBehaviourProvider(state -> {
|
|
|
|
if (state.is(BlockTags.WOODEN_DOORS)) {
|
|
|
|
return doorBehaviour;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2022-02-06 04:17:18 +01:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
TrapdoorMovingInteraction trapdoorBehaviour = new TrapdoorMovingInteraction();
|
|
|
|
registerBehaviourProvider(state -> {
|
|
|
|
if (state.is(BlockTags.WOODEN_TRAPDOORS)) {
|
|
|
|
return trapdoorBehaviour;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
}
|
2021-10-21 20:46:26 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public interface BehaviourProvider {
|
|
|
|
@Nullable
|
|
|
|
MovingInteractionBehaviour getBehaviour(BlockState state);
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
}
|