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:
kotakotik22 2021-08-16 07:57:10 +03:00
parent f1701ae784
commit 30cef7025e
4 changed files with 63 additions and 22 deletions

View file

@ -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.FluidTankBlock;
import com.simibubi.create.content.contraptions.fluids.tank.FluidTankConnectivityHandler; import com.simibubi.create.content.contraptions.fluids.tank.FluidTankConnectivityHandler;
import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkBlock; 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.AbstractPressurePlateBlock;
import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.AbstractRailBlock;
@ -50,7 +50,6 @@ import net.minecraft.block.LadderBlock;
import net.minecraft.block.RedstoneDiodeBlock; import net.minecraft.block.RedstoneDiodeBlock;
import net.minecraft.block.RedstoneWallTorchBlock; import net.minecraft.block.RedstoneWallTorchBlock;
import net.minecraft.block.RedstoneWireBlock; import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.block.SpawnerBlock;
import net.minecraft.block.StandingSignBlock; import net.minecraft.block.StandingSignBlock;
import net.minecraft.block.TorchBlock; import net.minecraft.block.TorchBlock;
import net.minecraft.block.WallSignBlock; import net.minecraft.block.WallSignBlock;
@ -195,8 +194,7 @@ public class BlockMovementChecks {
return false; return false;
if (state.getBlock().getTags().contains(NON_MOVABLE)) if (state.getBlock().getTags().contains(NON_MOVABLE))
return false; return false;
if (AllConfigs.SERVER.kinetics.spawnerMovement.get() == CKinetics.SpawnerMovementSetting.UNMOVABLE if (ContraptionMovementSetting.get(state.getBlock()) == ContraptionMovementSetting.UNMOVABLE)
&& block instanceof SpawnerBlock)
return false; return false;
// Move controllers only when they aren't moving // Move controllers only when they aren't moving

View file

@ -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.AbstractContraptionEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.ContraptionMovementSetting;
import com.simibubi.create.foundation.config.CKinetics;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.NBTHelper;
import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.AbstractRailBlock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.DispenserBlock; import net.minecraft.block.DispenserBlock;
import net.minecraft.block.SpawnerBlock;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.dispenser.DefaultDispenseItemBehavior; import net.minecraft.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.dispenser.IBlockSource; import net.minecraft.dispenser.IBlockSource;
@ -218,14 +216,10 @@ public class MinecartContraptionItem extends Item {
return; return;
OrientedContraptionEntity contraption = (OrientedContraptionEntity) passengers.get(0); OrientedContraptionEntity contraption = (OrientedContraptionEntity) passengers.get(0);
if (AllConfigs.SERVER.kinetics.spawnerMovement.get() == CKinetics.SpawnerMovementSetting.NO_PICKUP) { if(ContraptionMovementSetting.isNoPickup(contraption.getContraption().getBlocks().values())) {
Contraption blocks = contraption.getContraption(); player.displayClientMessage(Lang.translate("contraption.minecart_contraption_illegal_pickup")
if (blocks != null && blocks.getBlocks().values().stream() .withStyle(TextFormatting.RED), true);
.anyMatch(i -> i.state.getBlock() instanceof SpawnerBlock)) { return;
player.displayClientMessage(Lang.translate("contraption.minecart_contraption_illegal_pickup")
.withStyle(TextFormatting.RED), true);
return;
}
} }
if (event.getWorld().isClientSide) { if (event.getWorld().isClientSide) {

View file

@ -35,8 +35,8 @@ public class CKinetics extends ConfigBase {
public ConfigInt maxPistonPoles = i(64, 1, "maxPistonPoles", Comments.maxPistonPoles); public ConfigInt maxPistonPoles = i(64, 1, "maxPistonPoles", Comments.maxPistonPoles);
public ConfigInt maxRopeLength = i(128, 1, "maxRopeLength", Comments.maxRopeLength); public ConfigInt maxRopeLength = i(128, 1, "maxRopeLength", Comments.maxRopeLength);
public ConfigInt maxCartCouplingLength = i(32, 1, "maxCartCouplingLength", Comments.maxCartCouplingLength); public ConfigInt maxCartCouplingLength = i(32, 1, "maxCartCouplingLength", Comments.maxCartCouplingLength);
public ConfigEnum<SpawnerMovementSetting> spawnerMovement = public ConfigEnum<ContraptionMovementSetting> spawnerMovement =
e(SpawnerMovementSetting.NO_PICKUP, "movableSpawners", Comments.spawnerMovement); e(ContraptionMovementSetting.NO_PICKUP, "movableSpawners", Comments.spawnerMovement);
public CStress stressValues = nested(1, CStress::new, Comments.stress); public CStress stressValues = nested(1, CStress::new, Comments.stress);
@ -103,8 +103,4 @@ public class CKinetics extends ConfigBase {
ALL, CREEPERS, NONE ALL, CREEPERS, NONE
} }
public enum SpawnerMovementSetting {
MOVABLE, NO_PICKUP, UNMOVABLE
}
} }

View file

@ -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();
}
}