From 90648a90c1146843db99c3c6a942a797bd27b177 Mon Sep 17 00:00:00 2001 From: PixelToast Date: Wed, 2 Apr 2014 18:45:13 -0400 Subject: [PATCH 1/2] Added :gsub("\\\n","\\n") to string serialization this is because string.format("q","\n")=="\\\n" which can break some database programs --- .../assets/opencomputers/lua/rom/lib/serialization.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/opencomputers/lua/rom/lib/serialization.lua b/src/main/resources/assets/opencomputers/lua/rom/lib/serialization.lua index ed2b25190..6dc4cb0b4 100644 --- a/src/main/resources/assets/opencomputers/lua/rom/lib/serialization.lua +++ b/src/main/resources/assets/opencomputers/lua/rom/lib/serialization.lua @@ -28,7 +28,7 @@ function serialization.serialize(value, pretty) return tostring(v) end elseif t == "string" then - return string.format("%q", v) + return string.format("%q", v):gsub("\\\n","\\n") elseif t == "table" and pretty and getmetatable(v) and getmetatable(v).__tostring then return tostring(v) elseif t == "table" then @@ -130,4 +130,4 @@ function serialization.unserialize(data) return output end -return serialization \ No newline at end of file +return serialization From 523b4c12d3380e126a2ef9da2dd715782424c834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 3 Apr 2014 11:51:16 +0200 Subject: [PATCH 2/2] Suppressing use of the leash by robots, because that's horribly borked (due to the fake player entity only being server side and not being saved). Fixed robot interaction with entities when Battlegear 2 is present (e.g. shears on sheep). --- .../oc/server/component/robot/Player.scala | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/robot/Player.scala b/src/main/scala/li/cil/oc/server/component/robot/Player.scala index 7fb9f3c70..57af9f22b 100644 --- a/src/main/scala/li/cil/oc/server/component/robot/Player.scala +++ b/src/main/scala/li/cil/oc/server/component/robot/Player.scala @@ -9,13 +9,13 @@ import net.minecraft.block.{BlockPistonBase, BlockFluid, Block} import net.minecraft.entity.item.EntityItem import net.minecraft.entity.player.{EnumStatus, EntityPlayer} import net.minecraft.entity.{IMerchant, EntityLivingBase, Entity} -import net.minecraft.item.{ItemBlock, ItemStack} +import net.minecraft.item.{Item, ItemBlock, ItemStack} import net.minecraft.potion.PotionEffect import net.minecraft.server.MinecraftServer import net.minecraft.util._ import net.minecraft.world.World import net.minecraftforge.common.{MinecraftForge, ForgeHooks, ForgeDirection} -import net.minecraftforge.event.entity.player.PlayerInteractEvent +import net.minecraftforge.event.entity.player.{EntityInteractEvent, PlayerInteractEvent} import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.event.{Event, ForgeEventFactory} @@ -107,7 +107,25 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett } override def interactWith(entity: Entity) = { - callUsingItemInSlot(0, stack => super.interactWith(entity)) + val cancel = try MinecraftForge.EVENT_BUS.post(new EntityInteractEvent(this, entity)) catch { + case t: Throwable => + if (!t.getStackTrace.exists(_.getClassName.startsWith("mods.battlegear2."))) { + OpenComputers.log.log(Level.WARNING, "Some event handler screwed up!", t) + } + false + } + !cancel && callUsingItemInSlot(0, stack => { + val current = getCurrentEquippedItem + + val result = isItemUseAllowed(stack) && (entity.interactFirst(this) || (entity match { + case living: EntityLivingBase if current != null => current.func_111282_a(this, living) + case _ => false + })) + if (current != null && current.stackSize <= 0) { + destroyCurrentEquippedItem() + } + result + }) } def activateBlockOrUseItem(x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float, duration: Double): ActivationType.Value = { @@ -130,7 +148,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett val result = if (shouldActivate && block.onBlockActivated(world, x, y, z, this, side, hitX, hitY, hitZ)) ActivationType.BlockActivated - else if (tryPlaceBlockWhileHandlingFunnySpecialCases(stack, x, y, z, side, hitX, hitY, hitZ)) + else if (isItemUseAllowed(stack) && tryPlaceBlockWhileHandlingFunnySpecialCases(stack, x, y, z, side, hitX, hitY, hitZ)) ActivationType.ItemPlaced else if (tryUseItem(stack, duration)) ActivationType.ItemUsed @@ -152,9 +170,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett private def tryUseItem(stack: ItemStack, duration: Double) = { clearItemInUse() - stack != null && stack.stackSize > 0 && - (Settings.get.allowUseItemsWithDuration || stack.getMaxItemUseDuration <= 0) && - (!PortalGun.isPortalGun(stack) || PortalGun.isStandardPortalGun(stack)) && { + stack != null && stack.stackSize > 0 && isItemUseAllowed(stack) && { val oldSize = stack.stackSize val oldDamage = if (stack != null) stack.getItemDamage else 0 val oldData = if (stack.hasTagCompound) stack.getTagCompound.copy() else null @@ -290,6 +306,12 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett }) } + private def isItemUseAllowed(stack: ItemStack) = { + (Settings.get.allowUseItemsWithDuration || stack.getMaxItemUseDuration <= 0) && + (!PortalGun.isPortalGun(stack) || PortalGun.isStandardPortalGun(stack)) && + !stack.isItemEqual(new ItemStack(Item.leash)) + } + override def dropPlayerItemWithRandomChoice(stack: ItemStack, inPlace: Boolean) = robot.spawnStackInWorld(stack, if (inPlace) ForgeDirection.UNKNOWN else facing)