2021-08-09 07:21:48 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2021-10-21 20:46:26 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2021-08-16 09:44:34 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.deployer.DeployerMovingInteraction;
|
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;
|
2021-08-09 07:21:48 +02:00
|
|
|
|
2021-11-02 00:08:20 +01:00
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
2021-08-09 07:21:48 +02:00
|
|
|
|
|
|
|
public class AllInteractionBehaviours {
|
2021-10-21 20:46:26 +02:00
|
|
|
private static final HashMap<ResourceLocation, Supplier<MovingInteractionBehaviour>> INTERACT_BEHAVIOURS =
|
|
|
|
new HashMap<>();
|
2021-08-09 07:21:48 +02:00
|
|
|
|
2021-10-21 20:46:26 +02:00
|
|
|
public static void addInteractionBehaviour(ResourceLocation loc, Supplier<MovingInteractionBehaviour> behaviour) {
|
|
|
|
if (INTERACT_BEHAVIOURS.containsKey(loc))
|
2021-08-09 07:21:48 +02:00
|
|
|
Create.LOGGER.warn("Interaction behaviour for " + loc.toString() + " was overridden");
|
|
|
|
INTERACT_BEHAVIOURS.put(loc, behaviour);
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:46:26 +02:00
|
|
|
public static void addInteractionBehaviour(Block block, Supplier<MovingInteractionBehaviour> behaviour) {
|
2021-08-09 07:21:48 +02:00
|
|
|
addInteractionBehaviour(block.getRegistryName(), behaviour);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2021-10-21 20:46:26 +02:00
|
|
|
public static MovingInteractionBehaviour of(ResourceLocation loc) {
|
|
|
|
return (INTERACT_BEHAVIOURS.get(loc) == null) ? null
|
|
|
|
: INTERACT_BEHAVIOURS.get(loc)
|
|
|
|
.get();
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2021-10-21 20:46:26 +02:00
|
|
|
public static MovingInteractionBehaviour of(Block block) {
|
2021-08-09 07:21:48 +02:00
|
|
|
return of(block.getRegistryName());
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:46:26 +02:00
|
|
|
public static boolean contains(Block block) {
|
2021-08-09 07:21:48 +02:00
|
|
|
return INTERACT_BEHAVIOURS.containsKey(block.getRegistryName());
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:46:26 +02:00
|
|
|
static void register() {
|
2021-08-16 09:44:34 +02:00
|
|
|
addInteractionBehaviour(Blocks.LEVER.getRegistryName(), LeverMovingInteraction::new);
|
|
|
|
addInteractionBehaviour(AllBlocks.DEPLOYER.getId(), DeployerMovingInteraction::new);
|
2021-10-21 20:46:26 +02:00
|
|
|
|
|
|
|
// TODO: Scan registry for instanceof (-> modded door support)
|
|
|
|
|
|
|
|
for (Block trapdoor : ImmutableList.of(Blocks.ACACIA_TRAPDOOR, Blocks.OAK_TRAPDOOR, Blocks.DARK_OAK_TRAPDOOR,
|
|
|
|
Blocks.SPRUCE_TRAPDOOR, Blocks.JUNGLE_TRAPDOOR, Blocks.BIRCH_TRAPDOOR, Blocks.WARPED_TRAPDOOR,
|
|
|
|
Blocks.CRIMSON_TRAPDOOR)) {
|
|
|
|
addInteractionBehaviour(trapdoor.getRegistryName(), TrapdoorMovingInteraction::new);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Block door : ImmutableList.of(Blocks.ACACIA_DOOR, Blocks.OAK_DOOR, Blocks.DARK_OAK_DOOR,
|
|
|
|
Blocks.SPRUCE_DOOR, Blocks.JUNGLE_DOOR, Blocks.BIRCH_DOOR, Blocks.WARPED_DOOR, Blocks.CRIMSON_DOOR)) {
|
|
|
|
addInteractionBehaviour(door.getRegistryName(), DoorMovingInteraction::new);
|
|
|
|
}
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
}
|