From 7826e5d8425dd14178ebed4a4c8fa381047f30c7 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 24 Jan 2022 12:21:34 +0700 Subject: [PATCH] Gravitation stabilizer lens --- shapegen.js | 2 +- .../ru/dbotthepony/mc/otm/datagen/DataGen.kt | 1 + .../java/ru/dbotthepony/mc/otm/Registry.java | 12 +- .../mc/otm/shapes/BlockShapes.java | 50 ++++++ .../otm/block/BlockGravitationStabilizer.kt | 161 +++++++++++++++++- .../BlockEntityGravitationStabilizer.kt | 10 +- .../overdrive_that_matters/lang/en_us.json | 1 + ... => gravitation_stabilizer_lens_idle.json} | 0 ... gravitation_stabilizer_lens_working.json} | 0 9 files changed, 228 insertions(+), 9 deletions(-) rename src/main/resources/assets/overdrive_that_matters/models/block/{gravitational_stabilizer_lens_idle.json => gravitation_stabilizer_lens_idle.json} (100%) rename src/main/resources/assets/overdrive_that_matters/models/block/{gravitational_stabilizer_lens_working.json => gravitation_stabilizer_lens_working.json} (100%) diff --git a/shapegen.js b/shapegen.js index 3aab97d5d..228b3b2ea 100644 --- a/shapegen.js +++ b/shapegen.js @@ -37,7 +37,7 @@ for (const model of args) { for (const elementID in obj.elements) { const element = obj.elements[elementID] - if (element.rotation) + if (element.rotation && element.rotation.angle != 0) continue; const from = element.from diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt index 605afb48e..3025bef58 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt @@ -124,6 +124,7 @@ object DataGen { block(Blocks.MATTER_REPLICATOR) block(Blocks.PLATE_PRESS) block(Blocks.GRAVITATION_STABILIZER) + block(Blocks.GRAVITATION_STABILIZER_LENS) } with(itemModelProvider) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index 37f4d34db..a807fc480 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -147,6 +147,7 @@ public class Registry { public static final ResourceLocation BLACK_HOLE = loc("black_hole"); public static final ResourceLocation GRAVITATION_STABILIZER = loc("gravitation_stabilizer"); // нужен рецепт + public static final ResourceLocation GRAVITATION_STABILIZER_LENS = loc("gravitation_stabilizer_lens"); public static final ResourceLocation CARGO_CRATE = loc("cargo_crate"); // нужен рецепт? // building blocks @@ -309,6 +310,7 @@ public class Registry { public static final BlockBlackHole BLACK_HOLE = new BlockBlackHole(); public static final BlockGravitationStabilizer GRAVITATION_STABILIZER = new BlockGravitationStabilizer(); + public static final BlockGravitationStabilizerLens GRAVITATION_STABILIZER_LENS = new BlockGravitationStabilizerLens(); public static final Block TRITANIUM_ORE = new OreBlock( BlockBehaviour.Properties.of(Material.STONE) @@ -389,6 +391,7 @@ public class Registry { PLATE_PRESS.setRegistryName(Names.PLATE_PRESS); GRAVITATION_STABILIZER.setRegistryName(Names.GRAVITATION_STABILIZER); + GRAVITATION_STABILIZER_LENS.setRegistryName(Names.GRAVITATION_STABILIZER_LENS); DEBUG_EXPLOSION_SMALL.setRegistryName(Names.DEBUG_EXPLOSION_SMALL); DEBUG_SPHERE_POINTS.setRegistryName(Names.DEBUG_SPHERE_POINTS); @@ -426,6 +429,7 @@ public class Registry { event.getRegistry().register(CHEMICAL_GENERATOR); event.getRegistry().register(PLATE_PRESS); event.getRegistry().register(GRAVITATION_STABILIZER); + event.getRegistry().register(GRAVITATION_STABILIZER_LENS); event.getRegistry().register(DEBUG_EXPLOSION_SMALL); event.getRegistry().register(DEBUG_SPHERE_POINTS); @@ -513,10 +517,10 @@ public class Registry { public static final ItemTritaniumArmor TRITANIUM_BOOTS = new ItemTritaniumArmor(EquipmentSlot.FEET); public static final Item[] TRITANIUM_ARMOR = new Item[] { - TRITANIUM_HELMET, - TRITANIUM_CHESTPLATE, - TRITANIUM_PANTS, - TRITANIUM_BOOTS + TRITANIUM_HELMET, + TRITANIUM_CHESTPLATE, + TRITANIUM_PANTS, + TRITANIUM_BOOTS }; public static final Item MATTER_IO_PORT = new Item(new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); diff --git a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java index ca08aaaae..29056fa29 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java +++ b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java @@ -367,4 +367,54 @@ public class BlockShapes { new SimpleCuboid(0.0625d, 0.5d, 0.5625d, 0.125d, 0.875d, 0.75d), new SimpleCuboid(0.775d, 0.75d, 0.125d, 0.9625d, 0.9375d, 0.875d) ); + + public static final BlockShape GRAVITATION_STABILIZER = new BlockShape( + new SimpleCuboid(0.5d, 0.0625d, 0.6875d, 0.9375d, 0.6875d, 0.875d), + new SimpleCuboid(0.0625d, 0.125d, 0.6875d, 0.125d, 0.25d, 0.875d), + new SimpleCuboid(0.0625d, 0.4375d, 0.6875d, 0.125d, 0.5625d, 0.875d), + new SimpleCuboid(0.0625d, 0.6875d, 0.6875d, 0.9375d, 0.9375d, 0.9375d), + new SimpleCuboid(0.0625d, 0.0625d, 0.5d, 0.9375d, 0.9375d, 0.6875d), + new SimpleCuboid(0.1875d, 0.1875d, 0.0625d, 0.8125d, 0.8125d, 0.375d), + new SimpleCuboid(0.75d, 0.4375d, 0d, 0.875d, 0.5625d, 0.4375d), + new SimpleCuboid(0.125d, 0.4375d, 0d, 0.25d, 0.5625d, 0.4375d), + new SimpleCuboid(0.4375d, 0.75d, 0d, 0.5625d, 0.875d, 0.4375d), + new SimpleCuboid(0.4375d, 0.125d, 0d, 0.5625d, 0.25d, 0.4375d), + new SimpleCuboid(0.125d, 0.375d, 0.6875d, 0.5d, 0.625d, 0.9375d), + new SimpleCuboid(0.125d, 0.0625d, 0.6875d, 0.5d, 0.3125d, 0.9375d), + new SimpleCuboid(0.125d, 0.125d, 0.4375d, 0.875d, 0.25d, 0.5625d), + new SimpleCuboid(0.75d, 0.25d, 0.4375d, 0.875d, 0.75d, 0.5625d), + new SimpleCuboid(0.125d, 0.25d, 0.4375d, 0.25d, 0.75d, 0.5625d), + new SimpleCuboid(0.125d, 0.75d, 0.4375d, 0.875d, 0.875d, 0.5625d), + new SimpleCuboid(0d, 0d, 0d, 0.125d, 0.125d, 1d), + new SimpleCuboid(0.875d, 0d, 0d, 1d, 0.125d, 1d), + new SimpleCuboid(0.875d, 0.875d, 0d, 1d, 1d, 1d), + new SimpleCuboid(0d, 0.875d, 0d, 0.125d, 1d, 1d), + new SimpleCuboid(0d, 0.125d, 0d, 0.125d, 0.875d, 0.0625d), + new SimpleCuboid(0.875d, 0.125d, 0d, 1d, 0.875d, 0.0625d), + new SimpleCuboid(0.0625d, 0.125d, 0.125d, 0.125d, 0.875d, 0.25d), + new SimpleCuboid(0.875d, 0.125d, 0.125d, 0.9375d, 0.875d, 0.25d), + new SimpleCuboid(0.125d, 0d, 0.875d, 0.875d, 0.125d, 1d), + new SimpleCuboid(0.125d, 0.875d, 0.875d, 0.875d, 1d, 1d), + new SimpleCuboid(0.125d, 0.875d, 0.125d, 0.875d, 0.9375d, 0.25d), + new SimpleCuboid(0.125d, 0.0625d, 0.125d, 0.875d, 0.125d, 0.25d) + ); + + public static final BlockShape GRAVITATION_STABILIZER_LENS = new BlockShape( + new SimpleCuboid(0.1875d, 0.1875d, 0.3125d, 0.8125d, 0.8125d, 0.625d), + new SimpleCuboid(0.1875d, 0.1875d, 0.6875d, 0.8125d, 0.8125d, 1d), + new SimpleCuboid(0.75d, 0.4375d, 0.25d, 0.875d, 0.5625d, 1d), + new SimpleCuboid(0.125d, 0.4375d, 0.25d, 0.25d, 0.5625d, 1d), + new SimpleCuboid(0.4375d, 0.75d, 0.25d, 0.5625d, 0.875d, 1d), + new SimpleCuboid(0.4375d, 0.125d, 0.25d, 0.5625d, 0.25d, 1d), + new SimpleCuboid(0.875d, 0d, 0.125d, 1d, 0.125d, 1d), + new SimpleCuboid(0d, 0d, 0.125d, 0.125d, 0.125d, 1d), + new SimpleCuboid(0d, 0.875d, 0.125d, 0.125d, 1d, 1d), + new SimpleCuboid(0.875d, 0.875d, 0.125d, 1d, 1d, 1d), + new SimpleCuboid(0d, 0.125d, 0.9375d, 0.125d, 0.875d, 1d), + new SimpleCuboid(0.875d, 0.125d, 0.9375d, 1d, 0.875d, 1d), + new SimpleCuboid(0.0625d, 0.125d, 0.75d, 0.125d, 0.875d, 0.875d), + new SimpleCuboid(0.875d, 0.125d, 0.75d, 0.9375d, 0.875d, 0.875d), + new SimpleCuboid(0.125d, 0.875d, 0.75d, 0.875d, 0.9375d, 0.875d), + new SimpleCuboid(0.125d, 0.0625d, 0.75d, 0.875d, 0.125d, 0.875d) + ); } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt index 9fcbc4845..880714d18 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockGravitationStabilizer.kt @@ -1,26 +1,40 @@ package ru.dbotthepony.mc.otm.block import net.minecraft.core.BlockPos +import net.minecraft.core.Direction import net.minecraft.core.SectionPos +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.item.ItemStack import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Blocks import net.minecraft.world.level.block.EntityBlock import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.entity.BlockEntityTicker import net.minecraft.world.level.block.entity.BlockEntityType +import net.minecraft.world.level.block.state.BlockBehaviour import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.material.Material import net.minecraft.world.level.material.MaterialColor +import net.minecraft.world.level.material.PushReaction +import net.minecraft.world.phys.shapes.CollisionContext +import net.minecraft.world.phys.shapes.VoxelShape +import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.Registry import ru.dbotthepony.mc.otm.block.entity.BlockEntityGravitationStabilizer import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState import ru.dbotthepony.mc.otm.core.plus import ru.dbotthepony.mc.otm.core.times +import ru.dbotthepony.mc.otm.shapes.BlockShapes +import kotlin.math.PI -class BlockGravitationStabilizer : BlockMatteryRotatable(Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3f, 600.0f)), EntityBlock { +private val props = BlockBehaviour.Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3f, 600.0f) + +class BlockGravitationStabilizer : BlockMatteryRotatable(props), EntityBlock { override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity { return BlockEntityGravitationStabilizer(p_153215_, p_153216_) } @@ -44,7 +58,7 @@ class BlockGravitationStabilizer : BlockMatteryRotatable(Properties.of(Material. } override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - val state = super.getStateForPlacement(context) ?: return null + var state = super.getStateForPlacement(context) ?: return null val blockPos = context.clickedPos val level = context.level @@ -58,12 +72,153 @@ class BlockGravitationStabilizer : BlockMatteryRotatable(Properties.of(Material. if (!getState.isAir) { if (chunk.getBlockEntity(pos) is BlockEntityBlackHole) { - return state.setValue(FACING_FULL, face) + state = state.setValue(FACING_FULL, face) + break } } } } + val bbPos = blockPos + state.getValue(FACING_FULL).normal + if (!context.level.isInWorldBounds(bbPos)) return null + + if (!level.getBlockState(bbPos).canBeReplaced(context)) return null + return state } + + override fun setPlacedBy( + level: Level, + blockPos: BlockPos, + blockState: BlockState, + entity: LivingEntity?, + itemStack: ItemStack + ) { + super.setPlacedBy(level, blockPos, blockState, entity, itemStack) + + if (!level.isClientSide) { + val bbPos = blockPos + blockState.getValue(FACING_FULL).normal + val newState = Registry.Blocks.GRAVITATION_STABILIZER_LENS.defaultBlockState() + .setValue(FACING_FULL, blockState.getValue(FACING_FULL)) + + level.setBlock(bbPos, newState, UPDATE_ALL) + } + } + + override fun getPistonPushReaction(p_60584_: BlockState): PushReaction { + return PushReaction.BLOCK + } + + override fun neighborChanged( + state: BlockState, + level: Level, + pos: BlockPos, + sender: Block, + sender_pos: BlockPos, + flag: Boolean + ) { + super.neighborChanged(state, level, pos, sender, sender_pos, flag) + + if (!level.isClientSide) { + OverdriveThatMatters.tickOnce(level) { + if (level.getBlockState(pos).block !is BlockGravitationStabilizer) return@tickOnce + + val bb = getBoundingBlock(level, state, pos) + if (bb.block !is BlockGravitationStabilizerLens) { + level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL) + } + } + } + } + + override fun getShape( + p_60555_: BlockState, + p_60556_: BlockGetter, + p_60557_: BlockPos, + p_60558_: CollisionContext + ): VoxelShape { + return SHAPES[p_60555_.getValue(FACING_FULL).ordinal] + } + + companion object { + private val SHAPES = arrayOf( + BlockShapes.GRAVITATION_STABILIZER.rotateAroundX(PI / 2).computeShape(), + BlockShapes.GRAVITATION_STABILIZER.rotateAroundX(-PI / 2).computeShape(), + BlockShapes.GRAVITATION_STABILIZER.computeShape(), + BlockShapes.GRAVITATION_STABILIZER.rotate(Direction.NORTH).computeShape(), + BlockShapes.GRAVITATION_STABILIZER.rotate(Direction.WEST).computeShape(), + BlockShapes.GRAVITATION_STABILIZER.rotate(Direction.EAST).computeShape() + ) + + fun getBoundingBlock(level: Level, blockState: BlockState, blockPos: BlockPos): BlockState { + return level.getBlockState(getBoundingBlockPos(blockState, blockPos)) + } + + fun getBoundingBlockPos(blockState: BlockState, blockPos: BlockPos): BlockPos { + return blockPos + blockState.getValue(FACING_FULL).normal + } + } +} + +class BlockGravitationStabilizerLens : BlockMatteryRotatable(props) { + override val hasFreeRotation: Boolean get() = true + + override fun createBlockStateDefinition(builder: StateDefinition.Builder) { + super.createBlockStateDefinition(builder) + builder.add(WorkerState.SEMI_WORKER_STATE) + } + + override fun getPistonPushReaction(p_60584_: BlockState): PushReaction { + return PushReaction.BLOCK + } + + override fun neighborChanged( + state: BlockState, + level: Level, + pos: BlockPos, + sender: Block, + sender_pos: BlockPos, + flag: Boolean + ) { + super.neighborChanged(state, level, pos, sender, sender_pos, flag) + + if (!level.isClientSide) { + OverdriveThatMatters.tickOnce(level) { + if (level.getBlockState(pos).block !is BlockGravitationStabilizerLens) return@tickOnce + + val bb = getBoundingBlock(level, state, pos) + if (bb.block !is BlockGravitationStabilizer) { + level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL) + } + } + } + } + + override fun getShape( + p_60555_: BlockState, + p_60556_: BlockGetter, + p_60557_: BlockPos, + p_60558_: CollisionContext + ): VoxelShape { + return SHAPES[p_60555_.getValue(FACING_FULL).ordinal] + } + + companion object { + fun getBoundingBlock(level: Level, blockState: BlockState, blockPos: BlockPos): BlockState { + return level.getBlockState(getBoundingBlockPos(blockState, blockPos)) + } + + fun getBoundingBlockPos(blockState: BlockState, blockPos: BlockPos): BlockPos { + return blockPos + blockState.getValue(FACING_FULL).opposite.normal + } + + private val SHAPES = arrayOf( + BlockShapes.GRAVITATION_STABILIZER_LENS.rotateAroundX(PI / 2).computeShape(), + BlockShapes.GRAVITATION_STABILIZER_LENS.rotateAroundX(-PI / 2).computeShape(), + BlockShapes.GRAVITATION_STABILIZER_LENS.computeShape(), + BlockShapes.GRAVITATION_STABILIZER_LENS.rotate(Direction.NORTH).computeShape(), + BlockShapes.GRAVITATION_STABILIZER_LENS.rotate(Direction.WEST).computeShape(), + BlockShapes.GRAVITATION_STABILIZER_LENS.rotate(Direction.EAST).computeShape() + ) + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityGravitationStabilizer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityGravitationStabilizer.kt index 3e33669c4..5a56002c5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityGravitationStabilizer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityGravitationStabilizer.kt @@ -11,6 +11,8 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.phys.AABB import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.Registry +import ru.dbotthepony.mc.otm.block.BlockGravitationStabilizer +import ru.dbotthepony.mc.otm.block.BlockGravitationStabilizerLens import ru.dbotthepony.mc.otm.block.BlockMatteryRotatable import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState @@ -28,7 +30,7 @@ class BlockEntityGravitationStabilizer(p_155229_: BlockPos, p_155230_: BlockStat var findBlackHole: BlockEntityBlackHole? = null val dir = blockState.getValue(BlockMatteryRotatable.FACING_FULL).normal - for (i in 1 .. RANGE) { + for (i in 2 .. RANGE) { val pos = blockPos + dir * i val chunk = level.chunkSource.getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z)) ?: continue val state = chunk.getBlockState(pos) @@ -56,6 +58,12 @@ class BlockEntityGravitationStabilizer(p_155229_: BlockPos, p_155230_: BlockStat blackHole = findBlackHole level.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, if (findBlackHole != null) WorkerState.WORKING else WorkerState.IDLE), Block.UPDATE_CLIENTS) + val posLens = BlockGravitationStabilizer.getBoundingBlockPos(blockState, blockPos) + val stateLens = level.getBlockState(posLens) + + if (stateLens.block is BlockGravitationStabilizerLens) { + level.setBlock(posLens, stateLens.setValue(WorkerState.SEMI_WORKER_STATE, if (findBlackHole != null) WorkerState.WORKING else WorkerState.IDLE), Block.UPDATE_CLIENTS) + } } } diff --git a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json index d4f7757cb..e3d36c8f6 100644 --- a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json +++ b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json @@ -170,6 +170,7 @@ "block.overdrive_that_matters.item_monitor": "Item Monitor", "block.overdrive_that_matters.plate_press": "Plate Press", "block.overdrive_that_matters.gravitation_stabilizer": "Gravitation Stabilizer", + "block.overdrive_that_matters.gravitation_stabilizer_lens": "Gravitation Stabilizer Lens", "block.overdrive_that_matters.gravitation_stabilizer.desc": "Reduces gravitation effects of singularities", "block.overdrive_that_matters.gravitation_stabilizer.desc2": "Requires no power to operate", "block.overdrive_that_matters.gravitation_stabilizer.desc3": "Keep in mind the effect of multiple stabilizers produce exponentially increasing result", diff --git a/src/main/resources/assets/overdrive_that_matters/models/block/gravitational_stabilizer_lens_idle.json b/src/main/resources/assets/overdrive_that_matters/models/block/gravitation_stabilizer_lens_idle.json similarity index 100% rename from src/main/resources/assets/overdrive_that_matters/models/block/gravitational_stabilizer_lens_idle.json rename to src/main/resources/assets/overdrive_that_matters/models/block/gravitation_stabilizer_lens_idle.json diff --git a/src/main/resources/assets/overdrive_that_matters/models/block/gravitational_stabilizer_lens_working.json b/src/main/resources/assets/overdrive_that_matters/models/block/gravitation_stabilizer_lens_working.json similarity index 100% rename from src/main/resources/assets/overdrive_that_matters/models/block/gravitational_stabilizer_lens_working.json rename to src/main/resources/assets/overdrive_that_matters/models/block/gravitation_stabilizer_lens_working.json