Create/src/main/java/com/simibubi/create/AllMovementBehaviours.java

70 lines
2.4 KiB
Java
Raw Normal View History

2020-08-08 23:16:22 +02:00
package com.simibubi.create;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
2020-08-09 12:40:33 +02:00
import com.simibubi.create.content.contraptions.components.actors.BellMovementBehaviour;
import com.simibubi.create.content.contraptions.components.actors.CampfireMovementBehaviour;
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;
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;
import net.minecraftforge.registries.IRegistryDelegate;
2020-08-08 23:16:22 +02:00
public class AllMovementBehaviours {
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
public static void registerBehaviour(IRegistryDelegate<Block> block, MovementBehaviour behaviour) {
BLOCK_BEHAVIOURS.put(block, behaviour);
2020-08-08 23:16:22 +02:00
}
public static void registerBehaviourProvider(BehaviourProvider provider) {
GLOBAL_BEHAVIOURS.add(provider);
}
2020-08-08 23:16:22 +02:00
@Nullable
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
for (BehaviourProvider provider : GLOBAL_BEHAVIOURS) {
behaviour = provider.getBehaviour(state);
if (behaviour != null) {
return behaviour;
}
}
return null;
2020-08-08 23:16:22 +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
}
static void registerDefaults() {
registerBehaviour(Blocks.BELL.delegate, new BellMovementBehaviour());
registerBehaviour(Blocks.CAMPFIRE.delegate, new CampfireMovementBehaviour());
DispenserMovementBehaviour.gatherMovedDispenseItemBehaviours();
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
}