mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-09 22:06:41 +01:00
a6e86520f5
- address some bezier track z fighting - portable storage interfaces now stay connected until a contraption departs - seats can now collect entities when collided with on a contraption - clicking on seats now tries to mount any leashed mobs first - fixed seated entities not staying on seats on disassembly. this probably also fixed issues with sub-contraptions (oops) - fixed portable storage interface not working on train contraptions
70 lines
2.8 KiB
Java
70 lines
2.8 KiB
Java
package com.simibubi.create;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.function.Supplier;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.MovingInteractionBehaviour;
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.DoorMovingInteraction;
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.LeverMovingInteraction;
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.TrapdoorMovingInteraction;
|
|
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;
|
|
|
|
public class AllInteractionBehaviours {
|
|
private static final HashMap<ResourceLocation, Supplier<MovingInteractionBehaviour>> INTERACT_BEHAVIOURS =
|
|
new HashMap<>();
|
|
|
|
public static void addInteractionBehaviour(ResourceLocation loc, Supplier<MovingInteractionBehaviour> behaviour) {
|
|
if (INTERACT_BEHAVIOURS.containsKey(loc))
|
|
Create.LOGGER.warn("Interaction behaviour for " + loc.toString() + " was overridden");
|
|
INTERACT_BEHAVIOURS.put(loc, behaviour);
|
|
}
|
|
|
|
public static void addInteractionBehaviour(Block block, Supplier<MovingInteractionBehaviour> behaviour) {
|
|
addInteractionBehaviour(block.getRegistryName(), behaviour);
|
|
}
|
|
|
|
public static <B extends Block> NonNullConsumer<? super B> addInteractionBehaviour(
|
|
MovingInteractionBehaviour movementBehaviour) {
|
|
return b -> addInteractionBehaviour(b.getRegistryName(), () -> movementBehaviour);
|
|
}
|
|
|
|
@Nullable
|
|
public static MovingInteractionBehaviour of(ResourceLocation loc) {
|
|
return (INTERACT_BEHAVIOURS.get(loc) == null) ? null
|
|
: INTERACT_BEHAVIOURS.get(loc)
|
|
.get();
|
|
}
|
|
|
|
@Nullable
|
|
public static MovingInteractionBehaviour of(Block block) {
|
|
return of(block.getRegistryName());
|
|
}
|
|
|
|
public static boolean contains(Block block) {
|
|
return INTERACT_BEHAVIOURS.containsKey(block.getRegistryName());
|
|
}
|
|
|
|
static void register() {
|
|
addInteractionBehaviour(Blocks.LEVER.getRegistryName(), LeverMovingInteraction::new);
|
|
|
|
// TODO: Scan registry for instanceof (-> modded door support)
|
|
|
|
for (Block trapdoor : ImmutableList.of(Blocks.ACACIA_TRAPDOOR, Blocks.OAK_TRAPDOOR, Blocks.DARK_OAK_TRAPDOOR,
|
|
Blocks.SPRUCE_TRAPDOOR, Blocks.JUNGLE_TRAPDOOR, Blocks.BIRCH_TRAPDOOR, Blocks.WARPED_TRAPDOOR,
|
|
Blocks.CRIMSON_TRAPDOOR)) {
|
|
addInteractionBehaviour(trapdoor.getRegistryName(), TrapdoorMovingInteraction::new);
|
|
}
|
|
|
|
for (Block door : ImmutableList.of(Blocks.ACACIA_DOOR, Blocks.OAK_DOOR, Blocks.DARK_OAK_DOOR,
|
|
Blocks.SPRUCE_DOOR, Blocks.JUNGLE_DOOR, Blocks.BIRCH_DOOR, Blocks.WARPED_DOOR, Blocks.CRIMSON_DOOR)) {
|
|
addInteractionBehaviour(door.getRegistryName(), DoorMovingInteraction::new);
|
|
}
|
|
}
|
|
}
|