2020-08-08 23:16:22 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
import java.util.ArrayList;
|
2020-08-09 13:32:08 +02:00
|
|
|
import java.util.HashMap;
|
2022-07-09 01:15:19 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2020-08-09 13:32:08 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-08-09 13:32:08 +02:00
|
|
|
|
2020-08-09 12:40:33 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour;
|
2020-08-09 13:32:08 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.actors.CampfireMovementBehaviour;
|
2020-09-01 22:41:17 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.actors.dispenser.DispenserMovementBehaviour;
|
|
|
|
import com.simibubi.create.content.contraptions.components.actors.dispenser.DropperMovementBehaviour;
|
2020-08-08 23:16:22 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
|
|
|
|
import com.tterrag.registrate.util.nullness.NonNullConsumer;
|
2020-08-09 13:32:08 +02:00
|
|
|
|
2021-11-02 00:08:20 +01:00
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2022-07-09 01:15:19 +02:00
|
|
|
import net.minecraftforge.registries.IRegistryDelegate;
|
2020-08-08 23:16:22 +02:00
|
|
|
|
|
|
|
public class AllMovementBehaviours {
|
2022-07-09 01:15:19 +02:00
|
|
|
private static final Map<IRegistryDelegate<Block>, MovementBehaviour> BLOCK_BEHAVIOURS = new HashMap<>();
|
|
|
|
private static final List<BehaviourProvider> GLOBAL_BEHAVIOURS = new ArrayList<>();
|
2020-08-08 23:16:22 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public static void registerBehaviour(IRegistryDelegate<Block> block, MovementBehaviour behaviour) {
|
|
|
|
BLOCK_BEHAVIOURS.put(block, behaviour);
|
2020-08-08 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public static void registerBehaviourProvider(BehaviourProvider provider) {
|
|
|
|
GLOBAL_BEHAVIOURS.add(provider);
|
2020-08-09 13:32:08 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 23:16:22 +02:00
|
|
|
@Nullable
|
2022-07-09 01:15:19 +02:00
|
|
|
public static MovementBehaviour getBehaviour(BlockState state) {
|
|
|
|
MovementBehaviour behaviour = BLOCK_BEHAVIOURS.get(state.getBlock().delegate);
|
|
|
|
if (behaviour != null) {
|
|
|
|
return behaviour;
|
|
|
|
}
|
2020-08-08 23:16:22 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
for (BehaviourProvider provider : GLOBAL_BEHAVIOURS) {
|
|
|
|
behaviour = provider.getBehaviour(state);
|
|
|
|
if (behaviour != null) {
|
|
|
|
return behaviour;
|
|
|
|
}
|
|
|
|
}
|
2021-04-08 19:22:11 +02:00
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
return null;
|
2020-08-08 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
public static <B extends Block> NonNullConsumer<? super B> movementBehaviour(
|
|
|
|
MovementBehaviour behaviour) {
|
|
|
|
return b -> registerBehaviour(b.delegate, behaviour);
|
2020-08-08 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
2022-07-09 01:15:19 +02:00
|
|
|
static void registerDefaults() {
|
|
|
|
registerBehaviour(Blocks.BELL.delegate, new BellMovementBehaviour());
|
|
|
|
registerBehaviour(Blocks.CAMPFIRE.delegate, new CampfireMovementBehaviour());
|
2020-09-01 22:41:17 +02:00
|
|
|
|
|
|
|
DispenserMovementBehaviour.gatherMovedDispenseItemBehaviours();
|
2022-07-09 01:15:19 +02:00
|
|
|
registerBehaviour(Blocks.DISPENSER.delegate, new DispenserMovementBehaviour());
|
|
|
|
registerBehaviour(Blocks.DROPPER.delegate, new DropperMovementBehaviour());
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface BehaviourProvider {
|
|
|
|
@Nullable
|
|
|
|
MovementBehaviour getBehaviour(BlockState state);
|
2020-08-09 12:40:33 +02:00
|
|
|
}
|
2020-08-08 23:16:22 +02:00
|
|
|
}
|