Skip to content

Commit

Permalink
Merge pull request #118 from Noktuska/beekeeper-fix
Browse files Browse the repository at this point in the history
Fix Beekeeper module not working with GT IApiary
  • Loading branch information
Dream-Master authored Mar 25, 2024
2 parents fe2f6fc + 20be9ea commit 6d8e8dd
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 114 deletions.
25 changes: 14 additions & 11 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ dependencies {

compile("com.google.code.findbugs:jsr305:3.0.2")

compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-328-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-343-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:EnderStorage:1.5.0:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.45.84:dev") {transitive = false }
compile("com.github.GTNewHorizons:ForestryMC:4.8.4:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Railcraft:9.15.6:dev") {transitive = false }
compile("com.github.GTNewHorizons:NotEnoughItems:2.5.23-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.45.128:dev") {transitive = false }
compile("com.github.GTNewHorizons:ForestryMC:4.8.7:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Railcraft:9.15.7:dev") {transitive = false }
compile("com.github.GTNewHorizons:NotEnoughItems:2.5.25-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:ForgeMultipart:1.4.8:dev") {transitive = false }
compile("com.github.GTNewHorizons:CodeChickenLib:1.2.1:dev") {transitive = false }
compile("com.github.GTNewHorizons:CodeChickenCore:1.2.1:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:waila:1.7.1:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Galacticraft:3.1.3-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:TinkersMechworks:0.3.1:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:ProjectRed:4.9.4-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:ProjectRed:4.9.5-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:BloodMagic:1.5.1:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.6.2-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.6.4-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:ExtraCells2:2.5.34:dev") {transitive = false }
compileOnly('com.github.GTNewHorizons:AE2FluidCraft-Rework:1.2.19-gtnh:dev') {transitive = false }
compileOnly('com.github.GTNewHorizons:AE2FluidCraft-Rework:1.2.22-gtnh:dev') {transitive = false }
compile("com.github.GTNewHorizons:EnderIO:2.7.1:dev") {
compile("com.github.GTNewHorizons:EnderCore:0.4.5:dev")
compile("com.github.GTNewHorizons:EnderCore:0.4.6:dev")
transitive = false
}
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.7.0-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.7.1-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:gendustry:1.7.0-GTNH:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:WirelessRedstone-CBE:1.5.0:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:BuildCraft:7.1.39:dev") {transitive = false }
Expand All @@ -47,7 +47,7 @@ dependencies {
compileOnly("curse.maven:agricraft-225635:2284133") {transitive = false }
compileOnly("curse.maven:stargatetech-2-226769:2230351") {transitive = false }

compileOnlyApi("com.github.GTNewHorizons:Angelica:1.0.0-alpha31:api") { transitive = false }
compileOnlyApi("com.github.GTNewHorizons:Angelica:1.0.0-alpha35:api") { transitive = false }

compileOnly(deobf("https://immibis.com/mcmoddl/files/redlogic-59.1.13.jar"))
compileOnly files("dependencies/ic2classic-api.zip") //curseforge one does NOT work ...
Expand All @@ -62,4 +62,7 @@ dependencies {
testCompile "org.mockito:mockito-all:1.10.19"
testCompile "org.scalactic:scalactic_2.11:2.2.6"
testCompile "org.scalatest:scalatest_2.11:2.2.6"

compileOnly("com.github.GTNewHorizons:ModularUI:1.1.42:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:StructureLib:1.3.0:dev") {transitive = false}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.15'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.19'
}


138 changes: 36 additions & 102 deletions src/main/scala/li/cil/oc/integration/forestry/UpgradeBeekeeper.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package li.cil.oc.integration.forestry

import java.util

import cpw.mods.fml.common.Loader
import forestry.api.apiculture.{BeeManager, IBeeHousing}
import forestry.plugins.PluginApiculture
import li.cil.oc.Constants
Expand All @@ -15,10 +13,6 @@ import li.cil.oc.server.component.result
import li.cil.oc.server.component.traits.{NetworkAware, SideRestricted, WorldAware}
import li.cil.oc.util.{BlockPosition, InventoryUtils}
import li.cil.oc.util.ExtendedArguments.extendedArguments
import li.cil.oc.util.ExtendedWorld._
import net.bdew.gendustry.api.blocks.IIndustrialApiary
import net.minecraft.inventory.ISidedInventory
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection

Expand All @@ -37,53 +31,43 @@ class UpgradeBeekeeper(val host: EnvironmentHost with internal.Agent) extends pr
DeviceAttribute.Product -> "Breeding bees for you (almost)"
)

private final val defaultStackSize = 64

override def getDeviceInfo: util.Map[String, String] = deviceInfo
override def position: BlockPosition = BlockPosition(host)
override protected def checkSideForAction(args: Arguments, n: Int): ForgeDirection = args.checkSideAny(n)

private def withApiary(side: ForgeDirection, f: IBeeHousing => Array[AnyRef]) =
if (host.mainInventory.getSizeInventory > 0) {
position.world.get.getTileEntity(position.offset(side)) match {
case housing: IBeeHousing => f(housing)
case _ => result(false, "Not facing an apiary")
}
}
else result(false, "No inventory?")

@Callback(doc = """function(side:number):boolean -- Swap the queen from the selected slot with the apiary at the specified side.""")
def swapQueen(context: Context, args: Arguments): Array[AnyRef] = {
val facing = checkSideForAction(args, 0)
withApiary(facing, housing => {
val selected = host.mainInventory.getStackInSlot(host.selectedSlot)
val oldQueen = housing.getBeeInventory.getQueen
housing.getBeeInventory.setQueen(selected)
host.mainInventory.setInventorySlotContents(host.selectedSlot, oldQueen)
result(true)
})
val pos = position.offset(facing)
result(UpgradeBeekeeperUtil.swapQueen(pos, host.mainInventory(), host.selectedSlot()))
}

@Callback(doc = """function(side:number):boolean -- Swap the drone from the selected slot with the apiary at the specified side.""")
def swapDrone(context: Context, args: Arguments): Array[AnyRef] = {
val facing = checkSideForAction(args, 0)
withApiary(facing, housing => {
val selected = host.mainInventory.getStackInSlot(host.selectedSlot)
val oldQueen = housing.getBeeInventory.getDrone
housing.getBeeInventory.setDrone(selected)
host.mainInventory.setInventorySlotContents(host.selectedSlot, oldQueen)
result(true)
})
val pos = position.offset(facing)
result(UpgradeBeekeeperUtil.swapDrone(pos, host.mainInventory(), host.selectedSlot()))
}

@Callback(doc = """function(side:number):number -- Get current progress percent for the apiary at the specified side.""")
def getBeeProgress(context: Context, args: Arguments): Array[AnyRef] = {
val facing = checkSideForAction(args, 0)
withApiary(facing, housing => result(housing.getBeekeepingLogic.getBeeProgressPercent))
val housing = UpgradeBeekeeperUtil.getBeeHousingAt(position.offset(facing))
if (housing == null)
return result(false, "No bee housing found")
result(housing.getBeekeepingLogic.getBeeProgressPercent)
}

@Callback(doc = """function(side:number):boolean -- Checks if current bee in the apiary at the specified side can work now.""")
def canWork(context: Context, args: Arguments): Array[AnyRef] = {
val facing = checkSideForAction(args, 0)
withApiary(facing, housing => result(housing.getBeekeepingLogic.canWork))
val housing = UpgradeBeekeeperUtil.getBeeHousingAt(position.offset(facing))
if (housing == null)
return result(false, "No bee housing found")
result(housing.getBeekeepingLogic.canWork)
}

@Callback(doc = """function(honeyslot:number):boolean -- Analyzes bee in selected slot, uses honey from the specified slot.""")
Expand Down Expand Up @@ -112,86 +96,36 @@ class UpgradeBeekeeper(val host: EnvironmentHost with internal.Agent) extends pr
result(true)
}

