Move cargo crate and android station to kotlin, implement comparator for cargo crate

This commit is contained in:
DBotThePony 2022-01-23 15:28:55 +07:00
parent ecde930bcd
commit 5dbd634215
Signed by: DBot
GPG Key ID: DCC23B5715498507
10 changed files with 233 additions and 262 deletions

View File

@ -25,12 +25,6 @@ public class MatterPanelScreen extends MatteryScreen<MenuMatterPanel> {
private static final int MODAL_WIDTH = 213; private static final int MODAL_WIDTH = 213;
private static final int MODAL_HEIGHT = 110; private static final int MODAL_HEIGHT = 110;
protected static final ResourceLocation CONTAINER = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/matter_panel.png");
protected ResourceLocation CONTAINER_BACKGROUND() {
return CONTAINER;
}
public MatterPanelScreen(MenuMatterPanel p_97741_, Inventory p_97742_, Component p_97743_) { public MatterPanelScreen(MenuMatterPanel p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_); super(p_97741_, p_97742_, p_97743_);

View File

@ -104,11 +104,11 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
public FramePanel main_frame; public FramePanel main_frame;
private boolean made_main_frame = false; private boolean made_main_frame = false;
public static final int DEFAULT_FRAME_WIDTH = 18 * 9 + 16; public static final float DEFAULT_FRAME_WIDTH = 18 * 9 + 16;
public static final int DEFAULT_FRAME_HEIGHT = 100; public static final float DEFAULT_FRAME_HEIGHT = 100;
public static final int INVENTORY_FRAME_WIDTH = DEFAULT_FRAME_WIDTH; public static final float INVENTORY_FRAME_WIDTH = DEFAULT_FRAME_WIDTH;
public static final int INVENTORY_FRAME_HEIGHT = 3 * 18 + 18 + 24; public static final float INVENTORY_FRAME_HEIGHT = 3 * 18 + 18 + 24;
public MatteryScreen(T menu, Inventory inventory, Component title) { public MatteryScreen(T menu, Inventory inventory, Component title) {
super(menu, inventory, title); super(menu, inventory, title);

View File

@ -12,6 +12,7 @@ import net.minecraft.nbt.Tag
import net.minecraft.world.Container import net.minecraft.world.Container
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import net.minecraftforge.common.util.LazyOptional
import java.util.function.Consumer import java.util.function.Consumer
operator fun Direction.unaryMinus(): Direction = this.opposite operator fun Direction.unaryMinus(): Direction = this.opposite
@ -58,3 +59,11 @@ inline fun <reified T : Tag> CompoundTag.ifHas(s: String, type: Class<T>, consum
consumer(tag as T) consumer(tag as T)
} }
} }
fun <T> LazyOptional<T>.orNull(): T? {
if (!isPresent) {
return null
}
return resolve().orElse(null)
}

View File

@ -1,64 +1,68 @@
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.InteractionHand
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult
import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player
import net.minecraft.world.entity.player.Player; 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.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.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 ru.dbotthepony.mc.otm.Registry
import net.minecraftforge.common.util.LazyOptional; import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation; import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability; import ru.dbotthepony.mc.otm.orNull
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
import javax.annotation.Nullable; class BlockAndroidStation : BlockMattery(), EntityBlock {
import javax.annotation.ParametersAreNonnullByDefault; override fun use(
blockState: BlockState,
level: Level,
blockPos: BlockPos,
ply: Player,
hand: InteractionHand,
blockHitResult: BlockHitResult
): InteractionResult {
val cap = ply.getCapability(MatteryCapability.ANDROID).orNull() ?: return InteractionResult.FAIL
@MethodsReturnNonnullByDefault if (!cap.isAndroid())
@ParametersAreNonnullByDefault return InteractionResult.FAIL
public class BlockAndroidStation extends BlockMattery implements EntityBlock {
private final VoxelShape SHAPE = BlockShapes.ANDROID_STATION.computeShape();
public BlockAndroidStation() { return super.use(blockState, level, blockPos, ply, hand, blockHitResult)
super();
} }
@Override override fun getShape(
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player ply, InteractionHand hand, BlockHitResult blockHitResult) { p_151964_: BlockState,
LazyOptional<IAndroidCapability> cap = ply.getCapability(MatteryCapability.ANDROID); p_151965_: BlockGetter,
p_151966_: BlockPos,
if (cap.resolve().isEmpty() || !cap.resolve().get().isAndroid()) p_151967_: CollisionContext
return InteractionResult.FAIL; ): VoxelShape {
return SHAPE
return super.use(blockState, level, blockPos, ply, hand, blockHitResult);
} }
@Override override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity {
@SuppressWarnings("deprecation") return BlockEntityAndroidStation(pos, state)
public VoxelShape getShape(BlockState p_151964_, BlockGetter p_151965_, BlockPos p_151966_, CollisionContext p_151967_) {
return SHAPE;
} }
@Nullable override fun <T : BlockEntity?> getTicker(
@Override level: Level,
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { state: BlockState,
return new BlockEntityAndroidStation(pos, state); type: BlockEntityType<T>
): BlockEntityTicker<T>? {
if (level.isClientSide || type !== Registry.BlockEntities.ANDROID_STATION)
return null
return BlockEntityTicker { _, _, _, t -> if (t is BlockEntityAndroidStation) t.tick() }
} }
@Nullable companion object {
@Override private val SHAPE = BlockShapes.ANDROID_STATION.computeShape()
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return level.isClientSide || type != Registry.BlockEntities.ANDROID_STATION ? null : BlockEntityAndroidStation::tick;
} }
} }

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.Containers import net.minecraft.world.Containers
import net.minecraft.world.inventory.AbstractContainerMenu
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
@ -13,7 +14,7 @@ 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
class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock { class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? { override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return BlockEntityCargoCrate(blockPos, blockState) return BlockEntityCargoCrate(blockPos, blockState)
} }
@ -23,7 +24,7 @@ class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock {
} }
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
return super.getStateForPlacement(context)!!.setValue(IS_OPEN, false) return super.getStateForPlacement(context)?.setValue(IS_OPEN, false)
} }
override fun onRemove( override fun onRemove(
@ -45,6 +46,15 @@ class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock {
} }
} }
override fun hasAnalogOutputSignal(p_60457_: BlockState): Boolean {
return true
}
override fun getAnalogOutputSignal(p_60487_: BlockState, level: Level, p_60489_: BlockPos): Int {
val tile = level.getBlockEntity(p_60489_) as? BlockEntityCargoCrate ?: return 0
return AbstractContainerMenu.getRedstoneSignalFromContainer(tile.container)
}
companion object { companion object {
@JvmField @JvmField
val IS_OPEN = BooleanProperty.create("open") val IS_OPEN = BooleanProperty.create("open")

View File

@ -1,88 +1,73 @@
package ru.dbotthepony.mc.otm.block.entity; package ru.dbotthepony.mc.otm.block.entity
import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.MethodsReturnNonnullByDefault
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component
import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.world.MenuProvider; import net.minecraft.world.MenuProvider
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.AABB
import net.minecraft.world.level.block.state.BlockState; import ru.dbotthepony.mc.otm.Registry
import net.minecraft.world.phys.AABB; import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability; import ru.dbotthepony.mc.otm.core.Fraction
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.menu.AndroidStationMenu
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage; import javax.annotation.ParametersAreNonnullByDefault
import ru.dbotthepony.mc.otm.core.Fraction;
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu;
import javax.annotation.Nullable; class BlockEntityAndroidStation(p_155229_: BlockPos, p_155230_: BlockState) :
import javax.annotation.ParametersAreNonnullByDefault; BlockEntityMatteryPowered(Registry.BlockEntities.ANDROID_STATION, p_155229_, p_155230_), MenuProvider {
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
@MethodsReturnNonnullByDefault override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu {
@ParametersAreNonnullByDefault return AndroidStationMenu(containerID, inventory, this)
public class BlockEntityAndroidStation extends BlockEntityMatteryPowered implements MenuProvider {
@Nullable
@Override
public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) {
return new AndroidStationMenu(containerID, inventory, this);
} }
private final TranslatableComponent MACHINE_NAME = new TranslatableComponent("block.overdrive_that_matters.android_station"); override fun getDefaultDisplayName(): Component {
return MACHINE_NAME
@Override
protected Component getDefaultDisplayName() {
return MACHINE_NAME;
} }
public BlockEntityAndroidStation(BlockPos p_155229_, BlockState p_155230_) { init {
super(Registry.BlockEntities.ANDROID_STATION, p_155229_, p_155230_); energy = MatteryMachineEnergyStorage(
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER, new Fraction(100_000), new Fraction(250), new Fraction(250)); this,
MatteryMachineEnergyStorage.MachineType.WORKER,
Fraction(100000),
Fraction(250),
Fraction(250)
)
} }
public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState blockState, T t) { fun tick() {
if (t instanceof BlockEntityAndroidStation tile) { batteryChargeLoop()
tile.batteryChargeLoop();
if (tile.isBlockedByRedstone()) if (isBlockedByRedstone) return
return; val level = level ?: return
val x = blockPos.x.toDouble()
val y = blockPos.y.toDouble()
val z = blockPos.z.toDouble()
final var pos = tile.getBlockPos(); for (ent in level.getEntitiesOfClass(LivingEntity::class.java, AABB(x, y, z, x + 1.0, y + 2.0, z + 1.0))) {
List<LivingEntity> entities = tile.getLevel().getEntitiesOfClass(LivingEntity.class, new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 2, pos.getZ() + 1)); ent.getCapability(MatteryCapability.ANDROID).ifPresent {
if (!it.isAndroid())
return@ifPresent
for (LivingEntity ent : entities) { val missing = it.missingPower
final var resolver = ent.getCapability(MatteryCapability.ANDROID).resolve();
if (resolver.isEmpty()) if (missing > Fraction.ZERO) {
continue; val extract = energy.extractEnergyInner(missing, true)
final var capability = resolver.get(); if (extract > Fraction.ZERO) {
val received = it.receiveEnergyOuter(extract, false)
if (!capability.isAndroid()) energy.extractEnergyInner(received, false)
continue;
final var missing = capability.getMissingPower();
if (missing.compareTo(Fraction.ZERO) > 0) {
final var extract = tile.energy.extractEnergyInner(missing, true);
if (extract.compareTo(Fraction.ZERO) > 0) {
final var received = capability.receiveEnergyOuter(extract, true);
if (received.compareTo(Fraction.ZERO) > 0) {
tile.energy.extractEnergyInner(extract, false);
capability.receiveEnergyOuter(extract, false);
} }
} }
} }
} }
} }
companion object {
private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.android_station")
} }
} }

