Move more to kotlin, add shapes and locale to item monitor and drive rack

This commit is contained in:
DBotThePony 2022-01-01 13:35:41 +07:00
parent 59a30e4935
commit 9261562de7
Signed by: DBot
GPG Key ID: DCC23B5715498507
6 changed files with 165 additions and 120 deletions

View File

@ -11,6 +11,8 @@ const models = [
['chemical_generator', 'chemical_generator_idle'], ['chemical_generator', 'chemical_generator_idle'],
['matter_bottler', 'matter_bottler_idle'], ['matter_bottler', 'matter_bottler_idle'],
'drive_rack',
'item_monitor',
]; ];
const fs = require('fs') const fs = require('fs')

View File

@ -1,55 +1,62 @@
package ru.dbotthepony.mc.otm.block; package ru.dbotthepony.mc.otm.block
import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos
import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level
import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.entity.BlockEntityTicker; 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.minecraft.world.level.material.Material
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor
import net.minecraft.world.level.material.MaterialColor; 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 ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.block.entity.BlockEntityBlackHole
import ru.dbotthepony.mc.otm.block.entity.BlockEntityBlackHole; import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
import javax.annotation.Nullable; class BlockBlackHole :
import javax.annotation.ParametersAreNonnullByDefault; Block(Properties.of(Material.Builder(MaterialColor.COLOR_BLACK).noCollider().nonSolid().build()).strength(-1f, 7200000.0f)), EntityBlock {
override fun getShape(
@MethodsReturnNonnullByDefault p_60555_: BlockState,
@ParametersAreNonnullByDefault p_60556_: BlockGetter,
public class BlockBlackHole extends Block implements EntityBlock { p_60557_: BlockPos,
public BlockBlackHole() { p_60558_: CollisionContext
super(Properties.of( ): VoxelShape {
new Material.Builder(MaterialColor.COLOR_BLACK).noCollider().nonSolid().build() return SHAPE
).strength(-1, 7200000.0F));
} }
public static final VoxelShape SHAPE = BlockShapes.BLACK_HOLE.computeShape(); override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return BlockEntityBlackHole(blockPos, blockState)
@Override
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
return SHAPE;
} }
@Nullable override fun <T : BlockEntity?> getTicker(
@Override p_153212_: Level,
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { p_153213_: BlockState,
return new BlockEntityBlackHole(blockPos, blockState); p_153214_: BlockEntityType<T>
): BlockEntityTicker<T>? {
if (p_153214_ !== Registry.BlockEntities.BLACK_HOLE) return null
return if (p_153212_.isClientSide) BlockEntityTicker { level: Level, blockPos: BlockPos, blockState: BlockState, t: T ->
BlockEntityBlackHole.clientTicker(
level,
blockPos,
blockState,
t
)
} else BlockEntityTicker { level: Level, blockPos: BlockPos, blockState: BlockState, t: T ->
BlockEntityBlackHole.ticker(
level,
blockPos,
blockState,
t
)
}
} }
@Nullable companion object {
@Override private val SHAPE = BlockShapes.BLACK_HOLE.computeShape()
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
if (p_153214_ != Registry.BlockEntities.BLACK_HOLE)
return null;
return p_153212_.isClientSide ? BlockEntityBlackHole::clientTicker : BlockEntityBlackHole::ticker;
} }
} }

View File

@ -1,56 +1,52 @@
package ru.dbotthepony.mc.otm.block; package ru.dbotthepony.mc.otm.block
import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos
import net.minecraft.core.BlockPos; import net.minecraft.world.Containers
import net.minecraft.world.Containers; import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level
import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty
import net.minecraft.world.level.block.state.properties.BooleanProperty; import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate
import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate;
import javax.annotation.Nullable; class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock {
import javax.annotation.ParametersAreNonnullByDefault; override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
return BlockEntityCargoCrate(blockPos, blockState)
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockCargoCrate extends BlockMatteryRotatable implements EntityBlock {
public static final BooleanProperty IS_OPEN = BooleanProperty.create("open");
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new BlockEntityCargoCrate(blockPos, blockState);
} }
@Override override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { super.createBlockStateDefinition(builder)
super.createBlockStateDefinition(builder); builder.add(IS_OPEN)
builder.add(IS_OPEN);
} }
@Nullable override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
@Override return super.getStateForPlacement(context)!!.setValue(IS_OPEN, false)
public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(IS_OPEN, false);
} }
@Override override fun onRemove(
@SuppressWarnings("deprecation") old_block_state: BlockState,
public void onRemove(BlockState old_block_state, Level level, BlockPos block_pos, BlockState new_block_state, boolean p_51542_) { level: Level,
if (!old_block_state.is(new_block_state.getBlock())) { block_pos: BlockPos,
BlockEntity blockentity = level.getBlockEntity(block_pos); new_block_state: BlockState,
p_51542_: Boolean
) {
if (!old_block_state.`is`(new_block_state.block)) {
val blockentity = level.getBlockEntity(block_pos)
if (blockentity instanceof BlockEntityCargoCrate crate) { if (blockentity is BlockEntityCargoCrate) {
Containers.dropContents(level, block_pos, crate.container); Containers.dropContents(level, block_pos, blockentity.container);
level.updateNeighbourForOutputSignal(block_pos, this); level.updateNeighbourForOutputSignal(block_pos, this);
} }
super.onRemove(old_block_state, level, block_pos, new_block_state, p_51542_); super.onRemove(old_block_state, level, block_pos, new_block_state, p_51542_)
} }
} }
companion object {
@JvmField
val IS_OPEN = BooleanProperty.create("open")
}
} }