private def findSameStack(upgrade: ItemStack, inv: ISidedInventory):Int = {
for (slot <- 2 to 5) {
val u = inv.getStackInSlot(slot)
if (u != null && u.getItem == upgrade.getItem && upgrade.getItemDamage == u.getItemDamage)
return slot
}
0
}

private def findEmptySlot(inv: ISidedInventory):Int = {
for (slot <- 2 to 5) {
if (inv.getStackInSlot(slot) == null)
return slot
}
0
}

@Callback(doc = """function(side:number):boolean -- Tries to add industrial upgrade from the selected slot to industrial apiary at the given side.""")
@Callback(doc = """function(side:number[,amount:number]):number -- Tries to add amount many or all industrial upgrades from the selected slot to industrial apiary at the given side.""")
def addIndustrialUpgrade(context: Context, args: Arguments): Array[AnyRef] = {
if (!Loader.isModLoaded("gendustry")) return result(false, "Gendustry not loaded!")
val inventory = host.mainInventory
val facing = checkSideForAction(args, 0)
val upgrade = inventory.getStackInSlot(host.selectedSlot)
if (upgrade == null) return result(false, "No upgrade in selected slot")
position.world.get.getTileEntity(position.offset(facing)) match {
case ia : IIndustrialApiary =>
val inv = ia.asInstanceOf[ISidedInventory]
if (!inv.isItemValidForSlot(2, upgrade))
return result(false, "Upgrade does not fit")

var slot = findSameStack(upgrade, inv)
if (slot == 0)
slot = findEmptySlot(inv)

val u = inv.getStackInSlot(slot)
if (u == null)
inv.setInventorySlotContents(slot, upgrade)
else {
u.stackSize += upgrade.stackSize
inv.setInventorySlotContents(slot, u)
}
inventory.setInventorySlotContents(host.selectedSlot, null)
result(true)

case _ => result(false, "Not facing an industrial apiary")
}
val pos = position.offset(facing)
var amount = defaultStackSize
if (args.count() > 1)
amount = args.checkInteger(1)
result(UpgradeBeekeeperUtil.addIndustrialUpgrade(pos, host.mainInventory(), host.selectedSlot(), amount))
}
@Callback(doc = """function(side:number, slot: number):table -- Get industrial upgrade in the given slot of the industrial apiary at the given side.""")
def getIndustrialUpgrade(context: Context, args: Arguments): Array[AnyRef] = {
if (!Loader.isModLoaded("gendustry")) return result(Unit, "Gendustry not loaded!")
val facing = checkSideForAction(args, 0)
position.world.get.getTileEntity(position.offset(facing)) match {
case ia: IIndustrialApiary =>
val inv = ia.asInstanceOf[ISidedInventory]
val slot = args.checkInteger(1) + 1
if (slot < 2 || slot > 5)
return result(Unit, "Wrong slot index (should be 1-4)")

result(inv.getStackInSlot(slot))

case _ => result(Unit, "Not facing an industrial apiary")
}
val pos = position.offset(facing)
val slot = args.checkInteger(1)
val maxIndex = UpgradeBeekeeperUtil.getMaxIndustrialUpgradeCount
if (slot < 1 || slot > maxIndex)
return result(Unit, "Wrong slot index (should be 1-" + maxIndex + ")")
result(UpgradeBeekeeperUtil.getIndustrialUpgrade(pos, slot))
}
@Callback(doc = """function(side:number, slot: number):boolean -- Remove industrial upgrade from the given slot of the industrial apiary at the given side.""")
@Callback(doc = """function(side:number, slot: number[, amount: number]):boolean -- Remove industrial upgrade from the given slot of the industrial apiary at the given side.""")
def removeIndustrialUpgrade(context: Context, args: Arguments): Array[AnyRef] = {
if (!Loader.isModLoaded("gendustry")) return result(false, "Gendustry not loaded!")
val facing = checkSideForAction(args, 0)
position.world.get.getTileEntity(position.offset(facing)) match {
case ia: IIndustrialApiary =>
val inv = ia.asInstanceOf[ISidedInventory]
val slot = args.checkInteger(1) + 1
if (slot < 2 || slot > 5)
return result(false, "Wrong slot index (should be 1-4)")

val u = inv.getStackInSlot(slot)
val res = InventoryUtils.insertIntoInventory(u, host.mainInventory)
inv.setInventorySlotContents(slot, if (u.stackSize > 0) u else null)
result(res)

case _ => result(false, "Not facing an industrial apiary")
}
val pos = position.offset(facing)
val slot = args.checkInteger(1)
val maxIndex = UpgradeBeekeeperUtil.getMaxIndustrialUpgradeCount
var amount = defaultStackSize
if (args.count() > 2)
amount = args.checkInteger(2)
if (slot < 1 || slot > maxIndex)
return result(false, "Wrong slot index (should be 1-" + maxIndex + ")")
result(UpgradeBeekeeperUtil.removeIndustrialUpgrade(pos, host.mainInventory(), host.selectedSlot(), slot, amount))
}
}
Loading

0 comments on commit 6d8e8dd

Please sign in to comment.