View File

@ -1,95 +1,81 @@
package ru.dbotthepony.mc.otm.block.entity; package ru.dbotthepony.mc.otm.block.entity
import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos
import net.minecraft.core.BlockPos; import net.minecraft.core.Direction
import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player
import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler
import net.minecraftforge.items.CapabilityItemHandler; import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.block.BlockCargoCrate
import ru.dbotthepony.mc.otm.block.BlockCargoCrate; import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.container.MatteryContainer; import ru.dbotthepony.mc.otm.ifHas
import ru.dbotthepony.mc.otm.container.MatteryContainerHandler; import ru.dbotthepony.mc.otm.menu.CargoCrateMenu
import ru.dbotthepony.mc.otm.menu.CargoCrateMenu; import ru.dbotthepony.mc.otm.set
import javax.annotation.Nonnull; class BlockEntityCargoCrate(
import javax.annotation.Nullable; p_155229_: BlockPos,
import javax.annotation.ParametersAreNonnullByDefault; p_155230_: BlockState
) : BlockEntityMattery(Registry.BlockEntities.CARGO_CRATE, p_155229_, p_155230_) {
val container = MatteryContainer(this::setChanged, 9 * 6)
private var interactingPlayers = 0
val handler = container.handler()
@MethodsReturnNonnullByDefault fun onPlayerOpen() {
@ParametersAreNonnullByDefault if (interactingPlayers++ == 0) {
public class BlockEntityCargoCrate extends BlockEntityMattery { level?.setBlock(blockPos, blockState.setValue(BlockCargoCrate.IS_OPEN, true), Block.UPDATE_CLIENTS)
private static final TranslatableComponent NAME = new TranslatableComponent("block.overdrive_that_matters.cargo_crate");
public int open_amount = 0;
public void onPlayerOpen() {
if (open_amount++ == 0 && level != null) {
level.setBlock(getBlockPos(), getBlockState().setValue(BlockCargoCrate.IS_OPEN, true), Block.UPDATE_CLIENTS);
} }
} }
public void onPlayerClose() { fun onPlayerClose() {
if (--open_amount == 0 && level != null) { if (--interactingPlayers == 0) {
level.setBlock(getBlockPos(), getBlockState().setValue(BlockCargoCrate.IS_OPEN, false), Block.UPDATE_CLIENTS); level?.setBlock(blockPos, blockState.setValue(BlockCargoCrate.IS_OPEN, false), Block.UPDATE_CLIENTS)
} }
} }
public final MatteryContainer container = new MatteryContainer(this::setChanged, 9 * 6); override fun invalidateCaps() {
public final MatteryContainerHandler item_handler = container.handler(); super.invalidateCaps()
handler.invalidate()
public BlockEntityCargoCrate(BlockPos p_155229_, BlockState p_155230_) {
super(Registry.BlockEntities.CARGO_CRATE, p_155229_, p_155230_);
} }
@Override override fun reviveCaps() {
public void invalidateCaps() { super.reviveCaps()
super.invalidateCaps(); handler.revive()
item_handler.invalidate();
} }
@Override override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
public void reviveCaps() { if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
super.reviveCaps(); return handler.get().cast()
item_handler.revive();
return super.getCapability(cap, side)
} }
@Nonnull public override fun saveAdditional(nbt: CompoundTag) {
@Override super.saveAdditional(nbt)
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { nbt["slots"] = container.serializeNBT()
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
return item_handler.get().cast();
return super.getCapability(cap, side);
} }
@Override override fun load(nbt: CompoundTag) {
public void saveAdditional(CompoundTag nbt) { super.load(nbt)
super.saveAdditional(nbt); nbt.ifHas("slots", CompoundTag::class.java, container::deserializeNBT)
nbt.put("slots", container.serializeNBT());
} }
@Override override fun getDefaultDisplayName(): Component {
public void load(CompoundTag nbt) { return NAME
super.load(nbt);
container.deserializeNBT(nbt.get("slots"));
} }
@Override override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu {
protected Component getDefaultDisplayName() { return CargoCrateMenu(containerID, inventory, this)
return NAME;
} }
@Nullable companion object {
@Override private val NAME = TranslatableComponent("block.overdrive_that_matters.cargo_crate")
public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) {
return new CargoCrateMenu(containerID, inventory, this);
} }
} }

