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_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_) {
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;
private boolean made_main_frame = false;
public static final int DEFAULT_FRAME_WIDTH = 18 * 9 + 16;
public static final int DEFAULT_FRAME_HEIGHT = 100;
public static final float DEFAULT_FRAME_WIDTH = 18 * 9 + 16;
public static final float DEFAULT_FRAME_HEIGHT = 100;
public static final int INVENTORY_FRAME_WIDTH = DEFAULT_FRAME_WIDTH;
public static final int INVENTORY_FRAME_HEIGHT = 3 * 18 + 18 + 24;
public static final float INVENTORY_FRAME_WIDTH = DEFAULT_FRAME_WIDTH;
public static final float INVENTORY_FRAME_HEIGHT = 3 * 18 + 18 + 24;
public MatteryScreen(T menu, Inventory inventory, Component 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.item.ItemStack
import net.minecraft.world.phys.Vec3
import net.minecraftforge.common.util.LazyOptional
import java.util.function.Consumer
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)
}
}
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.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
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.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.util.LazyOptional;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation;
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
import net.minecraft.core.BlockPos
import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResult
import net.minecraft.world.entity.player.Player
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
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.BlockState
import net.minecraft.world.phys.BlockHitResult
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability
import ru.dbotthepony.mc.otm.orNull
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
class BlockAndroidStation : BlockMattery(), EntityBlock {
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
@ParametersAreNonnullByDefault
public class BlockAndroidStation extends BlockMattery implements EntityBlock {
private final VoxelShape SHAPE = BlockShapes.ANDROID_STATION.computeShape();
if (!cap.isAndroid())
return InteractionResult.FAIL
public BlockAndroidStation() {
super();
return super.use(blockState, level, blockPos, ply, hand, blockHitResult)
}
@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player ply, InteractionHand hand, BlockHitResult blockHitResult) {
LazyOptional<IAndroidCapability> cap = ply.getCapability(MatteryCapability.ANDROID);
if (cap.resolve().isEmpty() || !cap.resolve().get().isAndroid())
return InteractionResult.FAIL;
return super.use(blockState, level, blockPos, ply, hand, blockHitResult);
override fun getShape(
p_151964_: BlockState,
p_151965_: BlockGetter,
p_151966_: BlockPos,
p_151967_: CollisionContext
): VoxelShape {
return SHAPE
}
@Override
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState p_151964_, BlockGetter p_151965_, BlockPos p_151966_, CollisionContext p_151967_) {
return SHAPE;
override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity {
return BlockEntityAndroidStation(pos, state)
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityAndroidStation(pos, state);
override fun <T : BlockEntity?> getTicker(
level: Level,
state: BlockState,
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
@Override
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;
companion object {
private val SHAPE = BlockShapes.ANDROID_STATION.computeShape()
}
}

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block
import net.minecraft.core.BlockPos
import net.minecraft.world.Containers
import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.Level
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
class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return BlockEntityCargoCrate(blockPos, blockState)
}
@ -23,7 +24,7 @@ class BlockCargoCrate : BlockMatteryRotatable(), EntityBlock {
}
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(
@ -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 {
@JvmField
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.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage;
import ru.dbotthepony.mc.otm.core.Fraction;
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu;
import net.minecraft.MethodsReturnNonnullByDefault
import net.minecraft.core.BlockPos
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.world.MenuProvider
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.AABB
import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage
import ru.dbotthepony.mc.otm.core.Fraction
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu
import javax.annotation.ParametersAreNonnullByDefault
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
class BlockEntityAndroidStation(p_155229_: BlockPos, p_155230_: BlockState) :
BlockEntityMatteryPowered(Registry.BlockEntities.ANDROID_STATION, p_155229_, p_155230_), MenuProvider {
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockEntityAndroidStation extends BlockEntityMatteryPowered implements MenuProvider {
@Nullable
@Override
public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) {
return new AndroidStationMenu(containerID, inventory, this);
override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu {
return AndroidStationMenu(containerID, inventory, this)
}
private final TranslatableComponent MACHINE_NAME = new TranslatableComponent("block.overdrive_that_matters.android_station");
@Override
protected Component getDefaultDisplayName() {
return MACHINE_NAME;
override fun getDefaultDisplayName(): Component {
return MACHINE_NAME
}
public BlockEntityAndroidStation(BlockPos p_155229_, BlockState p_155230_) {
super(Registry.BlockEntities.ANDROID_STATION, p_155229_, p_155230_);
energy = new MatteryMachineEnergyStorage(this, MatteryMachineEnergyStorage.MachineType.WORKER, new Fraction(100_000), new Fraction(250), new Fraction(250));
init {
energy = MatteryMachineEnergyStorage(
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) {
if (t instanceof BlockEntityAndroidStation tile) {
tile.batteryChargeLoop();
fun tick() {
batteryChargeLoop()
if (tile.isBlockedByRedstone())
return;
if (isBlockedByRedstone) 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();
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));
for (ent in level.getEntitiesOfClass(LivingEntity::class.java, AABB(x, y, z, x + 1.0, y + 2.0, z + 1.0))) {
ent.getCapability(MatteryCapability.ANDROID).ifPresent {
if (!it.isAndroid())
return@ifPresent
for (LivingEntity ent : entities) {
final var resolver = ent.getCapability(MatteryCapability.ANDROID).resolve();
val missing = it.missingPower
if (resolver.isEmpty())
continue;
if (missing > Fraction.ZERO) {
val extract = energy.extractEnergyInner(missing, true)
final var capability = resolver.get();
if (!capability.isAndroid())
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);
if (extract > Fraction.ZERO) {
val received = it.receiveEnergyOuter(extract, false)
energy.extractEnergyInner(received, 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.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.BlockCargoCrate;
import ru.dbotthepony.mc.otm.container.MatteryContainer;
import ru.dbotthepony.mc.otm.container.MatteryContainerHandler;
import ru.dbotthepony.mc.otm.menu.CargoCrateMenu;
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.state.BlockState
import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.common.util.LazyOptional
import net.minecraftforge.items.CapabilityItemHandler
import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.BlockCargoCrate
import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.ifHas
import ru.dbotthepony.mc.otm.menu.CargoCrateMenu
import ru.dbotthepony.mc.otm.set
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
class BlockEntityCargoCrate(
p_155229_: BlockPos,
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
@ParametersAreNonnullByDefault
public class BlockEntityCargoCrate extends BlockEntityMattery {
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);
fun onPlayerOpen() {
if (interactingPlayers++ == 0) {
level?.setBlock(blockPos, blockState.setValue(BlockCargoCrate.IS_OPEN, true), Block.UPDATE_CLIENTS)
}
}
public void onPlayerClose() {
if (--open_amount == 0 && level != null) {
level.setBlock(getBlockPos(), getBlockState().setValue(BlockCargoCrate.IS_OPEN, false), Block.UPDATE_CLIENTS);
fun onPlayerClose() {
if (--interactingPlayers == 0) {
level?.setBlock(blockPos, blockState.setValue(BlockCargoCrate.IS_OPEN, false), Block.UPDATE_CLIENTS)
}
}
public final MatteryContainer container = new MatteryContainer(this::setChanged, 9 * 6);
public final MatteryContainerHandler item_handler = container.handler();
public BlockEntityCargoCrate(BlockPos p_155229_, BlockState p_155230_) {
super(Registry.BlockEntities.CARGO_CRATE, p_155229_, p_155230_);
override fun invalidateCaps() {
super.invalidateCaps()
handler.invalidate()
}
@Override
public void invalidateCaps() {
super.invalidateCaps();
item_handler.invalidate();
override fun reviveCaps() {
super.reviveCaps()
handler.revive()
}
@Override
public void reviveCaps() {
super.reviveCaps();
item_handler.revive();
override fun <T> getCapability(cap: Capability<T>, side: Direction?): LazyOptional<T> {
if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
return handler.get().cast()
return super.getCapability(cap, side)
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
return item_handler.get().cast();
return super.getCapability(cap, side);
public override fun saveAdditional(nbt: CompoundTag) {
super.saveAdditional(nbt)
nbt["slots"] = container.serializeNBT()
}
@Override
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
nbt.put("slots", container.serializeNBT());
override fun load(nbt: CompoundTag) {
super.load(nbt)
nbt.ifHas("slots", CompoundTag::class.java, container::deserializeNBT)
}
@Override
public void load(CompoundTag nbt) {
super.load(nbt);
container.deserializeNBT(nbt.get("slots"));
override fun getDefaultDisplayName(): Component {
return NAME
}
@Override
protected Component getDefaultDisplayName() {
return NAME;
override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu {
return CargoCrateMenu(containerID, inventory, this)
}
@Nullable
@Override
public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) {
return new CargoCrateMenu(containerID, inventory, this);
companion object {
private val NAME = TranslatableComponent("block.overdrive_that_matters.cargo_crate")
}
}

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.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.GridPanel;
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel;
import ru.dbotthepony.mc.otm.menu.CargoCrateMenu;
import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory
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.SlotPanel
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> {
public CargoCrateScreen(CargoCrateMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title);
}
for (slot in menu.crateSlots)
SlotPanel(this, grid, slot)
@Nullable
@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;
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> {
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
@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.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate;
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate
public class CargoCrateMenu extends MatteryMenu {
public CargoCrateMenu(int p_38852_, Inventory inventory) {
this(p_38852_, inventory, null);
class CargoCrateMenu @JvmOverloads constructor(
p_38852_: Int,
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];
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]);
tile?.onPlayerOpen()
addInventorySlots()
}
if (tile != null)
tile.onPlayerOpen();
addInventorySlots();
override fun removed(p_38940_: Player) {
super.removed(p_38940_)
(tile as? BlockEntityCargoCrate)?.onPlayerClose()
}
@Override
public void removed(Player p_38940_) {
super.removed(p_38940_);
if (tile != null)
((BlockEntityCargoCrate) tile).onPlayerClose();
override fun getWorkingSlotStart(): Int {
return 0
}
@Override
protected int getWorkingSlotStart() {
return 0;
}
@Override
protected int getWorkingSlotEnd() {
return 9 * 6 + 1;
override fun getWorkingSlotEnd(): Int {
return 9 * 6 + 1
}
}