Stress Values API (#18)

This commit is contained in:
TropheusJ 2025-02-23 17:43:20 -05:00 committed by GitHub
parent a6d512356c
commit 2bd0034f01
Failed to generate hash of commit
16 changed files with 184 additions and 350 deletions

View file

@ -19,6 +19,7 @@ import static com.simibubi.create.foundation.data.TagGen.tagBlockAndItem;
import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.AllTags.AllBlockTags;
import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.api.behaviour.interaction.ConductorBlockInteractionBehavior; import com.simibubi.create.api.behaviour.interaction.ConductorBlockInteractionBehavior;
import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsBlock; import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsBlock;
import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovement; import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovement;
import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovingInteraction; import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovingInteraction;
@ -110,7 +111,6 @@ import com.simibubi.create.content.fluids.tank.FluidTankGenerator;
import com.simibubi.create.content.fluids.tank.FluidTankItem; import com.simibubi.create.content.fluids.tank.FluidTankItem;
import com.simibubi.create.content.fluids.tank.FluidTankModel; import com.simibubi.create.content.fluids.tank.FluidTankModel;
import com.simibubi.create.content.fluids.tank.FluidTankMovementBehavior; import com.simibubi.create.content.fluids.tank.FluidTankMovementBehavior;
import com.simibubi.create.content.kinetics.BlockStressDefaults;
import com.simibubi.create.content.kinetics.belt.BeltBlock; import com.simibubi.create.content.kinetics.belt.BeltBlock;
import com.simibubi.create.content.kinetics.belt.BeltGenerator; import com.simibubi.create.content.kinetics.belt.BeltGenerator;
import com.simibubi.create.content.kinetics.belt.BeltModel; import com.simibubi.create.content.kinetics.belt.BeltModel;
@ -270,6 +270,7 @@ import com.simibubi.create.foundation.item.ItemDescription;
import com.simibubi.create.foundation.item.UncontainableBlockItem; import com.simibubi.create.foundation.item.UncontainableBlockItem;
import com.simibubi.create.foundation.utility.ColorHandlers; import com.simibubi.create.foundation.utility.ColorHandlers;
import com.simibubi.create.foundation.utility.DyeHelper; import com.simibubi.create.foundation.utility.DyeHelper;
import com.simibubi.create.infrastructure.config.CStress;
import com.tterrag.registrate.providers.RegistrateRecipeProvider; import com.tterrag.registrate.providers.RegistrateRecipeProvider;
import com.tterrag.registrate.providers.loot.RegistrateBlockLootTables; import com.tterrag.registrate.providers.loot.RegistrateBlockLootTables;
import com.tterrag.registrate.util.DataIngredient; import com.tterrag.registrate.util.DataIngredient;
@ -365,7 +366,7 @@ public class AllBlocks {
public static final BlockEntry<ShaftBlock> SHAFT = REGISTRATE.block("shaft", ShaftBlock::new) public static final BlockEntry<ShaftBlock> SHAFT = REGISTRATE.block("shaft", ShaftBlock::new)
.initialProperties(SharedProperties::stone) .initialProperties(SharedProperties::stone)
.properties(p -> p.mapColor(MapColor.METAL).forceSolidOff()) .properties(p -> p.mapColor(MapColor.METAL).forceSolidOff())
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate(BlockStateGen.axisBlockProvider(false)) .blockstate(BlockStateGen.axisBlockProvider(false))
.onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new)) .onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new))
@ -376,7 +377,7 @@ public class AllBlocks {
.initialProperties(SharedProperties::stone) .initialProperties(SharedProperties::stone)
.properties(p -> p.sound(SoundType.WOOD) .properties(p -> p.sound(SoundType.WOOD)
.mapColor(MapColor.DIRT)) .mapColor(MapColor.DIRT))
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.axisBlockProvider(false)) .blockstate(BlockStateGen.axisBlockProvider(false))
.onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new)) .onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new))
@ -390,7 +391,7 @@ public class AllBlocks {
.properties(p -> p.sound(SoundType.WOOD) .properties(p -> p.sound(SoundType.WOOD)
.mapColor(MapColor.DIRT)) .mapColor(MapColor.DIRT))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.blockstate(BlockStateGen.axisBlockProvider(false)) .blockstate(BlockStateGen.axisBlockProvider(false))
.onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new)) .onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new))
.item(CogwheelBlockItem::new) .item(CogwheelBlockItem::new)
@ -456,7 +457,7 @@ public class AllBlocks {
.initialProperties(SharedProperties::stone) .initialProperties(SharedProperties::stone)
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.PODZOL)) .mapColor(MapColor.PODZOL))
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.onRegister(CreateRegistrate.connectedTextures(() -> new EncasedCTBehaviour(AllSpriteShifts.ANDESITE_CASING))) .onRegister(CreateRegistrate.connectedTextures(() -> new EncasedCTBehaviour(AllSpriteShifts.ANDESITE_CASING)))
.onRegister(CreateRegistrate.casingConnectivity((block, cc) -> cc.make(block, AllSpriteShifts.ANDESITE_CASING, .onRegister(CreateRegistrate.casingConnectivity((block, cc) -> cc.make(block, AllSpriteShifts.ANDESITE_CASING,
@ -471,7 +472,7 @@ public class AllBlocks {
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.PODZOL)) .mapColor(MapColor.PODZOL))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p))) .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p)))
.item() .item()
@ -483,7 +484,7 @@ public class AllBlocks {
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.PODZOL)) .mapColor(MapColor.PODZOL))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p))) .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p)))
.item() .item()
@ -495,7 +496,7 @@ public class AllBlocks {
.initialProperties(SharedProperties::stone) .initialProperties(SharedProperties::stone)
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.PODZOL)) .mapColor(MapColor.PODZOL))
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> new ChainDriveGenerator((state, suffix) -> p.models() .blockstate((c, p) -> new ChainDriveGenerator((state, suffix) -> p.models()
.getExistingFile(p.modLoc("block/" + c.getName() + "/" + suffix))).generate(c, p)) .getExistingFile(p.modLoc("block/" + c.getName() + "/" + suffix))).generate(c, p))
@ -508,7 +509,7 @@ public class AllBlocks {
.initialProperties(SharedProperties::stone) .initialProperties(SharedProperties::stone)
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.NETHER)) .mapColor(MapColor.NETHER))
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> new ChainDriveGenerator((state, suffix) -> { .blockstate((c, p) -> new ChainDriveGenerator((state, suffix) -> {
String powered = state.getValue(ChainGearshiftBlock.POWERED) ? "_powered" : ""; String powered = state.getValue(ChainGearshiftBlock.POWERED) ? "_powered" : "";
@ -530,7 +531,7 @@ public class AllBlocks {
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(new BeltGenerator()::generate) .blockstate(new BeltGenerator()::generate)
.transform(BlockStressDefaults.setImpact(0)) .transform(CStress.setNoImpact())
.transform(displaySource(AllDisplaySources.ITEM_NAMES)) .transform(displaySource(AllDisplaySources.ITEM_NAMES))
.onRegister(CreateRegistrate.blockModel(() -> BeltModel::new)) .onRegister(CreateRegistrate.blockModel(() -> BeltModel::new))
.register(); .register();
@ -541,7 +542,8 @@ public class AllBlocks {
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.PODZOL)) .mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BlockStressDefaults.setImpact(1)) .transform(CStress.setImpact(1))
.transform(CStress.setImpact(1))
.blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p)))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
@ -555,8 +557,8 @@ public class AllBlocks {
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate(new CreativeMotorGenerator()::generate) .blockstate(new CreativeMotorGenerator()::generate)
.transform(BlockStressDefaults.setCapacity(16384.0)) .transform(CStress.setCapacity(16384.0))
.transform(BlockStressDefaults.setGeneratorSpeed(() -> Couple.create(0, 256))) .onRegister(BlockStressValues.setGeneratorSpeed(256, true))
.item() .item()
.properties(p -> p.rarity(Rarity.EPIC)) .properties(p -> p.rarity(Rarity.EPIC))
.transform(customItemModel()) .transform(customItemModel())
@ -570,8 +572,8 @@ public class AllBlocks {
.blockstate( .blockstate(
(c, p) -> BlockStateGen.directionalBlockIgnoresWaterlogged(c, p, s -> AssetLookup.partialBaseModel(c, p))) (c, p) -> BlockStateGen.directionalBlockIgnoresWaterlogged(c, p, s -> AssetLookup.partialBaseModel(c, p)))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setCapacity(32.0)) .transform(CStress.setCapacity(32))
.transform(BlockStressDefaults.setGeneratorSpeed(WaterWheelBlock::getSpeedRange)) .onRegister(BlockStressValues.setGeneratorSpeed(8))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -585,8 +587,8 @@ public class AllBlocks {
.blockstate((c, p) -> axisBlock(c, p, .blockstate((c, p) -> axisBlock(c, p,
s -> s.getValue(LargeWaterWheelBlock.EXTENSION) ? AssetLookup.partialBaseModel(c, p, "extension") s -> s.getValue(LargeWaterWheelBlock.EXTENSION) ? AssetLookup.partialBaseModel(c, p, "extension")
: AssetLookup.partialBaseModel(c, p))) : AssetLookup.partialBaseModel(c, p)))
.transform(BlockStressDefaults.setCapacity(128.0)) .transform(CStress.setCapacity(128.0))
.transform(BlockStressDefaults.setGeneratorSpeed(LargeWaterWheelBlock::getSpeedRange)) .onRegister(BlockStressValues.setGeneratorSpeed(4))
.item(LargeWaterWheelBlockItem::new) .item(LargeWaterWheelBlockItem::new)
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -608,7 +610,7 @@ public class AllBlocks {
.blockstate(BlockStateGen.directionalBlockProvider(true)) .blockstate(BlockStateGen.directionalBlockProvider(true))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BlockStressDefaults.setImpact(2.0)) .transform(CStress.setImpact(2.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -629,7 +631,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.standardModel(c, p))) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.standardModel(c, p)))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.simpleItem() .simpleItem()
.register(); .register();
@ -638,8 +640,8 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.directionalBlockProvider(true)) .blockstate(BlockStateGen.directionalBlockProvider(true))
.transform(BlockStressDefaults.setCapacity(8.0)) .transform(CStress.setCapacity(8.0))
.transform(BlockStressDefaults.setGeneratorSpeed(HandCrankBlock::getSpeedRange)) .onRegister(BlockStressValues.setGeneratorSpeed(32))
.tag(AllBlockTags.BRITTLE.tag) .tag(AllBlockTags.BRITTLE.tag)
.onRegister(ItemUseOverrides::addBlock) .onRegister(ItemUseOverrides::addBlock)
.item() .item()
@ -669,7 +671,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.METAL)) .properties(p -> p.mapColor(MapColor.METAL))
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p)))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -682,7 +684,7 @@ public class AllBlocks {
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate((c, p) -> BlockStateGen.axisBlock(c, p, s -> AssetLookup.partialBaseModel(c, p))) .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, s -> AssetLookup.partialBaseModel(c, p)))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setImpact(8.0)) .transform(CStress.setImpact(8.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -706,7 +708,7 @@ public class AllBlocks {
.mapColor(MapColor.PODZOL)) .mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.horizontalBlockProvider(true)) .blockstate(BlockStateGen.horizontalBlockProvider(true))
.transform(BlockStressDefaults.setImpact(8.0)) .transform(CStress.setImpact(8.0))
.item(AssemblyOperatorBlockItem::new) .item(AssemblyOperatorBlockItem::new)
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -719,7 +721,7 @@ public class AllBlocks {
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p)))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item(AssemblyOperatorBlockItem::new) .item(AssemblyOperatorBlockItem::new)
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -793,7 +795,7 @@ public class AllBlocks {
.mapColor(MapColor.COLOR_GRAY)) .mapColor(MapColor.COLOR_GRAY))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate((c, p) -> p.horizontalBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p), 180)) .blockstate((c, p) -> p.horizontalBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p), 180))
.transform(BlockStressDefaults.setImpact(2.0)) .transform(CStress.setImpact(2.0))
.transform(displaySource(AllDisplaySources.ITEM_NAMES)) .transform(displaySource(AllDisplaySources.ITEM_NAMES))
.item(EjectorItem::new) .item(EjectorItem::new)
.transform(customItemModel()) .transform(customItemModel())
@ -831,7 +833,7 @@ public class AllBlocks {
.initialProperties(SharedProperties::wooden) .initialProperties(SharedProperties::wooden)
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.blockstate(new GaugeGenerator()::generate) .blockstate(new GaugeGenerator()::generate)
.transform(displaySource(AllDisplaySources.KINETIC_SPEED)) .transform(displaySource(AllDisplaySources.KINETIC_SPEED))
.item() .item()
@ -842,7 +844,7 @@ public class AllBlocks {
.initialProperties(SharedProperties::wooden) .initialProperties(SharedProperties::wooden)
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.blockstate(new GaugeGenerator()::generate) .blockstate(new GaugeGenerator()::generate)
.transform(displaySource(AllDisplaySources.KINETIC_STRESS)) .transform(displaySource(AllDisplaySources.KINETIC_STRESS))
.item() .item()
@ -923,7 +925,7 @@ public class AllBlocks {
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate(BlockStateGen.directionalBlockProviderIgnoresWaterlogged(true)) .blockstate(BlockStateGen.directionalBlockProviderIgnoresWaterlogged(true))
.onRegister(CreateRegistrate.blockModel(() -> PipeAttachmentModel::withoutAO)) .onRegister(CreateRegistrate.blockModel(() -> PipeAttachmentModel::withoutAO))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -955,7 +957,7 @@ public class AllBlocks {
REGISTRATE.block("copper_valve_handle", ValveHandleBlock::copper) REGISTRATE.block("copper_valve_handle", ValveHandleBlock::copper)
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.transform(BuilderTransformers.valveHandle(null)) .transform(BuilderTransformers.valveHandle(null))
.transform(BlockStressDefaults.setCapacity(8.0)) .transform(CStress.setCapacity(8.0))
.register(); .register();
public static final DyedBlockList<ValveHandleBlock> DYED_VALVE_HANDLES = new DyedBlockList<>(colour -> { public static final DyedBlockList<ValveHandleBlock> DYED_VALVE_HANDLES = new DyedBlockList<>(colour -> {
@ -1016,7 +1018,7 @@ public class AllBlocks {
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate(BlockStateGen.horizontalBlockProvider(true)) .blockstate(BlockStateGen.horizontalBlockProvider(true))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -1055,8 +1057,8 @@ public class AllBlocks {
.initialProperties(SharedProperties::copperMetal) .initialProperties(SharedProperties::copperMetal)
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.blockstate((c, p) -> p.horizontalFaceBlock(c.get(), AssetLookup.partialBaseModel(c, p))) .blockstate((c, p) -> p.horizontalFaceBlock(c.get(), AssetLookup.partialBaseModel(c, p)))
.transform(BlockStressDefaults.setCapacity(1024.0)) .transform(CStress.setCapacity(1024.0))
.transform(BlockStressDefaults.setGeneratorSpeed(SteamEngineBlock::getSpeedRange)) .onRegister(BlockStressValues.setGeneratorSpeed(64, true))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -1162,7 +1164,7 @@ public class AllBlocks {
existing.getLocation()) existing.getLocation())
.texture("2", p.modLoc("block/" + c.getName() + powered + flipped)); .texture("2", p.modLoc("block/" + c.getName() + powered + flipped));
})) }))
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.item() .item()
.transform(customItemModel("_", "block_single")) .transform(customItemModel("_", "block_single"))
.register(); .register();
@ -1172,8 +1174,8 @@ public class AllBlocks {
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(BuilderTransformers.bearing("windmill", "gearbox")) .transform(BuilderTransformers.bearing("windmill", "gearbox"))
.transform(BlockStressDefaults.setCapacity(512.0)) .transform(CStress.setCapacity(512.0))
.transform(BlockStressDefaults.setGeneratorSpeed(WindmillBearingBlock::getSpeedRange)) .onRegister(BlockStressValues.setGeneratorSpeed(16, true))
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.register(); .register();
@ -1182,7 +1184,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BuilderTransformers.bearing("mechanical", "gearbox")) .transform(BuilderTransformers.bearing("mechanical", "gearbox"))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.onRegister(movementBehaviour(new StabilizedBearingMovementBehaviour())) .onRegister(movementBehaviour(new StabilizedBearingMovementBehaviour()))
.register(); .register();
@ -1192,7 +1194,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.TERRACOTTA_BROWN)) .properties(p -> p.mapColor(MapColor.TERRACOTTA_BROWN))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BuilderTransformers.bearing("clockwork", "brass_gearbox")) .transform(BuilderTransformers.bearing("clockwork", "brass_gearbox"))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.register(); .register();
@ -1204,7 +1206,7 @@ public class AllBlocks {
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.blockstate(BlockStateGen.horizontalAxisBlockProvider(true)) .blockstate(BlockStateGen.horizontalAxisBlockProvider(true))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -1233,7 +1235,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.TERRACOTTA_BROWN)) .properties(p -> p.mapColor(MapColor.TERRACOTTA_BROWN))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.horizontalBlockProvider(true)) .blockstate(BlockStateGen.horizontalBlockProvider(true))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -1337,7 +1339,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.directionalBlockProvider(true)) .blockstate(BlockStateGen.directionalBlockProvider(true))
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.onRegister(movementBehaviour(new DrillMovementBehaviour())) .onRegister(movementBehaviour(new DrillMovementBehaviour()))
.item() .item()
.tag(AllItemTags.CONTRAPTION_CONTROLLED.tag) .tag(AllItemTags.CONTRAPTION_CONTROLLED.tag)
@ -1350,7 +1352,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(new SawGenerator()::generate) .blockstate(new SawGenerator()::generate)
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.onRegister(movementBehaviour(new SawMovementBehaviour())) .onRegister(movementBehaviour(new SawMovementBehaviour()))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.item() .item()
@ -1363,7 +1365,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.PODZOL)) .properties(p -> p.mapColor(MapColor.PODZOL))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.directionalAxisBlockProvider()) .blockstate(BlockStateGen.directionalAxisBlockProvider())
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.onRegister(movementBehaviour(new DeployerMovementBehaviour())) .onRegister(movementBehaviour(new DeployerMovementBehaviour()))
.onRegister(interactionBehaviour(new DeployerMovingInteraction())) .onRegister(interactionBehaviour(new DeployerMovingInteraction()))
.item(AssemblyOperatorBlockItem::new) .item(AssemblyOperatorBlockItem::new)
@ -1538,7 +1540,7 @@ public class AllBlocks {
.mapColor(MapColor.TERRACOTTA_YELLOW)) .mapColor(MapColor.TERRACOTTA_YELLOW))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.blockstate(BlockStateGen.horizontalBlockProvider(true)) .blockstate(BlockStateGen.horizontalBlockProvider(true))
.transform(BlockStressDefaults.setImpact(2.0)) .transform(CStress.setImpact(2.0))
.onRegister(CreateRegistrate.connectedTextures(CrafterCTBehaviour::new)) .onRegister(CreateRegistrate.connectedTextures(CrafterCTBehaviour::new))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.item() .item()
@ -1552,7 +1554,7 @@ public class AllBlocks {
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.properties(BlockBehaviour.Properties::noOcclusion) .properties(BlockBehaviour.Properties::noOcclusion)
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.blockstate(new SequencedGearshiftGenerator()::generate) .blockstate(new SequencedGearshiftGenerator()::generate)
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
@ -1563,7 +1565,7 @@ public class AllBlocks {
.properties(p -> p.noOcclusion() .properties(p -> p.noOcclusion()
.mapColor(MapColor.TERRACOTTA_YELLOW)) .mapColor(MapColor.TERRACOTTA_YELLOW))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.blockstate(BlockStateGen.axisBlockProvider(true)) .blockstate(BlockStateGen.axisBlockProvider(true))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
@ -1575,7 +1577,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.TERRACOTTA_YELLOW)) .properties(p -> p.mapColor(MapColor.TERRACOTTA_YELLOW))
.transform(axeOrPickaxe()) .transform(axeOrPickaxe())
.tag(AllBlockTags.SAFE_NBT.tag) .tag(AllBlockTags.SAFE_NBT.tag)
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.blockstate(BlockStateGen.horizontalAxisBlockProvider(true)) .blockstate(BlockStateGen.horizontalAxisBlockProvider(true))
.item() .item()
.transform(customItemModel()) .transform(customItemModel())
@ -1592,7 +1594,7 @@ public class AllBlocks {
.modelFile(AssetLookup.partialBaseModel(c, p)) .modelFile(AssetLookup.partialBaseModel(c, p))
.rotationX(s.getValue(ArmBlock.CEILING) ? 180 : 0) .rotationX(s.getValue(ArmBlock.CEILING) ? 180 : 0)
.build())) .build()))
.transform(BlockStressDefaults.setImpact(2.0)) .transform(CStress.setImpact(2.0))
.item(ArmItem::new) .item(ArmItem::new)
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
@ -2026,7 +2028,7 @@ public class AllBlocks {
.properties(p -> p.mapColor(MapColor.COLOR_GRAY)) .properties(p -> p.mapColor(MapColor.COLOR_GRAY))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.transform(BlockStressDefaults.setImpact(0)) .transform(CStress.setNoImpact())
.blockstate((c, p) -> p.horizontalBlock(c.get(), AssetLookup.partialBaseModel(c, p))) .blockstate((c, p) -> p.horizontalBlock(c.get(), AssetLookup.partialBaseModel(c, p)))
.transform(displayTarget(AllDisplayTargets.DISPLAY_BOARD)) .transform(displayTarget(AllDisplayTargets.DISPLAY_BOARD))
.lang("Display Board") .lang("Display Board")

View file

@ -0,0 +1,50 @@
package com.simibubi.create.api.stress;
import java.util.function.DoubleSupplier;
import com.simibubi.create.api.registry.SimpleRegistry;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import net.minecraft.world.level.block.Block;
public class BlockStressValues {
/**
* Registry for suppliers of stress impacts. Determine the base impact at 1 RPM.
*/
public static final SimpleRegistry<Block, DoubleSupplier> IMPACTS = SimpleRegistry.create();
/**
* Registry for suppliers of stress capacities. Determine the base capacity at 1 RPM.
*/
public static final SimpleRegistry<Block, DoubleSupplier> CAPACITIES = SimpleRegistry.create();
/**
* Registry for generator RPM values. This is only used for tooltips; actual functionality is determined by the block.
*/
public static final SimpleRegistry<Block, GeneratedRpm> RPM = SimpleRegistry.create();
public static double getImpact(Block block) {
DoubleSupplier supplier = IMPACTS.get(block);
return supplier == null ? 0 : supplier.getAsDouble();
}
public static double getCapacity(Block block) {
DoubleSupplier supplier = CAPACITIES.get(block);
return supplier == null ? 0 : supplier.getAsDouble();
}
/**
* Shortcut for when a generator always generates the same RPM.
*/
public static NonNullConsumer<Block> setGeneratorSpeed(int value) {
return block -> RPM.register(block, new GeneratedRpm(value, false));
}
/**
* Utility for Registrate. Registers the given RPM generation info to blocks passed to the returned consumer.
*/
public static NonNullConsumer<Block> setGeneratorSpeed(int value, boolean mayGenerateLess) {
return block -> RPM.register(block, new GeneratedRpm(value, mayGenerateLess));
}
public record GeneratedRpm(int value, boolean mayGenerateLess) {
}
}

View file

@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.bearing;
import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllBlockEntityTypes;
import com.simibubi.create.foundation.block.IBE; import com.simibubi.create.foundation.block.IBE;
import net.createmod.catnip.data.Couple;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
@ -51,9 +50,4 @@ public class WindmillBearingBlock extends BearingBlock implements IBE<WindmillBe
public BlockEntityType<? extends WindmillBearingBlockEntity> getBlockEntityType() { public BlockEntityType<? extends WindmillBearingBlockEntity> getBlockEntityType() {
return AllBlockEntityTypes.WINDMILL_BEARING.get(); return AllBlockEntityTypes.WINDMILL_BEARING.get();
} }
public static Couple<Integer> getSpeedRange() {
return Couple.create(1, 16);
}
} }

