Merge pull request #9 from Creators-of-Create/jay/mc1.20.1/contraption-movement-setting-api

Make Contraption Movement Settings API
This commit is contained in:
IThundxr 2025-02-20 08:47:50 -05:00 committed by GitHub
commit 1888998553
Failed to generate hash of commit
7 changed files with 100 additions and 57 deletions

View file

@ -0,0 +1,17 @@
package com.simibubi.create;
import com.simibubi.create.api.contraption.ContraptionMovementSetting;
import com.simibubi.create.infrastructure.config.AllConfigs;
import net.minecraft.world.level.block.Blocks;
public class AllContraptionMovementSettings {
public static void registerDefaults() {
ContraptionMovementSetting.REGISTRY.register(Blocks.SPAWNER, () -> AllConfigs.server().kinetics.spawnerMovement.get());
ContraptionMovementSetting.REGISTRY.register(Blocks.BUDDING_AMETHYST, () -> AllConfigs.server().kinetics.amethystMovement.get());
ContraptionMovementSetting.REGISTRY.register(Blocks.OBSIDIAN, () -> AllConfigs.server().kinetics.obsidianMovement.get());
ContraptionMovementSetting.REGISTRY.register(Blocks.CRYING_OBSIDIAN, () -> AllConfigs.server().kinetics.obsidianMovement.get());
ContraptionMovementSetting.REGISTRY.register(Blocks.RESPAWN_ANCHOR, () -> AllConfigs.server().kinetics.obsidianMovement.get());
ContraptionMovementSetting.REGISTRY.register(Blocks.REINFORCED_DEEPSLATE, () -> AllConfigs.server().kinetics.reinforcedDeepslateMovement.get());
}
}

View file

