mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-29 07:51:12 -04:00
Merge branch 'master' of github.com:MightyPirates/OpenComputers into MC1.7
Conflicts: src/main/scala/li/cil/oc/server/component/robot/Player.scala
This commit is contained in:
commit
47ba428c59
@ -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
|
||||
|
@ -12,7 +12,7 @@ import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.entity.player.EntityPlayer.EnumStatus
|
||||
import net.minecraft.entity.{IMerchant, EntityLivingBase, Entity}
|
||||
import net.minecraft.init.Blocks
|
||||
import net.minecraft.init.{Items, Blocks}
|
||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
||||
import net.minecraft.potion.PotionEffect
|
||||
import net.minecraft.server.MinecraftServer
|
||||
@ -21,7 +21,7 @@ import net.minecraft.world.World
|
||||
import net.minecraftforge.common.ForgeHooks
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import net.minecraftforge.common.util.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.ForgeEventFactory
|
||||
import net.minecraftforge.event.world.BlockEvent
|
||||
@ -123,7 +123,25 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Play
|
||||
}
|
||||
|
||||
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.interactWithEntity(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 = {
|
||||
@ -145,7 +163,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Play
|
||||
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
|
||||
@ -167,9 +185,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Play
|
||||
|
||||
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
|
||||
@ -303,6 +319,12 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Play
|
||||
})
|
||||
}
|
||||
|
||||
private def isItemUseAllowed(stack: ItemStack) = {
|
||||
(Settings.get.allowUseItemsWithDuration || stack.getMaxItemUseDuration <= 0) &&
|
||||
(!PortalGun.isPortalGun(stack) || PortalGun.isStandardPortalGun(stack)) &&
|
||||
!stack.isItemEqual(new ItemStack(Items.lead))
|
||||
}
|
||||
|
||||
override def dropPlayerItemWithRandomChoice(stack: ItemStack, inPlace: Boolean) =
|
||||
robot.spawnStackInWorld(stack, if (inPlace) ForgeDirection.UNKNOWN else facing)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user