View file

@ -11,9 +11,9 @@ import org.jetbrains.annotations.NotNull;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.api.boiler.BoilerHeater; import com.simibubi.create.api.boiler.BoilerHeater;
import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.content.decoration.steamWhistle.WhistleBlock; import com.simibubi.create.content.decoration.steamWhistle.WhistleBlock;
import com.simibubi.create.content.decoration.steamWhistle.WhistleBlockEntity; import com.simibubi.create.content.decoration.steamWhistle.WhistleBlockEntity;
import com.simibubi.create.content.kinetics.BlockStressValues;
import com.simibubi.create.content.kinetics.steamEngine.SteamEngineBlock; import com.simibubi.create.content.kinetics.steamEngine.SteamEngineBlock;
import com.simibubi.create.foundation.advancement.AdvancementBehaviour; import com.simibubi.create.foundation.advancement.AdvancementBehaviour;
import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllAdvancements;

View file

@ -1,68 +0,0 @@
package com.simibubi.create.content.kinetics;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import net.createmod.catnip.data.Couple;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
public class BlockStressDefaults {
/**
* Increment this number if all stress entries should be forced to update in the
* next release. Worlds from the previous version will overwrite potentially
* changed values with the new defaults.
*/
public static final int FORCED_UPDATE_VERSION = 2;
public static final Map<ResourceLocation, Double> DEFAULT_IMPACTS = new ConcurrentHashMap<>();
public static final Map<ResourceLocation, Double> DEFAULT_CAPACITIES = new ConcurrentHashMap<>();
public static final Map<ResourceLocation, Supplier<Couple<Integer>>> GENERATOR_SPEEDS = new ConcurrentHashMap<>();
public static void setDefaultImpact(ResourceLocation blockId, double impact) {
DEFAULT_IMPACTS.put(blockId, impact);
}
public static void setDefaultCapacity(ResourceLocation blockId, double capacity) {
DEFAULT_CAPACITIES.put(blockId, capacity);
}
public static void setGeneratorSpeed(ResourceLocation blockId, Supplier<Couple<Integer>> provider) {
GENERATOR_SPEEDS.put(blockId, provider);
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setNoImpact() {
return setImpact(0);
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setImpact(double impact) {
return b -> {
setDefaultImpact(new ResourceLocation(b.getOwner()
.getModid(), b.getName()), impact);
return b;
};
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setCapacity(double capacity) {
return b -> {
setDefaultCapacity(new ResourceLocation(b.getOwner()
.getModid(), b.getName()), capacity);
return b;
};
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setGeneratorSpeed(
Supplier<Couple<Integer>> provider) {
return b -> {
setGeneratorSpeed(new ResourceLocation(b.getOwner()
.getModid(), b.getName()), provider);
return b;
};
}
}

View file

@ -1,116 +0,0 @@
package com.simibubi.create.content.kinetics;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import net.createmod.catnip.platform.CatnipServices;
import net.createmod.catnip.data.Couple;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
public class BlockStressValues {
private static final Map<String, IStressValueProvider> PROVIDERS = new HashMap<>();
public static void registerProvider(String namespace, IStressValueProvider provider) {
PROVIDERS.put(namespace, provider);
}
@Nullable
public static IStressValueProvider getProvider(String namespace) {
return PROVIDERS.get(namespace);
}
@Nullable
public static IStressValueProvider getProvider(Block block) {
return getProvider(CatnipServices.REGISTRIES.getKeyOrThrow(block)
.getNamespace());
}
public static double getImpact(Block block) {
ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block);
IStressValueProvider provider = getProvider(blockId.getNamespace());
if (provider != null) {
return provider.getImpact(block);
}
Double defaultImpact = BlockStressDefaults.DEFAULT_IMPACTS.get(blockId);
if (defaultImpact != null) {
return defaultImpact;
}
return 0;
}
public static double getCapacity(Block block) {
ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block);
IStressValueProvider provider = getProvider(blockId.getNamespace());
if (provider != null) {
return provider.getCapacity(block);
}
Double defaultCapacity = BlockStressDefaults.DEFAULT_CAPACITIES.get(blockId);
if (defaultCapacity != null) {
return defaultCapacity;
}
return 0;
}
public static boolean hasImpact(Block block) {
ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block);
IStressValueProvider provider = getProvider(blockId.getNamespace());
if (provider != null) {
return provider.hasImpact(block);
}
return BlockStressDefaults.DEFAULT_IMPACTS.containsKey(blockId);
}
public static boolean hasCapacity(Block block) {
ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block);
IStressValueProvider provider = getProvider(blockId.getNamespace());
if (provider != null) {
return provider.hasCapacity(block);
}
return BlockStressDefaults.DEFAULT_CAPACITIES.containsKey(blockId);
}
@Nullable
public static Couple<Integer> getGeneratedRPM(Block block) {
ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block);
IStressValueProvider provider = getProvider(blockId.getNamespace());
if (provider != null) {
return provider.getGeneratedRPM(block);
}
return null;
}
public interface IStressValueProvider {
/**
* Gets the stress impact of a block.
*
* @param block The block.
* @return the stress impact value of the block, or 0 if it does not have one.
*/
double getImpact(Block block);
/**
* Gets the stress capacity of a block.
*
* @param block The block.
* @return the stress capacity value of the block, or 0 if it does not have one.
*/
double getCapacity(Block block);
boolean hasImpact(Block block);
boolean hasCapacity(Block block);
/**
*
* @param block
* @return min, max generated RPM; null if block does not have a stress capacity
*/
@Nullable
Couple<Integer> getGeneratedRPM(Block block);
}
}

