[IC2] Не работает кастомная машина

Версия Minecraft
1.7.10
1,470
19
189
Всем привет. Сделал машину с двумя входными и двумя выходными слотами, но при помещении предмета прогресс не идет. Код копировал и правил с индукционной печки.
Gui
Kotlin:
class GuiQuantCompressor(container1: ContainerQuantCompressor): GuiIC2(container1) {
    override fun drawGuiContainerBackgroundLayer(f: Float, x: Int, y: Int) {
        super.drawGuiContainerBackgroundLayer(f, x, y)
        val chargeLevel = Math.round((this.container.base as TileEntityQuantCompressor).chargeLevel * 14.0f)
        this.drawTexturedModalRect(this.xoffset + 56, this.yoffset + 36 + 14 - chargeLevel, 176, 14 - chargeLevel, 14, chargeLevel)
        val i1 = (this.container.base as TileEntityQuantCompressor).gaugeProgressScaled(24)
        this.drawTexturedModalRect(this.xoffset + 79, this.yoffset + 34, 176, 14, i1 + 1, 16)
    }

    override fun getName(): String = I18n.format("$modid.quant_compressor.gui.name")
    override fun getResourceLocation(): ResourceLocation = ResourceLocation(IC2.textureDomain, "textures/gui/GUIInduction.png")
}
Container
Kotlin:
class ContainerQuantCompressor(entityPlayer: EntityPlayer?, tileEntity: TileEntityQuantCompressor): ContainerElectricMachine<TileEntityQuantCompressor>(entityPlayer, tileEntity, 166, 56, 53) {
    init {
        this.addSlotToContainer(SlotInvSlot(tileEntity.inputSlotA, 0, 47, 17))
        this.addSlotToContainer(SlotInvSlot(tileEntity.inputSlotB, 0, 63, 17))
        this.addSlotToContainer(SlotInvSlot(tileEntity.outputSlotA, 0, 113, 35))
        this.addSlotToContainer(SlotInvSlot(tileEntity.outputSlotB, 0, 131, 35))
        for (i in 0..1) {
            this.addSlotToContainer(SlotInvSlot(tileEntity.upgradeSlot, i, 153, 26 + i * 18))
        }
    }

    override fun getNetworkedFields(): List<String> {
        val ret = super.getNetworkedFields()
        ret.add("progress")
        return ret
    }
}
TileEntity
Kotlin:
class TileEntityQuantCompressor: TileEntityElectricMachine(256000, 4, 2), IHasGui, IUpgradableBlock {
    var inputSlotA: InvSlotProcessable
    var inputSlotB: InvSlotProcessable
    var upgradeSlot: InvSlotUpgrade
    var outputSlotA: InvSlotOutput
    var outputSlotB: InvSlotOutput
    var progress: Short = 0

    init {
        this.inputSlotA = InvSlotProcessableGeneric(this, "inputA", 0, 1, Recipes.compressor)
        this.inputSlotB = InvSlotProcessableGeneric(this, "inputB", 1, 1, Recipes.compressor)
        this.outputSlotA = InvSlotOutput(this, "outputA", 2, 1)
        this.outputSlotB = InvSlotOutput(this, "outputB", 3, 1)
        this.upgradeSlot = InvSlotUpgrade(this, "upgrade", 4, 2)
    }

    override fun readFromNBT(nbttagcompound: NBTTagCompound) {
        super.readFromNBT(nbttagcompound)
        this.progress = nbttagcompound.getShort("progress")
    }

    override fun writeToNBT(nbttagcompound: NBTTagCompound) {
        super.writeToNBT(nbttagcompound)
        nbttagcompound.setShort("progress", this.progress)
    }



