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

65 lines
2.5 KiB
Java
Raw Normal View History

2020-08-08 23:16:22 +02:00
package com.simibubi.create;
import java.util.HashMap;
import javax.annotation.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.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.resources.ResourceLocation;
2020-08-08 23:16:22 +02:00
public class AllMovementBehaviours {
private static final HashMap<ResourceLocation, MovementBehaviour> MOVEMENT_BEHAVIOURS = new HashMap<>();
2020-08-08 23:16:22 +02:00
public static void addMovementBehaviour(ResourceLocation resourceLocation, MovementBehaviour movementBehaviour) {
if (MOVEMENT_BEHAVIOURS.containsKey(resourceLocation))
Create.LOGGER.warn("Movement behaviour for " + resourceLocation.toString() + " was overridden");
MOVEMENT_BEHAVIOURS.put(resourceLocation, movementBehaviour);
2020-08-08 23:16:22 +02:00
}
public static void addMovementBehaviour(Block block, MovementBehaviour movementBehaviour) {
addMovementBehaviour(block.getRegistryName(), movementBehaviour);
}
2020-08-08 23:16:22 +02:00
@Nullable
public static MovementBehaviour of(ResourceLocation resourceLocation) {
return MOVEMENT_BEHAVIOURS.getOrDefault(resourceLocation, null);
2020-08-08 23:16:22 +02:00
}
@Nullable
public static MovementBehaviour of(Block block) {
return of(block.getRegistryName());
}
@Nullable
public static MovementBehaviour of(BlockState state) {
return of(state.getBlock());
2020-08-08 23:16:22 +02:00
}
public static boolean contains(Block block) {
return MOVEMENT_BEHAVIOURS.containsKey(block.getRegistryName());
2020-08-08 23:16:22 +02:00
}
public static <B extends Block> NonNullConsumer<? super B> addMovementBehaviour(
MovementBehaviour movementBehaviour) {
return b -> addMovementBehaviour(b.getRegistryName(), movementBehaviour);
}
2020-08-09 12:40:33 +02:00
static void register() {
addMovementBehaviour(Blocks.BELL, new BellMovementBehaviour());
addMovementBehaviour(Blocks.CAMPFIRE, new CampfireMovementBehaviour());
DispenserMovementBehaviour.gatherMovedDispenseItemBehaviours();
addMovementBehaviour(Blocks.DISPENSER, new DispenserMovementBehaviour());
addMovementBehaviour(Blocks.DROPPER, new DropperMovementBehaviour());
2020-08-09 12:40:33 +02:00
}
2020-08-08 23:16:22 +02:00
}