View File

@ -1,21 +1,40 @@
package ru.dbotthepony.mc.otm.block; package ru.dbotthepony.mc.otm.block
import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos
import net.minecraft.core.BlockPos; import net.minecraft.core.Direction
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.entity.BlockEntity
import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveRack; import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveRack
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import javax.annotation.Nullable; class BlockDriveRack : BlockMatteryRotatable(), EntityBlock {
import javax.annotation.ParametersAreNonnullByDefault; override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return BlockEntityDriveRack(blockPos, blockState)
}
@MethodsReturnNonnullByDefault override fun getShape(
@ParametersAreNonnullByDefault p_60555_: BlockState,
public class BlockDriveRack extends BlockMatteryRotatable implements EntityBlock { p_60556_: BlockGetter,
@Nullable p_60557_: BlockPos,
@Override p_60558_: CollisionContext
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { ): VoxelShape {
return new BlockEntityDriveRack(blockPos, blockState); return SHAPES[p_60555_.getValue(FACING).ordinal]
}
companion object {
private val def = BlockShapes.DRIVE_RACK.computeShape()
private val SHAPES: List<VoxelShape> = listOf(
def,
def,
def,
BlockShapes.DRIVE_RACK.rotate(Direction.NORTH).computeShape(),
BlockShapes.DRIVE_RACK.rotate(Direction.WEST).computeShape(),
BlockShapes.DRIVE_RACK.rotate(Direction.EAST).computeShape()
)
} }
} }

View File

@ -1,21 +1,40 @@
package ru.dbotthepony.mc.otm.block; package ru.dbotthepony.mc.otm.block
import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos
import net.minecraft.core.BlockPos; import net.minecraft.core.Direction
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.entity.BlockEntity
import ru.dbotthepony.mc.otm.block.entity.BlockEntityItemMonitor; import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.entity.BlockEntityItemMonitor
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import javax.annotation.Nullable; class BlockItemMonitor : BlockMatteryRotatable(), EntityBlock {
import javax.annotation.ParametersAreNonnullByDefault; override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return BlockEntityItemMonitor(blockPos, blockState)
}
@MethodsReturnNonnullByDefault override fun getShape(
@ParametersAreNonnullByDefault p_60555_: BlockState,
public class BlockItemMonitor extends BlockMatteryRotatable implements EntityBlock { p_60556_: BlockGetter,
@Nullable p_60557_: BlockPos,
@Override p_60558_: CollisionContext
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { ): VoxelShape {
return new BlockEntityItemMonitor(blockPos, blockState); return SHAPES[p_60555_.getValue(FACING).ordinal]
}
companion object {
private val def = BlockShapes.ITEM_MONITOR.computeShape()
private val SHAPES: List<VoxelShape> = listOf(
def,
def,
def,
BlockShapes.ITEM_MONITOR.rotate(Direction.NORTH).computeShape(),
BlockShapes.ITEM_MONITOR.rotate(Direction.WEST).computeShape(),
BlockShapes.ITEM_MONITOR.rotate(Direction.EAST).computeShape()
)
} }
} }

View File

@ -154,6 +154,8 @@
"block.overdrive_that_matters.black_hole": "Local Anomalous Singular Gravitation Field", "block.overdrive_that_matters.black_hole": "Local Anomalous Singular Gravitation Field",
"block.overdrive_that_matters.energy_counter": "Energy Counter", "block.overdrive_that_matters.energy_counter": "Energy Counter",
"block.overdrive_that_matters.chemical_generator": "Chemical Generator", "block.overdrive_that_matters.chemical_generator": "Chemical Generator",
"block.overdrive_that_matters.drive_rack": "Condensation Drive Rack",
"block.overdrive_that_matters.item_monitor": "Item Monitor",
"otm.container.matter_panel.number_input": "Input replication task count", "otm.container.matter_panel.number_input": "Input replication task count",