View file

@ -10,7 +10,7 @@ import javax.annotation.Nullable;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation; import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation;
import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation; import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation;
import com.simibubi.create.content.kinetics.BlockStressValues; import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.content.kinetics.KineticNetwork; import com.simibubi.create.content.kinetics.KineticNetwork;
import com.simibubi.create.content.kinetics.RotationPropagator; import com.simibubi.create.content.kinetics.RotationPropagator;
import com.simibubi.create.content.kinetics.base.IRotate.SpeedLevel; import com.simibubi.create.content.kinetics.base.IRotate.SpeedLevel;

View file

@ -9,7 +9,6 @@ import com.simibubi.create.foundation.block.IBE;
import com.simibubi.create.foundation.block.ProperWaterloggedBlock; import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.infrastructure.config.AllConfigs; import com.simibubi.create.infrastructure.config.AllConfigs;
import net.createmod.catnip.data.Couple;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis; import net.minecraft.core.Direction.Axis;
@ -150,9 +149,4 @@ public class HandCrankBlock extends DirectionalKineticBlock
public boolean isPathfindable(BlockState state, BlockGetter reader, BlockPos pos, PathComputationType type) { public boolean isPathfindable(BlockState state, BlockGetter reader, BlockPos pos, PathComputationType type) {
return false; return false;
} }
public static Couple<Integer> getSpeedRange() {
return Couple.create(32, 32);
}
} }

