mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Made robot not send null to the client when its inventory changes.
Closes #2360.
This commit is contained in:
parent
30e3e129c8
commit
41599b0c10
@ -11,6 +11,8 @@ import li.cil.oc.client.Textures
|
|||||||
import li.cil.oc.common.EventHandler
|
import li.cil.oc.common.EventHandler
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
import li.cil.oc.util.RenderState
|
import li.cil.oc.util.RenderState
|
||||||
|
import li.cil.oc.util.StackOption
|
||||||
|
import li.cil.oc.util.StackOption._
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.client.renderer._
|
import net.minecraft.client.renderer._
|
||||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType
|
||||||
@ -343,8 +345,8 @@ object RobotRenderer extends TileEntitySpecialRenderer[tileentity.RobotProxy] {
|
|||||||
|
|
||||||
if (MinecraftForgeClient.getRenderPass == 0 && !robot.renderingErrored && x * x + y * y + z * z < 24 * 24) {
|
if (MinecraftForgeClient.getRenderPass == 0 && !robot.renderingErrored && x * x + y * y + z * z < 24 * 24) {
|
||||||
val itemRenderer = Minecraft.getMinecraft.getItemRenderer
|
val itemRenderer = Minecraft.getMinecraft.getItemRenderer
|
||||||
Option(robot.getStackInSlot(0)) match {
|
StackOption(robot.getStackInSlot(0)) match {
|
||||||
case Some(stack) =>
|
case SomeStack(stack) =>
|
||||||
|
|
||||||
RenderState.pushAttrib()
|
RenderState.pushAttrib()
|
||||||
GlStateManager.pushMatrix()
|
GlStateManager.pushMatrix()
|
||||||
|
@ -6,6 +6,8 @@ import li.cil.oc.Settings
|
|||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.common.Slot
|
import li.cil.oc.common.Slot
|
||||||
import li.cil.oc.common.Tier
|
import li.cil.oc.common.Tier
|
||||||
|
import li.cil.oc.util.StackOption
|
||||||
|
import li.cil.oc.util.StackOption._
|
||||||
import net.minecraft.inventory.IInventory
|
import net.minecraft.inventory.IInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.util.text.ITextComponent
|
import net.minecraft.util.text.ITextComponent
|
||||||
@ -60,8 +62,8 @@ abstract class Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected def exists(inventory: IInventory, p: ItemStack => Boolean) = {
|
protected def exists(inventory: IInventory, p: ItemStack => Boolean) = {
|
||||||
(0 until inventory.getSizeInventory).exists(slot => Option(inventory.getStackInSlot(slot)) match {
|
(0 until inventory.getSizeInventory).exists(slot => StackOption(inventory.getStackInSlot(slot)) match {
|
||||||
case Some(stack) => p(stack)
|
case SomeStack(stack) => p(stack)
|
||||||
case _ => false
|
case _ => false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ import li.cil.oc.util.BlockPosition
|
|||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
import li.cil.oc.util.ExtendedWorld._
|
import li.cil.oc.util.ExtendedWorld._
|
||||||
import li.cil.oc.util.InventoryUtils
|
import li.cil.oc.util.InventoryUtils
|
||||||
|
import li.cil.oc.util.StackOption
|
||||||
|
import li.cil.oc.util.StackOption._
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockLiquid
|
import net.minecraft.block.BlockLiquid
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
@ -357,8 +359,8 @@ class Robot extends traits.Computer with traits.PowerInformation with traits.Rot
|
|||||||
}
|
}
|
||||||
if (!appliedToolEnchantments) {
|
if (!appliedToolEnchantments) {
|
||||||
appliedToolEnchantments = true
|
appliedToolEnchantments = true
|
||||||
Option(getStackInSlot(0)) match {
|
StackOption(getStackInSlot(0)) match {
|
||||||
case Some(item) => player_.getAttributeMap.applyAttributeModifiers(item.getAttributeModifiers(EntityEquipmentSlot.MAINHAND))
|
case SomeStack(item) => player_.getAttributeMap.applyAttributeModifiers(item.getAttributeModifiers(EntityEquipmentSlot.MAINHAND))
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -578,10 +580,10 @@ class Robot extends traits.Computer with traits.PowerInformation with traits.Rot
|
|||||||
if (isServer) {
|
if (isServer) {
|
||||||
if (isToolSlot(slot)) {
|
if (isToolSlot(slot)) {
|
||||||
player_.getAttributeMap.removeAttributeModifiers(stack.getAttributeModifiers(EntityEquipmentSlot.MAINHAND))
|
player_.getAttributeMap.removeAttributeModifiers(stack.getAttributeModifiers(EntityEquipmentSlot.MAINHAND))
|
||||||
ServerPacketSender.sendRobotInventory(this, slot, null)
|
ServerPacketSender.sendRobotInventory(this, slot, ItemStack.EMPTY)
|
||||||
}
|
}
|
||||||
if (isUpgradeSlot(slot)) {
|
if (isUpgradeSlot(slot)) {
|
||||||
ServerPacketSender.sendRobotInventory(this, slot, null)
|
ServerPacketSender.sendRobotInventory(this, slot, ItemStack.EMPTY)
|
||||||
}
|
}
|
||||||
if (isFloppySlot(slot)) {
|
if (isFloppySlot(slot)) {
|
||||||
common.Sound.playDiskEject(this)
|
common.Sound.playDiskEject(this)
|
||||||
@ -675,10 +677,10 @@ class Robot extends traits.Computer with traits.PowerInformation with traits.Rot
|
|||||||
|
|
||||||
override def componentSlot(address: String): Int = components.indexWhere(_.exists(env => env.node != null && env.node.address == address))
|
override def componentSlot(address: String): Int = components.indexWhere(_.exists(env => env.node != null && env.node.address == address))
|
||||||
|
|
||||||
override def hasRedstoneCard: Boolean = (containerSlots ++ componentSlots).exists(slot => Option(getStackInSlot(slot)).fold(false)(DriverRedstoneCard.worksWith(_, getClass)))
|
override def hasRedstoneCard: Boolean = (containerSlots ++ componentSlots).exists(slot => StackOption(getStackInSlot(slot)).fold(false)(DriverRedstoneCard.worksWith(_, getClass)))
|
||||||
|
|
||||||
private def computeInventorySize() = math.min(maxInventorySize, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (Option(getStackInSlot(slot)) match {
|
private def computeInventorySize() = math.min(maxInventorySize, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (StackOption(getStackInSlot(slot)) match {
|
||||||
case Some(stack) => Option(Driver.driverFor(stack, getClass)) match {
|
case SomeStack(stack) => Option(Driver.driverFor(stack, getClass)) match {
|
||||||
case Some(driver: item.Inventory) => driver.inventoryCapacity(stack)
|
case Some(driver: item.Inventory) => driver.inventoryCapacity(stack)
|
||||||
case _ => 0
|
case _ => 0
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package li.cil.oc.server.agent
|
|||||||
import li.cil.oc.api.internal
|
import li.cil.oc.api.internal
|
||||||
import li.cil.oc.util.ExtendedInventory._
|
import li.cil.oc.util.ExtendedInventory._
|
||||||
import li.cil.oc.util.InventoryUtils
|
import li.cil.oc.util.InventoryUtils
|
||||||
|
import li.cil.oc.util.StackOption
|
||||||
|
import li.cil.oc.util.StackOption._
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.entity.player.InventoryPlayer
|
import net.minecraft.entity.player.InventoryPlayer
|
||||||
import net.minecraft.item.Item
|
import net.minecraft.item.Item
|
||||||
@ -32,8 +34,8 @@ class Inventory(val agent: internal.Agent) extends InventoryPlayer(null) {
|
|||||||
|
|
||||||
override def decrementAnimations() {
|
override def decrementAnimations() {
|
||||||
for (slot <- 0 until getSizeInventory) {
|
for (slot <- 0 until getSizeInventory) {
|
||||||
Option(getStackInSlot(slot)) match {
|
StackOption(getStackInSlot(slot)) match {
|
||||||
case Some(stack) => try stack.updateAnimation(agent.world, if (!agent.world.isRemote) agent.player else null, slot, slot == 0) catch {
|
case SomeStack(stack) => try stack.updateAnimation(agent.world, if (!agent.world.isRemote) agent.player else null, slot, slot == 0) catch {
|
||||||
case ignored: NullPointerException => // Client side item updates that need a player instance...
|
case ignored: NullPointerException => // Client side item updates that need a player instance...
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user