View File

@ -1,30 +1,20 @@
package ru.dbotthepony.mc.otm.client.screen; package ru.dbotthepony.mc.otm.client.screen
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.screen.panels.Dock; import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel; import ru.dbotthepony.mc.otm.client.screen.panels.GridPanel
import ru.dbotthepony.mc.otm.client.screen.panels.GridPanel; import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel; import ru.dbotthepony.mc.otm.menu.CargoCrateMenu
import ru.dbotthepony.mc.otm.menu.CargoCrateMenu;
import javax.annotation.Nullable; class CargoCrateScreen(menu: CargoCrateMenu, inventory: Inventory, title: Component) : MatteryScreen<CargoCrateMenu>(menu, inventory, title) {
override fun makeMainFrame(): FramePanel {
val frame = FramePanel(this, null, 0f, 0f, INVENTORY_FRAME_WIDTH, 22f + 4f + 6f * 18f, getTitle())
val grid = GridPanel(this, frame, 8f, 18f, 9f * 18f, 6f * 18f, 9, 6)
public class CargoCrateScreen extends MatteryScreen<CargoCrateMenu> { for (slot in menu.crateSlots)
public CargoCrateScreen(CargoCrateMenu menu, Inventory inventory, Component title) { SlotPanel(this, grid, slot)
super(menu, inventory, title);
}
@Nullable return frame
@Override
protected FramePanel makeMainFrame() {
var frame = new FramePanel(this, null, 0, 0, INVENTORY_FRAME_WIDTH, 22 + 4 + 6 * 18, getTitle());
var grid = new GridPanel(this, frame, 8, 18, 9 * 18, 6 * 18, 9, 6);
for (var slot : menu.crate_slots)
new SlotPanel<>(this, grid, slot);
return frame;
} }
} }