View file

@ -8,7 +8,6 @@ import com.simibubi.create.AllItems;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.BlockHelper;
import net.createmod.catnip.data.Couple;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
@ -22,6 +21,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -32,7 +32,7 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
public class ValveHandleBlock extends HandCrankBlock { public class ValveHandleBlock extends HandCrankBlock {
public final DyeColor color; public final DyeColor color;
public static ValveHandleBlock copper(Properties properties) { public static ValveHandleBlock copper(Properties properties) {
return new ValveHandleBlock(properties, null); return new ValveHandleBlock(properties, null);
} }
@ -111,9 +111,4 @@ public class ValveHandleBlock extends HandCrankBlock {
public int getRotationSpeed() { public int getRotationSpeed() {
return 32; return 32;
} }
public static Couple<Integer> getSpeedRange() {
return Couple.create(32, 32);
}
} }

View file

@ -2,7 +2,7 @@ package com.simibubi.create.content.kinetics.steamEngine;
import java.util.List; import java.util.List;
import com.simibubi.create.content.kinetics.BlockStressValues; import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity; import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity;
import net.createmod.catnip.platform.CatnipServices; import net.createmod.catnip.platform.CatnipServices;
@ -16,6 +16,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
public class PoweredShaftBlockEntity extends GeneratingKineticBlockEntity { public class PoweredShaftBlockEntity extends GeneratingKineticBlockEntity {

View file

@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock; import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock;
import com.simibubi.create.foundation.block.IBE; import com.simibubi.create.foundation.block.IBE;
import net.createmod.catnip.data.Couple;
import net.createmod.catnip.data.Iterate; import net.createmod.catnip.data.Iterate;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -164,10 +163,6 @@ public class LargeWaterWheelBlock extends RotatedPillarKineticBlock implements I
return 2.25f; return 2.25f;
} }
public static Couple<Integer> getSpeedRange() {
return Couple.create(4, 4);
}
@Override @Override
public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
return false; return false;

View file

@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.kinetics.base.DirectionalKineticBlock; import com.simibubi.create.content.kinetics.base.DirectionalKineticBlock;
import com.simibubi.create.foundation.block.IBE; import com.simibubi.create.foundation.block.IBE;
import net.createmod.catnip.data.Couple;
import net.createmod.catnip.data.Iterate; import net.createmod.catnip.data.Iterate;
import net.createmod.catnip.levelWrappers.WrappedLevel; import net.createmod.catnip.levelWrappers.WrappedLevel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -127,10 +126,6 @@ public class WaterWheelBlock extends DirectionalKineticBlock implements IBE<Wate
return AllBlockEntityTypes.WATER_WHEEL.get(); return AllBlockEntityTypes.WATER_WHEEL.get();
} }
public static Couple<Integer> getSpeedRange() {
return Couple.create(8, 8);
}
@Override @Override
public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
return false; return false;

