Gravitation stabilizer lens

This commit is contained in:
DBotThePony 2022-01-24 12:21:34 +07:00
parent d5a4b43d73
commit 7826e5d842
Signed by: DBot
GPG Key ID: DCC23B5715498507
9 changed files with 228 additions and 9 deletions

View File

@ -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

View File

@ -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) {

View File

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

View File

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

View File

@ -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<Block, BlockState>) {
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()
)
}
}

View File

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

View File

@ -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",