diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index f41f5d70c..56874d2ce 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -1126,8 +1126,8 @@ public class Registry { public static class Menus { public static final MenuType ANDROID_STATION = new MenuType<>(AndroidStationMenu::new); - public static final MenuType BATTERY_BANK = new MenuType<>(BatteryBankMenu::new); - public static final MenuType MATTER_DECOMPOSER = new MenuType<>(MatterDecomposerMenu::new); + public static final MenuType BATTERY_BANK = new MenuType<>(MenuBatteryBank::new); + public static final MenuType MATTER_DECOMPOSER = new MenuType<>(MenuMatterDecomposer::new); public static final MenuType MATTER_CAPACITOR_BANK = new MenuType<>(MenuMatterCapacitor::new); public static final MenuType PATTERN_STORAGE = new MenuType<>(MenuPatternStorage::new); public static final MenuType MATTER_SCANNER = new MenuType<>(MenuMatterScanner::new); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockBatteryBank.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockBatteryBank.kt index b216cbd94..29986f0d2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockBatteryBank.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockBatteryBank.kt @@ -35,7 +35,7 @@ class BlockBatteryBank : BlockMatteryRotatable(), EntityBlock { return state } - override fun getTicker( + override fun getTicker( level: Level, p_153213_: BlockState, type: BlockEntityType @@ -71,18 +71,18 @@ class BlockBatteryBank : BlockMatteryRotatable(), EntityBlock { companion object { @JvmField val BATTERY_SLOTS_PROPS = arrayOf( - BooleanProperty.create("battery_0"), - BooleanProperty.create("battery_1"), - BooleanProperty.create("battery_2"), - BooleanProperty.create("battery_3"), - BooleanProperty.create("battery_4"), - BooleanProperty.create("battery_5"), - BooleanProperty.create("battery_6"), - BooleanProperty.create("battery_7"), - BooleanProperty.create("battery_8"), - BooleanProperty.create("battery_9"), - BooleanProperty.create("battery_10"), - BooleanProperty.create("battery_11") + BooleanProperty.create("battery_0") as BooleanProperty, + BooleanProperty.create("battery_1") as BooleanProperty, + BooleanProperty.create("battery_2") as BooleanProperty, + BooleanProperty.create("battery_3") as BooleanProperty, + BooleanProperty.create("battery_4") as BooleanProperty, + BooleanProperty.create("battery_5") as BooleanProperty, + BooleanProperty.create("battery_6") as BooleanProperty, + BooleanProperty.create("battery_7") as BooleanProperty, + BooleanProperty.create("battery_8") as BooleanProperty, + BooleanProperty.create("battery_9") as BooleanProperty, + BooleanProperty.create("battery_10") as BooleanProperty, + BooleanProperty.create("battery_11") as BooleanProperty, ) private val SHAPES: List diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterCapacitorBank.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterCapacitorBank.kt index de9a5d9f8..573ab34dd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterCapacitorBank.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterCapacitorBank.kt @@ -1,69 +1,61 @@ -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.Direction; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.EntityBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCapacitorBank; -import ru.dbotthepony.mc.otm.shapes.BlockShapes; +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.BlockGetter +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.EntityBlock +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.phys.shapes.CollisionContext +import net.minecraft.world.phys.shapes.VoxelShape +import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCapacitorBank +import ru.dbotthepony.mc.otm.shapes.BlockShapes -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; -import java.util.List; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public class BlockMatterCapacitorBank extends BlockMatteryRotatable implements EntityBlock { - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return new BlockEntityMatterCapacitorBank(blockPos, blockState); +class BlockMatterCapacitorBank : BlockMatteryRotatable(), EntityBlock { + override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity { + return BlockEntityMatterCapacitorBank(blockPos, blockState) } - @Nullable - @Override - public BlockState getStateForPlacement(BlockPlaceContext context) { - var state = super.getStateForPlacement(context); + override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { + var state = super.getStateForPlacement(context) ?: return null - for (var prop : BlockBatteryBank.BATTERY_SLOTS_PROPS) - state = state.setValue(prop, false); + for (prop in BlockBatteryBank.BATTERY_SLOTS_PROPS) + state = state.setValue(prop, false) - return state; + return state } - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(BlockBatteryBank.BATTERY_SLOTS_PROPS); - super.createBlockStateDefinition(builder); + override fun createBlockStateDefinition(builder: StateDefinition.Builder) { + builder.add(*BlockBatteryBank.BATTERY_SLOTS_PROPS) + super.createBlockStateDefinition(builder) } - private static final List SHAPES; - - static { - var def = BlockShapes.BATTERY_BANK.computeShape(); - - SHAPES = List.of( - def, - def, - def, - BlockShapes.BATTERY_BANK.rotate(Direction.NORTH).computeShape(), - BlockShapes.BATTERY_BANK.rotate(Direction.WEST).computeShape(), - BlockShapes.BATTERY_BANK.rotate(Direction.EAST).computeShape() - ); + override fun getShape( + p_60555_: BlockState, + p_60556_: BlockGetter, + p_60557_: BlockPos, + p_60558_: CollisionContext + ): VoxelShape { + return SHAPES[p_60555_.getValue(FACING).ordinal] } - @Override - @SuppressWarnings("deprecation") - public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) { - return SHAPES.get(p_60555_.getValue(FACING).ordinal()); + companion object { + private val SHAPES: List + + init { + val def = BlockShapes.BATTERY_BANK.computeShape() + + SHAPES = listOf( + def, + def, + def, + BlockShapes.BATTERY_BANK.rotate(Direction.NORTH).computeShape(), + BlockShapes.BATTERY_BANK.rotate(Direction.WEST).computeShape(), + BlockShapes.BATTERY_BANK.rotate(Direction.EAST).computeShape() + ) + } } -} +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterPanel.kt index 22b217102..d83a21cb4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockMatterPanel.kt @@ -1,120 +1,103 @@ -package ru.dbotthepony.mc.otm.block; +package ru.dbotthepony.mc.otm.block -import com.google.common.collect.ImmutableMap; -import net.minecraft.MethodsReturnNonnullByDefault; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.EntityBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterPanel; +import com.google.common.collect.ImmutableMap +import net.minecraft.world.level.block.EntityBlock +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.entity.BlockEntity +import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterPanel +import net.minecraft.world.phys.shapes.VoxelShape +import net.minecraft.world.phys.shapes.Shapes +import net.minecraft.world.level.BlockGetter +import net.minecraft.world.phys.shapes.CollisionContext +import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.state.properties.EnumProperty -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public class BlockMatterPanel extends BlockMattery implements EntityBlock { - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return new BlockEntityMatterPanel(blockPos, blockState); +class BlockMatterPanel : BlockMattery(), EntityBlock { + override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity { + return BlockEntityMatterPanel(blockPos, blockState) } - public static final EnumProperty FACING = EnumProperty.create( - "facing", - Direction.class); + private val shapes: ImmutableMap - private ImmutableMap SHAPES; + init { + registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.SOUTH)) - public BlockMatterPanel() { - super(); - - registerDefaultState(this.getStateDefinition().any().setValue(FACING, Direction.SOUTH)); - - SHAPES = getShapeForEachState(blockstate -> { - return switch (blockstate.getValue(FACING)) { - case NORTH -> Shapes.box( - 0.0d, - 0.0d, - 0.625d, - - 1.0d, - 1.0d, - 1.0d - ); - case EAST -> Shapes.box( - 0.0d, - 0.0d, - 0.0d, - - 0.375d, - 1.0d, - 1.0d - ); - case WEST -> Shapes.box( - 0.625d, - 0.0d, - 0.0d, - - 1.0d, - 1.0d, - 1.0d - ); - case DOWN -> Shapes.box( - 0.0d, - 0.625d, - 0.0d, - - 1.0d, - 1.0d, - 1.0d - ); - case UP -> Shapes.box( - 0.0d, - 0.0d, - 0.0d, - - 1.0d, - 0.375d, - 1.0d - ); - default -> Shapes.box( - 0.0d, - 0.0d, - 0.0d, - - 1.0d, - 1.0d, - 0.375d - ); - }; - }); + shapes = getShapeForEachState { + when (it.getValue(FACING)) { + Direction.NORTH -> Shapes.box( + 0.0, + 0.0, + 0.625, + 1.0, + 1.0, + 1.0 + ) + Direction.EAST -> Shapes.box( + 0.0, + 0.0, + 0.0, + 0.375, + 1.0, + 1.0 + ) + Direction.WEST -> Shapes.box( + 0.625, + 0.0, + 0.0, + 1.0, + 1.0, + 1.0 + ) + Direction.DOWN -> Shapes.box( + 0.0, + 0.625, + 0.0, + 1.0, + 1.0, + 1.0 + ) + Direction.UP -> Shapes.box( + 0.0, + 0.0, + 0.0, + 1.0, + 0.375, + 1.0 + ) + else -> Shapes.box( + 0.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.375 + ) + } + } } - @Override - @SuppressWarnings("deprecation") - public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) { - return SHAPES.get(p_60555_); + override fun getShape( + p_60555_: BlockState, + p_60556_: BlockGetter, + p_60557_: BlockPos, + p_60558_: CollisionContext + ): VoxelShape { + return shapes[p_60555_]!! } - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(FACING); + override fun createBlockStateDefinition(builder: StateDefinition.Builder) { + builder.add(FACING) } - @Nullable - @Override - public BlockState getStateForPlacement(BlockPlaceContext context) { - return this.defaultBlockState().setValue(FACING, context.getClickedFace()); + override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { + return defaultBlockState().setValue(FACING, context.clickedFace) } -} + companion object { + val FACING = EnumProperty.create("facing", Direction::class.java) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockPatternStorage.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockPatternStorage.kt index e1a330802..e91aae7b7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockPatternStorage.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/BlockPatternStorage.kt @@ -1,80 +1,73 @@ -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.Direction; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.EntityBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.VoxelShape; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityPatternStorage; -import ru.dbotthepony.mc.otm.shapes.BlockShapes; +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.BlockGetter +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.EntityBlock +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.level.block.state.properties.BooleanProperty +import net.minecraft.world.phys.shapes.CollisionContext +import net.minecraft.world.phys.shapes.VoxelShape +import ru.dbotthepony.mc.otm.block.entity.BlockEntityPatternStorage +import ru.dbotthepony.mc.otm.shapes.BlockShapes -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; -import java.util.List; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public class BlockPatternStorage extends BlockMatteryRotatable implements EntityBlock { - public static final BooleanProperty[] PATTERN_STORAGE_DISKS_PROPS = new BooleanProperty[] { - BooleanProperty.create("disk_0"), - BooleanProperty.create("disk_1"), - BooleanProperty.create("disk_2"), - BooleanProperty.create("disk_3"), - BooleanProperty.create("disk_4"), - BooleanProperty.create("disk_5"), - BooleanProperty.create("disk_6"), - BooleanProperty.create("disk_7"), - }; - - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return new BlockEntityPatternStorage(blockPos, blockState); +class BlockPatternStorage : BlockMatteryRotatable(), EntityBlock { + override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? { + return BlockEntityPatternStorage(blockPos, blockState) } - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(PATTERN_STORAGE_DISKS_PROPS); - super.createBlockStateDefinition(builder); + override fun createBlockStateDefinition(builder: StateDefinition.Builder) { + builder.add(*PATTERN_STORAGE_DISKS_PROPS) + super.createBlockStateDefinition(builder) } - @Nullable - @Override - public BlockState getStateForPlacement(BlockPlaceContext context) { - var state = super.getStateForPlacement(context); + override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { + var state = super.getStateForPlacement(context) ?: return null - for (var prop : PATTERN_STORAGE_DISKS_PROPS) - state = state.setValue(prop, false); + for (prop in PATTERN_STORAGE_DISKS_PROPS) + state = state.setValue(prop, false) - return state; + return state } - private static final List SHAPES; - - static { - var def = BlockShapes.PATTERN_STORAGE.computeShape(); - - SHAPES = List.of( - def, - def, - def, - BlockShapes.PATTERN_STORAGE.rotate(Direction.NORTH).computeShape(), - BlockShapes.PATTERN_STORAGE.rotate(Direction.WEST).computeShape(), - BlockShapes.PATTERN_STORAGE.rotate(Direction.EAST).computeShape() - ); + override fun getShape( + p_60555_: BlockState, + p_60556_: BlockGetter, + p_60557_: BlockPos, + p_60558_: CollisionContext + ): VoxelShape { + return SHAPES[p_60555_.getValue(FACING).ordinal] } - @Override - @SuppressWarnings("deprecation") - public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) { - return SHAPES.get(p_60555_.getValue(FACING).ordinal()); + companion object { + val PATTERN_STORAGE_DISKS_PROPS = arrayOf( + BooleanProperty.create("disk_0") as BooleanProperty, + BooleanProperty.create("disk_1") as BooleanProperty, + BooleanProperty.create("disk_2") as BooleanProperty, + BooleanProperty.create("disk_3") as BooleanProperty, + BooleanProperty.create("disk_4") as BooleanProperty, + BooleanProperty.create("disk_5") as BooleanProperty, + BooleanProperty.create("disk_6") as BooleanProperty, + BooleanProperty.create("disk_7") as BooleanProperty + ) + + private val SHAPES: List + + init { + val def = BlockShapes.PATTERN_STORAGE.computeShape() + + SHAPES = listOf( + def, + def, + def, + BlockShapes.PATTERN_STORAGE.rotate(Direction.NORTH).computeShape(), + BlockShapes.PATTERN_STORAGE.rotate(Direction.WEST).computeShape(), + BlockShapes.PATTERN_STORAGE.rotate(Direction.EAST).computeShape() + ) + } } -} +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityBatteryBank.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityBatteryBank.kt index 3e1e8b2f5..b374bf3d8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityBatteryBank.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityBatteryBank.kt @@ -28,7 +28,7 @@ import ru.dbotthepony.mc.otm.capability.extractEnergy import ru.dbotthepony.mc.otm.capability.receiveEnergy import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.core.Fraction -import ru.dbotthepony.mc.otm.menu.BatteryBankMenu +import ru.dbotthepony.mc.otm.menu.MenuBatteryBank import ru.dbotthepony.mc.otm.set import ru.dbotthepony.mc.otm.unaryMinus import javax.annotation.ParametersAreNonnullByDefault @@ -37,7 +37,7 @@ import javax.annotation.ParametersAreNonnullByDefault @ParametersAreNonnullByDefault class BlockEntityBatteryBank(p_155229_: BlockPos, p_155230_: BlockState) : BlockEntityMattery(Registry.BlockEntities.BATTERY_BANK, p_155229_, p_155230_) { // 6 на 2 - val container: MatteryContainer = object : MatteryContainer(this::setChanged, 6 * 2) { + val container: MatteryContainer = object : MatteryContainer(this::setChanged, CAPACITY) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) @@ -247,16 +247,12 @@ class BlockEntityBatteryBank(p_155229_: BlockPos, p_155230_: BlockState) : Block super.load(nbt) } - companion object { - private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.battery_bank") - } - override fun getDefaultDisplayName(): Component { return MACHINE_NAME } - override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu? { - return BatteryBankMenu(containerID, inventory, this, container) + override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { + return MenuBatteryBank(containerID, inventory, this) } override fun invalidateCaps() { @@ -351,4 +347,9 @@ class BlockEntityBatteryBank(p_155229_: BlockPos, p_155230_: BlockState) : Block } } } + + companion object { + private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.battery_bank") + const val CAPACITY = 6 * 2 + } } \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt index 6f76ed7f7..42f1b59b4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterDecomposer.kt @@ -31,7 +31,7 @@ import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import ru.dbotthepony.mc.otm.ifHas import ru.dbotthepony.mc.otm.matter.MatterRegistry -import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu +import ru.dbotthepony.mc.otm.menu.MenuMatterDecomposer import ru.dbotthepony.mc.otm.set class BlockEntityMatterDecomposer(pos: BlockPos, state: BlockState) @@ -80,7 +80,7 @@ class BlockEntityMatterDecomposer(pos: BlockPos, state: BlockState) } override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { - return MatterDecomposerMenu(containerID, inventory, this) + return MenuMatterDecomposer(containerID, inventory, this) } override fun saveAdditional(nbt: CompoundTag) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenBatteryBank.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenBatteryBank.kt index f97136c47..b7ffc1a67 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenBatteryBank.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenBatteryBank.kt @@ -1,25 +1,25 @@ package ru.dbotthepony.mc.otm.client.screen import net.minecraft.network.chat.Component -import ru.dbotthepony.mc.otm.menu.BatteryBankMenu +import ru.dbotthepony.mc.otm.menu.MenuBatteryBank import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel -class ScreenBatteryBank(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Component) : - MatteryScreen(menu, p_97742_, p_97743_) { +class ScreenBatteryBank(menu: MenuBatteryBank, p_97742_: Inventory, p_97743_: Component) : + MatteryScreen(menu, p_97742_, p_97743_) { override fun makeMainFrame(): FramePanel{ val frame = super.makeMainFrame()!! - PowerGaugePanel(this, frame, menu.battery_widget, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT) + PowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT) for (i in 0 .. 5) - SlotPanel(this, frame, menu.battery_slots[i], 44f + 18 * i, 32f) + SlotPanel(this, frame, menu.containerSlots[i], 44f + 18 * i, 32f) for (i in 6 .. 11) - SlotPanel(this, frame, menu.battery_slots[i], 44f + 18 * (i - 6), 32f + 18f) + SlotPanel(this, frame, menu.containerSlots[i], 44f + 18 * (i - 6), 32f + 18f) return frame } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenMatterDecomposer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenMatterDecomposer.kt index 39634278b..3c7459a35 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenMatterDecomposer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ScreenMatterDecomposer.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.mc.otm.client.screen import net.minecraft.network.chat.Component -import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu +import ru.dbotthepony.mc.otm.menu.MenuMatterDecomposer import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel @@ -9,19 +9,19 @@ import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel -class ScreenMatterDecomposer(p_97741_: MatterDecomposerMenu, p_97742_: Inventory, p_97743_: Component) : - MatteryScreen(p_97741_, p_97742_, p_97743_) { +class ScreenMatterDecomposer(p_97741_: MenuMatterDecomposer, p_97742_: Inventory, p_97743_: Component) : + MatteryScreen(p_97741_, p_97742_, p_97743_) { override fun makeMainFrame(): FramePanel { val frame = super.makeMainFrame()!! val m = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) - MatterGaugePanel(this, frame, menu.matter_widget, LEFT_MARGIN + m.width, GAUGE_TOP_WITH_SLOT) + MatterGaugePanel(this, frame, menu.matterWidget, LEFT_MARGIN + m.width, GAUGE_TOP_WITH_SLOT) SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.input, 56f, PROGRESS_SLOT_TOP) - ProgressGaugePanel(this, frame, menu.progress, 78f, PROGRESS_ARROW_TOP) + ProgressGaugePanel(this, frame, menu.progressWidget, 78f, PROGRESS_ARROW_TOP) SlotPanel(this, frame, menu.output, 104f, PROGRESS_SLOT_TOP) return frame diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuBatteryBank.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuBatteryBank.kt index 6f026343f..5d12dee40 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuBatteryBank.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuBatteryBank.kt @@ -1,50 +1,40 @@ -package ru.dbotthepony.mc.otm.menu; +package ru.dbotthepony.mc.otm.menu -import net.minecraft.world.Container; -import net.minecraft.world.SimpleContainer; -import net.minecraft.world.entity.player.Inventory; -import ru.dbotthepony.mc.otm.Registry; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityBatteryBank; -import ru.dbotthepony.mc.otm.capability.MatteryCapability; -import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget; +import net.minecraft.world.Container +import kotlin.jvm.JvmOverloads +import net.minecraft.world.entity.player.Inventory +import ru.dbotthepony.mc.otm.block.entity.BlockEntityBatteryBank +import net.minecraft.world.SimpleContainer +import ru.dbotthepony.mc.otm.Registry +import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget +import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.orNull -public class BatteryBankMenu extends MatteryMenu { - protected BlockEntityBatteryBank tile; +class MenuBatteryBank @JvmOverloads constructor( + p_38852_: Int, + inventory: Inventory, + tile: BlockEntityBatteryBank? = null, +) : MatteryMenu(Registry.Menus.BATTERY_BANK, p_38852_, inventory, tile) { + val powerLevel: LevelGaugeWidget + val containerSlots: Array - public LevelGaugeWidget battery_widget; - public BatterySlot[] battery_slots = new BatterySlot[6 * 2]; - - public BatteryBankMenu(int p_38852_, Inventory inventory) { - this(p_38852_, inventory, null, new SimpleContainer(6 * 2)); - } - - public BatteryBankMenu(int p_38852_, Inventory inventory, BlockEntityBatteryBank tile, Container batteries) { - super(Registry.Menus.BATTERY_BANK, p_38852_, inventory, tile); - this.tile = tile; - - if (tile == null || tile.getCapability(MatteryCapability.ENERGY).resolve().isEmpty()) { - battery_widget = new LevelGaugeWidget(this); - } else { - battery_widget = new LevelGaugeWidget(this, tile.getCapability(MatteryCapability.ENERGY).resolve().get()); + init { + val container: Container = tile?.container ?: SimpleContainer(BlockEntityBatteryBank.CAPACITY) + powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull()) + containerSlots = Array(BlockEntityBatteryBank.CAPACITY) { + val slot = BatterySlot(container, it) + addSlot(slot) + return@Array slot } - for (int row = 0; row < 2; row++) { - for (int column = 0; column < 6; column++) { - battery_slots[row * 6 + column] = new BatterySlot(batteries, row * 6 + column, 44 + column * 18, 24 + row * 18); - addSlot(battery_slots[row * 6 + column]); - } - } - - addInventorySlots(); + addInventorySlots() } - @Override - protected int getWorkingSlotStart() { - return 0; + override fun getWorkingSlotStart(): Int { + return 0 } - @Override - protected int getWorkingSlotEnd() { - return 6 * 2; + override fun getWorkingSlotEnd(): Int { + return BlockEntityBatteryBank.CAPACITY } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuMatterDecomposer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuMatterDecomposer.kt index 668ef5857..656e5746a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuMatterDecomposer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MenuMatterDecomposer.kt @@ -1,64 +1,59 @@ -package ru.dbotthepony.mc.otm.menu; +package ru.dbotthepony.mc.otm.menu -import net.minecraft.world.Container; -import net.minecraft.world.SimpleContainer; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.item.ItemStack; -import ru.dbotthepony.mc.otm.matter.MatterRegistry; -import ru.dbotthepony.mc.otm.Registry; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer; -import ru.dbotthepony.mc.otm.capability.MatteryCapability; -import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget; -import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget; +import kotlin.jvm.JvmOverloads +import net.minecraft.world.entity.player.Inventory +import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer +import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget +import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget +import net.minecraft.world.SimpleContainer +import net.minecraft.world.item.ItemStack +import ru.dbotthepony.mc.otm.Registry +import ru.dbotthepony.mc.otm.matter.MatterRegistry +import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.orNull -import javax.annotation.Nullable; +class MenuMatterDecomposer @JvmOverloads constructor( + containerID: Int, + inventory: Inventory, + tile: BlockEntityMatterDecomposer? = null +) : MenuMatteryPowered(Registry.Menus.MATTER_DECOMPOSER, containerID, inventory, tile) { + val input: MatterySlot + val output: MachineOutputSlot + val progressWidget: ProgressGaugeWidget + val matterWidget: LevelGaugeWidget -public class MatterDecomposerMenu extends MenuMatteryPowered { - public MatterDecomposerMenu(int containerID, Inventory inventory) { - this(containerID, inventory, null); - } - - public MatterySlot input; - public MachineOutputSlot output; - public ProgressGaugeWidget progress; - public LevelGaugeWidget matter_widget; - - public MatterDecomposerMenu(int containerID, Inventory inventory, @Nullable BlockEntityMatterDecomposer tile) { - super(Registry.Menus.MATTER_DECOMPOSER, containerID, inventory, tile); - Container container = tile != null ? tile.itemContainer : new SimpleContainer(2); + init { + val container = tile?.itemContainer ?: SimpleContainer(2) // Вход - input = new MatterySlot(container, 0, 61, 36) { - @Override - public boolean mayPlace(ItemStack p_40231_) { - return MatterRegistry.canDecompose(p_40231_); + input = object : MatterySlot(container, 0, 61, 36) { + override fun mayPlace(p_40231_: ItemStack): Boolean { + return MatterRegistry.canDecompose(p_40231_) } - }; - - addSlot(input); - - // Выход - output = new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36); - addSlot(output); - - if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) { - matter_widget = new LevelGaugeWidget(this); - progress = new ProgressGaugeWidget(this); - } else { - matter_widget = new LevelGaugeWidget(this, tile.getCapability(MatteryCapability.MATTER).resolve().get()); - progress = new ProgressGaugeWidget(this, () -> (float) tile.getWorkProgress(), tile::isUnableToProcess); } - addInventorySlots(); + addSlot(input) + + // Выход + output = MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36) + addSlot(output) + + matterWidget = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.MATTER)?.orNull()) + + if (tile == null) { + progressWidget = ProgressGaugeWidget(this) + } else { + progressWidget = ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) + } + + addInventorySlots() } - @Override - protected int getWorkingSlotStart() { - return 0; + override fun getWorkingSlotStart(): Int { + return 0 } - @Override - protected int getWorkingSlotEnd() { - return 1; + override fun getWorkingSlotEnd(): Int { + return 2 } -} +} \ No newline at end of file