View File

@ -16,7 +16,7 @@ import java.util.function.Consumer
open class MatteryContainer(val watcher: Runnable, private val size: Int) : Container, Iterable<ItemStack> { open class MatteryContainer(val watcher: Runnable, private val size: Int) : Container, Iterable<ItemStack> {
constructor(watcher: BlockEntity, size: Int) : this(watcher::setChanged, size) constructor(watcher: BlockEntity, size: Int) : this(watcher::setChanged, size)
// constructor(watcher: BlockEntityMattery, size: Int) : this(watcher::setChangedLight, size) constructor(size: Int) : this({}, size)
private var ignoreChangeNotifications = 0 private var ignoreChangeNotifications = 0
@JvmField protected val slots: Array<ItemStack> = Array(size) { ItemStack.EMPTY } @JvmField protected val slots: Array<ItemStack> = Array(size) { ItemStack.EMPTY }

View File

@ -1,48 +1,41 @@
package ru.dbotthepony.mc.otm.menu; package ru.dbotthepony.mc.otm.menu
import net.minecraft.world.SimpleContainer; import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate; import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate
public class CargoCrateMenu extends MatteryMenu { class CargoCrateMenu @JvmOverloads constructor(
public CargoCrateMenu(int p_38852_, Inventory inventory) { p_38852_: Int,
this(p_38852_, inventory, null); inventory: Inventory,
tile: BlockEntityCargoCrate? = null
) : MatteryMenu(Registry.Menus.CARGO_CRATE, p_38852_, inventory, tile) {
val crateSlots: Array<MatterySlot>
init {
val container = tile?.container ?: SimpleContainer(9 * 6)
crateSlots = Array(9 * 6) {
val slot = MatterySlot(container, it)
addSlot(slot)
return@Array slot
} }
public final MatterySlot[] crate_slots = new MatterySlot[9 * 6]; tile?.onPlayerOpen()
addInventorySlots()
public CargoCrateMenu(int p_38852_, Inventory inventory, BlockEntityCargoCrate tile) {
super(Registry.Menus.CARGO_CRATE, p_38852_, inventory, tile);
var container = tile != null ? tile.container : new SimpleContainer(9 * 6);
for (int i = 0; i < container.getContainerSize(); i++) {
crate_slots[i] = new MatterySlot(container, i);
addSlot(crate_slots[i]);
} }
if (tile != null) override fun removed(p_38940_: Player) {
tile.onPlayerOpen(); super.removed(p_38940_)
(tile as? BlockEntityCargoCrate)?.onPlayerClose()
addInventorySlots();
} }
@Override override fun getWorkingSlotStart(): Int {
public void removed(Player p_38940_) { return 0
super.removed(p_38940_);
if (tile != null)
((BlockEntityCargoCrate) tile).onPlayerClose();
} }
@Override override fun getWorkingSlotEnd(): Int {
protected int getWorkingSlotStart() { return 9 * 6 + 1
return 0;
}
@Override
protected int getWorkingSlotEnd() {
return 9 * 6 + 1;
} }
} }