2021-08-09 07:21:48 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2021-08-16 09:44:34 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.deployer.DeployerMovingInteraction;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.LeverMovingInteraction;
|
2021-08-09 07:21:48 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.MovingInteractionBehaviour;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.Blocks;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2021-08-16 09:44:34 +02:00
|
|
|
import java.util.function.Supplier;
|
2021-08-09 07:21:48 +02:00
|
|
|
|
|
|
|
public class AllInteractionBehaviours {
|
2021-08-16 09:44:34 +02:00
|
|
|
private static final HashMap<ResourceLocation, Supplier<MovingInteractionBehaviour>> INTERACT_BEHAVIOURS = new HashMap<>();
|
2021-08-09 07:21:48 +02:00
|
|
|
|
2021-08-16 09:44:34 +02:00
|
|
|
public static void addInteractionBehaviour (ResourceLocation loc, Supplier<MovingInteractionBehaviour> behaviour) {
|
2021-08-09 07:21:48 +02:00
|
|
|
if (INTERACT_BEHAVIOURS.containsKey(loc)) {
|
|
|
|
Create.LOGGER.warn("Interaction behaviour for " + loc.toString() + " was overridden");
|
|
|
|
}
|
|
|
|
INTERACT_BEHAVIOURS.put(loc, behaviour);
|
|
|
|
}
|
|
|
|
|
2021-08-16 09:44:34 +02:00
|
|
|
public static void addInteractionBehavioiur (Block block, Supplier<MovingInteractionBehaviour> behaviour) {
|
2021-08-09 07:21:48 +02:00
|
|
|
addInteractionBehaviour(block.getRegistryName(), behaviour);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public static MovingInteractionBehaviour of (ResourceLocation loc) {
|
2021-08-16 09:44:34 +02:00
|
|
|
return (INTERACT_BEHAVIOURS.get(loc) == null) ? null : INTERACT_BEHAVIOURS.get(loc).get();
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public static MovingInteractionBehaviour of (Block block) {
|
|
|
|
return of(block.getRegistryName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean contains (Block block) {
|
|
|
|
return INTERACT_BEHAVIOURS.containsKey(block.getRegistryName());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void register () {
|
2021-08-16 09:44:34 +02:00
|
|
|
addInteractionBehaviour(Blocks.LEVER.getRegistryName(), LeverMovingInteraction::new);
|
|
|
|
addInteractionBehaviour(AllBlocks.DEPLOYER.getId(), DeployerMovingInteraction::new);
|
2021-08-09 07:21:48 +02:00
|
|
|
}
|
|
|
|
}
|