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

80 lines
2.8 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.List;
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.simibubi.create.foundation.utility.CreateRegistry;
2020-08-08 23:16:22 +02:00
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import net.minecraft.resources.ResourceLocation;
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.ForgeRegistries;
import net.minecraftforge.registries.IRegistryDelegate;
2020-08-08 23:16:22 +02:00
public class AllMovementBehaviours {
private static final CreateRegistry<Block, MovementBehaviour> BLOCK_BEHAVIOURS = new CreateRegistry<>(ForgeRegistries.BLOCKS);
private static final List<BehaviourProvider> GLOBAL_BEHAVIOURS = new ArrayList<>();
2020-08-08 23:16:22 +02:00
public static void registerBehaviour(ResourceLocation block, MovementBehaviour behaviour) {
BLOCK_BEHAVIOURS.register(block, behaviour);
}
public static void registerBehaviour(Block block, MovementBehaviour behaviour) {
BLOCK_BEHAVIOURS.register(block, behaviour);
}
@Deprecated(forRemoval = true)
public static void registerBehaviour(IRegistryDelegate<Block> block, MovementBehaviour behaviour) {
registerBehaviour(block.name(), 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());
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, behaviour);
2020-08-08 23:16:22 +02:00
}
static void registerDefaults() {
registerBehaviour(Blocks.BELL, new BellMovementBehaviour());
registerBehaviour(Blocks.CAMPFIRE, new CampfireMovementBehaviour());
DispenserMovementBehaviour.gatherMovedDispenseItemBehaviours();
registerBehaviour(Blocks.DISPENSER, new DispenserMovementBehaviour());
registerBehaviour(Blocks.DROPPER, 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
}