mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Contraption movement setting API
- Renamed SpawnerMovementSetting to ContraptionMovementSetting and moved it to its own class - Added a contraption movement setting registry - Made checks previously checking only spawner movement setting and the block being a spawner to check using ContraptionMovementSetting.get(block)
This commit is contained in:
parent
f1701ae784
commit
30cef7025e
4 changed files with 63 additions and 22 deletions
|
@ -29,8 +29,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pul
|
|||
import com.simibubi.create.content.contraptions.fluids.tank.FluidTankBlock;
|
||||
import com.simibubi.create.content.contraptions.fluids.tank.FluidTankConnectivityHandler;
|
||||
import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkBlock;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.config.CKinetics;
|
||||
|
||||
import com.simibubi.create.foundation.config.ContraptionMovementSetting;
|
||||
|
||||
import net.minecraft.block.AbstractPressurePlateBlock;
|
||||
import net.minecraft.block.AbstractRailBlock;
|
||||
|
@ -50,7 +50,6 @@ import net.minecraft.block.LadderBlock;
|
|||
import net.minecraft.block.RedstoneDiodeBlock;
|
||||
import net.minecraft.block.RedstoneWallTorchBlock;
|
||||
import net.minecraft.block.RedstoneWireBlock;
|
||||
import net.minecraft.block.SpawnerBlock;
|
||||
import net.minecraft.block.StandingSignBlock;
|
||||
import net.minecraft.block.TorchBlock;
|
||||
import net.minecraft.block.WallSignBlock;
|
||||
|
@ -195,8 +194,7 @@ public class BlockMovementChecks {
|
|||
return false;
|
||||
if (state.getBlock().getTags().contains(NON_MOVABLE))
|
||||
return false;
|
||||
if (AllConfigs.SERVER.kinetics.spawnerMovement.get() == CKinetics.SpawnerMovementSetting.UNMOVABLE
|
||||
&& block instanceof SpawnerBlock)
|
||||
if (ContraptionMovementSetting.get(state.getBlock()) == ContraptionMovementSetting.UNMOVABLE)
|
||||
return false;
|
||||
|
||||
// Move controllers only when they aren't moving
|
||||
|
|
|
@ -11,15 +11,13 @@ import com.simibubi.create.AllItems;
|
|||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.config.CKinetics;
|
||||
import com.simibubi.create.foundation.config.ContraptionMovementSetting;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
||||
|
||||
import net.minecraft.block.AbstractRailBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.SpawnerBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
|
@ -218,14 +216,10 @@ public class MinecartContraptionItem extends Item {
|
|||
return;
|
||||
OrientedContraptionEntity contraption = (OrientedContraptionEntity) passengers.get(0);
|
||||
|
||||
if (AllConfigs.SERVER.kinetics.spawnerMovement.get() == CKinetics.SpawnerMovementSetting.NO_PICKUP) {
|
||||
Contraption blocks = contraption.getContraption();
|
||||
if (blocks != null && blocks.getBlocks().values().stream()
|
||||
.anyMatch(i -> i.state.getBlock() instanceof SpawnerBlock)) {
|
||||
player.displayClientMessage(Lang.translate("contraption.minecart_contraption_illegal_pickup")
|
||||
.withStyle(TextFormatting.RED), true);
|
||||
return;
|
||||
}
|
||||
if(ContraptionMovementSetting.isNoPickup(contraption.getContraption().getBlocks().values())) {
|
||||
player.displayClientMessage(Lang.translate("contraption.minecart_contraption_illegal_pickup")
|
||||
.withStyle(TextFormatting.RED), true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getWorld().isClientSide) {
|
||||
|
|
|
@ -35,8 +35,8 @@ public class CKinetics extends ConfigBase {
|
|||
public ConfigInt maxPistonPoles = i(64, 1, "maxPistonPoles", Comments.maxPistonPoles);
|
||||
public ConfigInt maxRopeLength = i(128, 1, "maxRopeLength", Comments.maxRopeLength);
|
||||
public ConfigInt maxCartCouplingLength = i(32, 1, "maxCartCouplingLength", Comments.maxCartCouplingLength);
|
||||
public ConfigEnum<SpawnerMovementSetting> spawnerMovement =
|
||||
e(SpawnerMovementSetting.NO_PICKUP, "movableSpawners", Comments.spawnerMovement);
|
||||
public ConfigEnum<ContraptionMovementSetting> spawnerMovement =
|
||||
e(ContraptionMovementSetting.NO_PICKUP, "movableSpawners", Comments.spawnerMovement);
|
||||
|
||||
public CStress stressValues = nested(1, CStress::new, Comments.stress);
|
||||
|
||||
|
@ -103,8 +103,4 @@ public class CKinetics extends ConfigBase {
|
|||
ALL, CREEPERS, NONE
|
||||
}
|
||||
|
||||
public enum SpawnerMovementSetting {
|
||||
MOVABLE, NO_PICKUP, UNMOVABLE
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.simibubi.create.foundation.config;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.gen.feature.template.Template;
|
||||
import net.minecraftforge.common.extensions.IForgeBlock;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum ContraptionMovementSetting {
|
||||
MOVABLE, NO_PICKUP, UNMOVABLE;
|
||||
|
||||
private static HashMap<ResourceLocation, Supplier<ContraptionMovementSetting>> registry = new HashMap<>();
|
||||
|
||||
public static void register(ResourceLocation id, Supplier<ContraptionMovementSetting> setting) {
|
||||
registry.put(id, setting);
|
||||
}
|
||||
|
||||
static {
|
||||
// config isnt registered at this point, so im using lambda instead of a method reference
|
||||
register(Blocks.SPAWNER.getRegistryName(), () -> AllConfigs.SERVER.kinetics.spawnerMovement.get());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ContraptionMovementSetting get(Block block) {
|
||||
if (block instanceof IMovementSettingProvider)
|
||||
return ((IMovementSettingProvider) block).getContraptionMovementSetting();
|
||||
return get(block.getRegistryName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ContraptionMovementSetting get(ResourceLocation id) {
|
||||
Supplier<ContraptionMovementSetting> supplier = registry.get(id);
|
||||
return supplier == null ? null : supplier.get();
|
||||
}
|
||||
|
||||
protected static boolean allAre(Collection<Template.BlockInfo> blocks, ContraptionMovementSetting are) {
|
||||
return blocks.stream().anyMatch(b -> get(b.state.getBlock()) == are);
|
||||
}
|
||||
|
||||
public static boolean isNoPickup(Collection<Template.BlockInfo> blocks) {
|
||||
return allAre(blocks, ContraptionMovementSetting.NO_PICKUP);
|
||||
}
|
||||
|
||||
public interface IMovementSettingProvider extends IForgeBlock {
|
||||
ContraptionMovementSetting getContraptionMovementSetting();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue