2020-08-08 23:16:22 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2020-08-09 13:32:08 +02:00
|
|
|
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;
|
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 06:18:30 +01:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
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;
|
2020-08-08 23:16:22 +02:00
|
|
|
|
|
|
|
public class AllMovementBehaviours {
|
2021-05-23 03:00:10 +02:00
|
|
|
private static final HashMap<ResourceLocation, MovementBehaviour> MOVEMENT_BEHAVIOURS = new HashMap<>();
|
2020-08-08 23:16:22 +02:00
|
|
|
|
2020-08-09 14:36:07 +02:00
|
|
|
public static void addMovementBehaviour(ResourceLocation resourceLocation, MovementBehaviour movementBehaviour) {
|
2021-05-23 03:00:10 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-08-09 13:32:08 +02:00
|
|
|
public static void addMovementBehaviour(Block block, MovementBehaviour movementBehaviour) {
|
|
|
|
addMovementBehaviour(block.getRegistryName(), movementBehaviour);
|
|
|
|
}
|
|
|
|
|
2020-08-08 23:16:22 +02:00
|
|
|
@Nullable
|
2020-11-19 21:07:32 +01:00
|
|
|
public static MovementBehaviour of(ResourceLocation resourceLocation) {
|
2021-05-23 03:00:10 +02:00
|
|
|
return MOVEMENT_BEHAVIOURS.getOrDefault(resourceLocation, null);
|
2020-08-08 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2020-11-19 21:07:32 +01:00
|
|
|
public static MovementBehaviour of(Block block) {
|
|
|
|
return of(block.getRegistryName());
|
|
|
|
}
|
2021-04-08 19:22:11 +02:00
|
|
|
|
2020-11-19 21:07:32 +01:00
|
|
|
@Nullable
|
|
|
|
public static MovementBehaviour of(BlockState state) {
|
|
|
|
return of(state.getBlock());
|
2020-08-08 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
2020-11-19 21:07:32 +01:00
|
|
|
public static boolean contains(Block block) {
|
2021-05-23 03:00:10 +02:00
|
|
|
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() {
|
2020-08-09 13:32:08 +02:00
|
|
|
addMovementBehaviour(Blocks.BELL, new BellMovementBehaviour());
|
|
|
|
addMovementBehaviour(Blocks.CAMPFIRE, new CampfireMovementBehaviour());
|
2020-09-01 22:41:17 +02:00
|
|
|
|
2022-03-22 00:29:46 +01:00
|
|
|
DispenserMovementBehaviour.gatherMovedDispenseItemBehaviours();
|
2020-09-01 22:41:17 +02:00
|
|
|
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
|
|
|
}
|