View file

@ -20,6 +20,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.AllTags.AllBlockTags;
import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.AllTags.AllItemTags;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction; import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction;
import com.simibubi.create.content.contraptions.behaviour.TrapdoorMovingInteraction; import com.simibubi.create.content.contraptions.behaviour.TrapdoorMovingInteraction;
import com.simibubi.create.content.contraptions.piston.MechanicalPistonGenerator; import com.simibubi.create.content.contraptions.piston.MechanicalPistonGenerator;
@ -31,7 +32,6 @@ import com.simibubi.create.content.decoration.encasing.CasingBlock;
import com.simibubi.create.content.decoration.encasing.EncasedCTBehaviour; import com.simibubi.create.content.decoration.encasing.EncasedCTBehaviour;
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock; import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock;
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorMovementBehaviour; import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorMovementBehaviour;
import com.simibubi.create.content.kinetics.BlockStressDefaults;
import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock; import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock;
import com.simibubi.create.content.kinetics.crank.ValveHandleBlock; import com.simibubi.create.content.kinetics.crank.ValveHandleBlock;
import com.simibubi.create.content.kinetics.simpleRelays.encased.EncasedCogCTBehaviour; import com.simibubi.create.content.kinetics.simpleRelays.encased.EncasedCogCTBehaviour;
@ -51,6 +51,7 @@ import com.simibubi.create.foundation.block.ItemUseOverrides;
import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry;
import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour; import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour;
import com.simibubi.create.foundation.item.ItemDescription; import com.simibubi.create.foundation.item.ItemDescription;
import com.simibubi.create.infrastructure.config.CStress;
import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.builders.ItemBuilder; import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.providers.RegistrateRecipeProvider; import com.tterrag.registrate.providers.RegistrateRecipeProvider;
@ -226,7 +227,7 @@ public class BuilderTransformers {
Supplier<ItemLike> drop) { Supplier<ItemLike> drop) {
return b.initialProperties(SharedProperties::stone) return b.initialProperties(SharedProperties::stone)
.properties(BlockBehaviour.Properties::noOcclusion) .properties(BlockBehaviour.Properties::noOcclusion)
.transform(BlockStressDefaults.setNoImpact()) .transform(CStress.setNoImpact())
.loot((p, lb) -> p.dropOther(lb, drop.get())); .loot((p, lb) -> p.dropOther(lb, drop.get()));
} }
@ -235,7 +236,7 @@ public class BuilderTransformers {
.blockstate((c, p) -> p.horizontalBlock(c.get(), p.models() .blockstate((c, p) -> p.horizontalBlock(c.get(), p.models()
.getExistingFile(p.modLoc("block/cuckoo_clock/block")))) .getExistingFile(p.modLoc("block/cuckoo_clock/block"))))
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setImpact(1.0)) .transform(CStress.setImpact(1))
.item() .item()
.transform(ModelGen.customItemModel("cuckoo_clock", "item")); .transform(ModelGen.customItemModel("cuckoo_clock", "item"));
} }
@ -299,7 +300,7 @@ public class BuilderTransformers {
.texture("3", p.modLoc("block/valve_handle/valve_handle_" + variant))); .texture("3", p.modLoc("block/valve_handle/valve_handle_" + variant)));
}) })
.tag(AllBlockTags.BRITTLE.tag, AllBlockTags.VALVE_HANDLES.tag) .tag(AllBlockTags.BRITTLE.tag, AllBlockTags.VALVE_HANDLES.tag)
.transform(BlockStressDefaults.setGeneratorSpeed(ValveHandleBlock::getSpeedRange)) .onRegister(BlockStressValues.setGeneratorSpeed(32))
.onRegister(ItemUseOverrides::addBlock) .onRegister(ItemUseOverrides::addBlock)
.item() .item()
.tag(AllItemTags.VALVE_HANDLES.tag) .tag(AllItemTags.VALVE_HANDLES.tag)
@ -380,7 +381,7 @@ public class BuilderTransformers {
.properties(p -> p.noOcclusion()) .properties(p -> p.noOcclusion())
.blockstate(new MechanicalPistonGenerator(type)::generate) .blockstate(new MechanicalPistonGenerator(type)::generate)
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.item() .item()
.transform(ModelGen.customItemModel("mechanical_piston", type.getSerializedName(), "item")); .transform(ModelGen.customItemModel("mechanical_piston", type.getSerializedName(), "item"));
} }
@ -441,7 +442,7 @@ public class BuilderTransformers {
return b -> b.blockstate((c, p) -> p.horizontalBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) return b -> b.blockstate((c, p) -> p.horizontalBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p)))
.transform(pickaxeOnly()) .transform(pickaxeOnly())
.addLayer(() -> RenderType::cutoutMipped) .addLayer(() -> RenderType::cutoutMipped)
.transform(BlockStressDefaults.setImpact(4.0)) .transform(CStress.setImpact(4.0))
.loot((lt, block) -> { .loot((lt, block) -> {
Builder builder = LootTable.lootTable(); Builder builder = LootTable.lootTable();
LootItemCondition.Builder survivesExplosion = ExplosionCondition.survivesExplosion(); LootItemCondition.Builder survivesExplosion = ExplosionCondition.survivesExplosion();

View file

@ -9,8 +9,9 @@ import java.util.List;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.api.stress.BlockStressValues.GeneratedRpm;
import com.simibubi.create.content.equipment.goggles.GogglesItem; import com.simibubi.create.content.equipment.goggles.GogglesItem;
import com.simibubi.create.content.kinetics.BlockStressValues;
import com.simibubi.create.content.kinetics.base.IRotate; import com.simibubi.create.content.kinetics.base.IRotate;
import com.simibubi.create.content.kinetics.base.IRotate.StressImpact; import com.simibubi.create.content.kinetics.base.IRotate.StressImpact;
import com.simibubi.create.content.kinetics.crank.ValveHandleBlock; import com.simibubi.create.content.kinetics.crank.ValveHandleBlock;
@ -19,7 +20,6 @@ import com.simibubi.create.foundation.utility.CreateLang;
import com.simibubi.create.infrastructure.config.AllConfigs; import com.simibubi.create.infrastructure.config.AllConfigs;
import com.simibubi.create.infrastructure.config.CKinetics; import com.simibubi.create.infrastructure.config.CKinetics;
import net.createmod.catnip.data.Couple;
import net.createmod.catnip.lang.Lang; import net.createmod.catnip.lang.Lang;
import net.createmod.catnip.lang.LangBuilder; import net.createmod.catnip.lang.LangBuilder;
import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.CommonComponents;
@ -80,7 +80,7 @@ public class KineticStats implements TooltipModifier {
boolean hasStressImpact = boolean hasStressImpact =
StressImpact.isEnabled() && showStressImpact && BlockStressValues.getImpact(block) > 0; StressImpact.isEnabled() && showStressImpact && BlockStressValues.getImpact(block) > 0;
boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.hasCapacity(block); boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.getCapacity(block) > 0;
if (hasStressImpact) { if (hasStressImpact) {
CreateLang.translate("tooltip.stressImpact") CreateLang.translate("tooltip.stressImpact")
@ -110,7 +110,7 @@ public class KineticStats implements TooltipModifier {
.addTo(list); .addTo(list);
double capacity = BlockStressValues.getCapacity(block); double capacity = BlockStressValues.getCapacity(block);
Couple<Integer> generatedRPM = BlockStressValues.getGeneratedRPM(block); GeneratedRpm generatedRPM = BlockStressValues.RPM.get(block);
StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.HIGH StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.HIGH
: (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.LOW); : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.LOW);
@ -126,11 +126,10 @@ public class KineticStats implements TooltipModifier {
.addTo(list); .addTo(list);
if (generatedRPM != null) { if (generatedRPM != null) {
LangBuilder amount = CreateLang.number(capacity * generatedRPM.getSecond()) LangBuilder amount = CreateLang.number(capacity * generatedRPM.value())
.add(suUnit); .add(suUnit);
CreateLang.text(" -> ") CreateLang.text(" -> ")
.add(!generatedRPM.getFirst() .add(generatedRPM.mayGenerateLess() ? CreateLang.translate("tooltip.up_to", amount) : amount)
.equals(generatedRPM.getSecond()) ? CreateLang.translate("tooltip.up_to", amount) : amount)
.style(DARK_GRAY) .style(DARK_GRAY)
.addTo(list); .addTo(list);
} }

View file

@ -7,9 +7,10 @@ import java.util.function.Supplier;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.content.kinetics.BlockStressValues; import com.simibubi.create.api.stress.BlockStressValues;
import net.createmod.catnip.config.ConfigBase; import net.createmod.catnip.config.ConfigBase;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.ModLoadingContext;
@ -63,7 +64,9 @@ public class AllConfigs {
for (Entry<ModConfig.Type, ConfigBase> pair : CONFIGS.entrySet()) for (Entry<ModConfig.Type, ConfigBase> pair : CONFIGS.entrySet())
context.registerConfig(pair.getKey(), pair.getValue().specification); context.registerConfig(pair.getKey(), pair.getValue().specification);
BlockStressValues.registerProvider(context.getActiveNamespace(), server().kinetics.stressValues); CStress stress = server().kinetics.stressValues;
BlockStressValues.IMPACTS.registerProvider(stress::getImpact);
BlockStressValues.CAPACITIES.registerProvider(stress::getCapacity);
} }
@SubscribeEvent @SubscribeEvent

View file

@ -2,105 +2,94 @@ package com.simibubi.create.infrastructure.config;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.DoubleSupplier;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.content.kinetics.BlockStressDefaults; import com.tterrag.registrate.builders.BlockBuilder;
import com.simibubi.create.content.kinetics.BlockStressValues.IStressValueProvider; import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
import net.createmod.catnip.config.ConfigBase; import net.createmod.catnip.config.ConfigBase;
import net.createmod.catnip.platform.CatnipServices; import net.createmod.catnip.platform.CatnipServices;
import net.createmod.catnip.data.Couple;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.ForgeConfigSpec.Builder; import net.minecraftforge.common.ForgeConfigSpec.Builder;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
public class CStress extends ConfigBase implements IStressValueProvider { public class CStress extends ConfigBase {
// bump this version to reset configured values.
private static final int VERSION = 2;
private final Map<ResourceLocation, ConfigValue<Double>> capacities = new HashMap<>(); // IDs need to be used since configs load before registration
private final Map<ResourceLocation, ConfigValue<Double>> impacts = new HashMap<>();
private static final Object2DoubleMap<ResourceLocation> DEFAULT_IMPACTS = new Object2DoubleOpenHashMap<>();
private static final Object2DoubleMap<ResourceLocation> DEFAULT_CAPACITIES = new Object2DoubleOpenHashMap<>();
protected final Map<ResourceLocation, ConfigValue<Double>> capacities = new HashMap<>();
protected final Map<ResourceLocation, ConfigValue<Double>> impacts = new HashMap<>();
@Override @Override
public void registerAll(Builder builder) { public void registerAll(Builder builder) {
builder.comment(".", Comments.su, Comments.impact) builder.comment(".", Comments.su, Comments.impact)
.push("impact"); .push("impact");
BlockStressDefaults.DEFAULT_IMPACTS.forEach((r, i) -> { DEFAULT_IMPACTS.forEach((id, value) -> this.impacts.put(id, builder.define(id.getPath(), value)));
if (r.getNamespace()
.equals(Create.ID))
getImpacts().put(r, builder.define(r.getPath(), i));
});
builder.pop(); builder.pop();
builder.comment(".", Comments.su, Comments.capacity) builder.comment(".", Comments.su, Comments.capacity)
.push("capacity"); .push("capacity");
BlockStressDefaults.DEFAULT_CAPACITIES.forEach((r, i) -> { DEFAULT_CAPACITIES.forEach((id, value) -> this.capacities.put(id, builder.define(id.getPath(), value)));
if (r.getNamespace()
.equals(Create.ID))
getCapacities().put(r, builder.define(r.getPath(), i));
});
builder.pop(); builder.pop();
} }
@Override
public double getImpact(Block block) {
block = redirectValues(block);
ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block);
ConfigValue<Double> value = getImpacts().get(key);
if (value != null)
return value.get();
return 0;
}
@Override
public double getCapacity(Block block) {
block = redirectValues(block);
ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block);
ConfigValue<Double> value = getCapacities().get(key);
if (value != null)
return value.get();
return 0;
}
@Override
public Couple<Integer> getGeneratedRPM(Block block) {
block = redirectValues(block);
ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block);
Supplier<Couple<Integer>> supplier = BlockStressDefaults.GENERATOR_SPEEDS.get(key);
if (supplier == null)
return null;
return supplier.get();
}
@Override
public boolean hasImpact(Block block) {
block = redirectValues(block);
ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block);
return getImpacts().containsKey(key);
}
@Override
public boolean hasCapacity(Block block) {
block = redirectValues(block);
ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block);
return getCapacities().containsKey(key);
}
protected Block redirectValues(Block block) {
return block;
}
@Override @Override
public String getName() { public String getName() {
return "stressValues.v" + BlockStressDefaults.FORCED_UPDATE_VERSION; return "stressValues.v" + VERSION;
} }
public Map<ResourceLocation, ConfigValue<Double>> getImpacts() { @Nullable
return impacts; public DoubleSupplier getImpact(Block block) {
ResourceLocation id = CatnipServices.REGISTRIES.getKeyOrThrow(block);
ConfigValue<Double> value = this.impacts.get(id);
return value == null ? null : value::get;
} }
public Map<ResourceLocation, ConfigValue<Double>> getCapacities() { @Nullable
return capacities; public DoubleSupplier getCapacity(Block block) {
ResourceLocation id = CatnipServices.REGISTRIES.getKeyOrThrow(block);
ConfigValue<Double> value = this.capacities.get(id);
return value == null ? null : value::get;
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setNoImpact() {
return setImpact(0);
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setImpact(double value) {
return builder -> {
assertFromCreate(builder);
ResourceLocation id = Create.asResource(builder.getName());
DEFAULT_IMPACTS.put(id, value);
return builder;
};
}
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> setCapacity(double value) {
return builder -> {
assertFromCreate(builder);
ResourceLocation id = Create.asResource(builder.getName());
DEFAULT_CAPACITIES.put(id, value);
return builder;
};
}
private static void assertFromCreate(BlockBuilder<?, ?> builder) {
if (!builder.getOwner().getModid().equals(Create.ID)) {
throw new IllegalStateException("Non-Create blocks cannot be added to Create's config.");
}
} }
private static class Comments { private static class Comments {