mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
Enforce complexity limit for multiparts.
This commit is contained in:
parent
94eff66b34
commit
54eef9bb0c
@ -33,6 +33,8 @@ class PrintData extends ItemData(Constants.BlockName.Print) {
|
||||
var noclipOff = false
|
||||
var noclipOn = false
|
||||
|
||||
def complexity = stateOn.size max stateOff.size
|
||||
|
||||
def hasActiveState = stateOn.nonEmpty
|
||||
|
||||
def emitLight = lightLevel > 0
|
||||
|
@ -1,11 +1,14 @@
|
||||
package li.cil.oc.integration.mcmp
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.common.item.data.PrintData
|
||||
import li.cil.oc.integration.Mods
|
||||
import mcmultipart.item.IItemMultipartFactory
|
||||
import mcmultipart.multipart.IMultipart
|
||||
import mcmultipart.multipart.IPartFactory
|
||||
import mcmultipart.multipart.MultipartHelper
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.BlockPos
|
||||
@ -13,6 +16,8 @@ import net.minecraft.util.EnumFacing
|
||||
import net.minecraft.util.Vec3
|
||||
import net.minecraft.world.World
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
object PartFactory extends IPartFactory with IItemMultipartFactory {
|
||||
final val PartTypeCable = Mods.IDs.OpenComputers + ":" + Constants.BlockName.Cable
|
||||
final val PartTypePrint = Mods.IDs.OpenComputers + ":" + Constants.BlockName.Print
|
||||
@ -29,7 +34,7 @@ object PartFactory extends IPartFactory with IItemMultipartFactory {
|
||||
override def createPart(world: World, pos: BlockPos, side: EnumFacing, hit: Vec3, stack: ItemStack, player: EntityPlayer): IMultipart = {
|
||||
val descriptor = api.Items.get(stack)
|
||||
if (descriptor == CableDescriptor) new PartCable()
|
||||
else if (descriptor == PrintDescriptor) {
|
||||
else if (descriptor == PrintDescriptor && canAddPrint(world, pos, stack)) {
|
||||
val part = new PartPrint()
|
||||
part.wrapped.data.load(stack)
|
||||
part.wrapped.setFromEntityPitchAndYaw(player)
|
||||
@ -40,4 +45,13 @@ object PartFactory extends IPartFactory with IItemMultipartFactory {
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
private def canAddPrint(world: World, pos: BlockPos, stack: ItemStack): Boolean = {
|
||||
val container = MultipartHelper.getPartContainer(world, pos)
|
||||
val complexity = container.getParts.collect {
|
||||
case print: PartPrint => print.wrapped.data.complexity
|
||||
}.sum
|
||||
val data = new PrintData(stack)
|
||||
data.complexity + complexity <= Settings.get.maxPrintComplexity
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user