    override fun updateEntityServer() {
        super.updateEntityServer()
        var needsInvUpdate = false
        var newActive = this.active

        if (this.progress >= 4000) {
            this.operate()
            needsInvUpdate = true
            this.progress = 0
            newActive = false
        }

        val canOperate = this.canOperate()

        if (newActive && this.progress.toInt() != 0) {
            if (!canOperate || this.energy < 15.0) {
                if (!canOperate) {
                    this.progress = 0
                }

                newActive = false
            }
        } else if (canOperate) {
            if (this.energy >= 15.0) {
                progress + 300
                newActive = true
            }
        } else {
            this.progress = 0
        }

        if (newActive && canOperate) {
            this.energy -= 15.0
        }

        if (needsInvUpdate) {
            this.markDirty()
        }

        if (newActive != this.active) {
            this.active = newActive
        }

        for (i in 0 until this.upgradeSlot.size()) {
            val stack = this.upgradeSlot.get(i)
            if (stack != null && stack.item is IUpgradeItem && (stack.item as IUpgradeItem).onTick(stack, this)) {
                super.markDirty()
            }
        }

    }

    private fun operate() {
        this.operate(this.inputSlotA, this.outputSlotA)
        this.operate(this.inputSlotB, this.outputSlotB)
    }

    private fun operate(inputSlot: InvSlotProcessable, outputSlot: InvSlotOutput) {
        if (this.canOperate(inputSlot, outputSlot)) {
            outputSlot.add(inputSlot.process().items)
            inputSlot.consume()
        }
    }

    private fun canOperate(): Boolean = this.canOperate(this.inputSlotA, this.outputSlotA) || this.canOperate(this.inputSlotB, this.outputSlotB)
    private fun canOperate(inputSlot: InvSlotProcessable, outputSlot: InvSlotOutput): Boolean = if (inputSlot.isEmpty) false else { val output = inputSlot.process();if (output == null) false else outputSlot.canAdd(output.items) }
    override fun getGui(player: EntityPlayer?, isAdmin: Boolean): GuiScreen = GuiQuantCompressor(ContainerQuantCompressor(player, this))
    override fun getGuiContainer(player: EntityPlayer?): ContainerBase<*> = ContainerQuantCompressor(player, this)
    override fun onGuiClosed(player: EntityPlayer?) {}
    override fun getUpgradableProperties(): MutableSet<UpgradableProperty> = EnumSet.of(UpgradableProperty.RedstoneSensitive, UpgradableProperty.ItemConsuming, UpgradableProperty.ItemProducing)
    override fun useEnergy(amount: Double): Boolean = if (energy >= amount) { energy -= amount; true } else false
    override fun getEnergy(): Double = energy
    override fun getInventoryName(): String = "Quantum Compressor"
    fun gaugeProgressScaled(i: Int): Int = i * this.progress / 4000
    fun gaugeFuelScaled(i: Int): Int = (i.toDouble() * Math.min(this.energy, this.maxEnergy.toDouble()) / this.maxEnergy.toDouble()).toInt()
}
 
Последнее редактирование:
1,470
19
189
Проблема решилась просто
Kotlin:
override fun updateEntityServer() {
        super.updateEntityServer()
        var needsInvUpdate = false
        var newActive = this.active

        if (this.progress >= 4000) {
            this.operate()
            needsInvUpdate = true
            this.progress = 0
            newActive = false
        }

        val canOperate = this.canOperate()
        if (this.energy > 0.0 && canOperate) {
            --this.energy

            newActive = true
        }

        if (newActive && this.progress.toInt() != 0) {
            if (!canOperate || this.energy < 15.0) {
                if (!canOperate) {
                    this.progress = 0
                }

                newActive = false
            }
        } else if (canOperate) {
            if (this.energy >= 15.0) {
                newActive = true
            }
        } else {
            this.progress = 0
        }

        if (newActive && canOperate) {
            this.progress = (this.progress + 10000 / 30).toShort()
            this.energy -= 15.0
        }

        if (needsInvUpdate) {
            this.markDirty()
        }

        if (newActive != this.active) {
            this.active = newActive
        }

        for (i in 0 until this.upgradeSlot.size()) {
            val stack = this.upgradeSlot.get(i)
            if (stack != null && stack.item is IUpgradeItem && (stack.item as IUpgradeItem).onTick(stack, this)) {
                super.markDirty()
            }
        }
    }
 
Сверху