@ -11,7 +11,6 @@ import com.simibubi.create.api.behaviour.spouting.BlockSpoutingBehaviour;
import com.simibubi.create.compat.Mods;
import com.simibubi.create.compat.computercraft.ComputerCraftProxy;
import com.simibubi.create.compat.curios.Curios;
import com.simibubi.create.content.contraptions.ContraptionMovementSetting;
import com.simibubi.create.content.decoration.palettes.AllPaletteBlocks;
import com.simibubi.create.content.equipment.potatoCannon.BuiltinPotatoProjectileTypes;
import com.simibubi.create.content.fluids.tank.BoilerHeaters;
@ -172,7 +171,7 @@ public class Create {
BlockSpoutingBehaviour.registerDefaults();
AllMovementBehaviours.registerDefaults();
AllInteractionBehaviours.registerDefaults();
ContraptionMovementSetting.registerDefaults();
AllContraptionMovementSettings.registerDefaults();
// --
AllAdvancements.register();

View file

@ -0,0 +1,75 @@
package com.simibubi.create.api.contraption;
import java.util.Collection;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.simibubi.create.api.registry.SimpleRegistry;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraftforge.common.extensions.IForgeBlock;
/**
* Defines whether a block is movable by contraptions.
* The registry uses suppliers, so the setting of a block can change. This is useful for config options.
*/
public enum ContraptionMovementSetting {
/**
* Block is fully movable with no restrictions.
*/
MOVABLE,
/**
* Block can be mounted and moved, but if it's on a minecart contraption, the contraption cannot be picked up.
*/
NO_PICKUP,
/**
* Block cannot ever be moved by a contraption.
*/
UNMOVABLE;
public static final SimpleRegistry<Block, Supplier<ContraptionMovementSetting>> REGISTRY = SimpleRegistry.create();
/**
* Shortcut that gets the block of the given state.
*/
@Nullable
public static ContraptionMovementSetting get(BlockState state) {
return get(state.getBlock());
}
/**
* Get the current movement setting of the given block.
*/
@Nullable
public static ContraptionMovementSetting get(Block block) {
if (block instanceof MovementSettingProvider provider)
return provider.getContraptionMovementSetting();
Supplier<ContraptionMovementSetting> supplier = REGISTRY.get(block);
return supplier == null ? null : supplier.get();
}
/**
* Check if any of the blocks in the collection match the given setting.
*/
public static boolean anyAre(Collection<StructureTemplate.StructureBlockInfo> blocks, ContraptionMovementSetting setting) {
return blocks.stream().anyMatch(b -> get(b.state().getBlock()) == setting);
}
/**
* Check if any of the blocks in the collection forbid pickup.
*/
public static boolean isNoPickup(Collection<StructureTemplate.StructureBlockInfo> blocks) {
return anyAre(blocks, ContraptionMovementSetting.NO_PICKUP);
}
/**
* Interface that may optionally be implemented on a Block implementation which will be queried instead of the registry.
*/
public interface MovementSettingProvider extends IForgeBlock {
ContraptionMovementSetting getContraptionMovementSetting();
}
}

View file

@ -1,8 +1,12 @@
package com.simibubi.create.content.contraptions;
import java.util.ArrayList;
import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllTags.AllBlockTags;
import com.simibubi.create.api.connectivity.ConnectivityHandler;
import com.simibubi.create.api.contraption.ContraptionMovementSetting;
import com.simibubi.create.content.contraptions.actors.AttachedActorBlock;
import com.simibubi.create.content.contraptions.actors.harvester.HarvesterBlock;
import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceBlock;
@ -30,6 +34,7 @@ import com.simibubi.create.content.redstone.link.RedstoneLinkBlock;
import com.simibubi.create.content.trains.bogey.AbstractBogeyBlock;
import com.simibubi.create.content.trains.station.StationBlock;
import com.simibubi.create.content.trains.track.ITrackBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
@ -62,9 +67,6 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.material.PushReaction;
import java.util.ArrayList;
import java.util.List;
public class BlockMovementChecks {
private static final List<MovementNecessaryCheck> MOVEMENT_NECESSARY_CHECKS = new ArrayList<>();

View file

@ -1,50 +0,0 @@
package com.simibubi.create.content.contraptions;
import java.util.Collection;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.simibubi.create.api.registry.SimpleRegistry;
import com.simibubi.create.infrastructure.config.AllConfigs;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraftforge.common.extensions.IForgeBlock;
public enum ContraptionMovementSetting {
MOVABLE, NO_PICKUP, UNMOVABLE;
public static final SimpleRegistry<Block, Supplier<ContraptionMovementSetting>> REGISTRY = SimpleRegistry.create();
@Nullable
public static ContraptionMovementSetting get(Block block) {
if (block instanceof IMovementSettingProvider provider)
return provider.getContraptionMovementSetting();
Supplier<ContraptionMovementSetting> supplier = REGISTRY.get(block);
return supplier == null ? null : supplier.get();
}
public static boolean allAre(Collection<StructureTemplate.StructureBlockInfo> blocks, ContraptionMovementSetting are) {
return blocks.stream().anyMatch(b -> get(b.state().getBlock()) == are);
}
public static boolean isNoPickup(Collection<StructureTemplate.StructureBlockInfo> blocks) {
return allAre(blocks, ContraptionMovementSetting.NO_PICKUP);
}
public static void registerDefaults() {
REGISTRY.register(Blocks.SPAWNER, () -> AllConfigs.server().kinetics.spawnerMovement.get());
REGISTRY.register(Blocks.BUDDING_AMETHYST, () -> AllConfigs.server().kinetics.amethystMovement.get());
REGISTRY.register(Blocks.OBSIDIAN, () -> AllConfigs.server().kinetics.obsidianMovement.get());
REGISTRY.register(Blocks.CRYING_OBSIDIAN, () -> AllConfigs.server().kinetics.obsidianMovement.get());
REGISTRY.register(Blocks.RESPAWN_ANCHOR, () -> AllConfigs.server().kinetics.obsidianMovement.get());
REGISTRY.register(Blocks.REINFORCED_DEEPSLATE, () -> AllConfigs.server().kinetics.reinforcedDeepslateMovement.get());
}
public interface IMovementSettingProvider extends IForgeBlock {
ContraptionMovementSetting getContraptionMovementSetting();
}
}

View file

@ -8,9 +8,9 @@ import org.apache.commons.lang3.tuple.MutablePair;
import com.simibubi.create.AllItems;
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
import com.simibubi.create.api.contraption.ContraptionMovementSetting;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import com.simibubi.create.content.contraptions.Contraption;
import com.simibubi.create.content.contraptions.ContraptionMovementSetting;
import com.simibubi.create.content.contraptions.OrientedContraptionEntity;
import com.simibubi.create.content.contraptions.actors.psi.PortableStorageInterfaceMovement;
import com.simibubi.create.content.contraptions.behaviour.MovementContext;

View file

@ -1,6 +1,6 @@
package com.simibubi.create.infrastructure.config;
import com.simibubi.create.content.contraptions.ContraptionMovementSetting;
import com.simibubi.create.api.contraption.ContraptionMovementSetting;
import net.createmod.catnip.config.ConfigBase;