diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/pastebin.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/pastebin.lua index 685428499..b5ff93473 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/pastebin.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/pastebin.lua @@ -21,7 +21,7 @@ local function get(pasteId, filename) end io.write("Downloading from pastebin.com... ") - local url = "http://pastebin.com/raw.php?i=" .. pasteId + local url = "http://pastebin.com/raw/" .. pasteId local result, response = pcall(internet.request, url) if result then io.write("success.\n") diff --git a/src/main/resources/assets/opencomputers/loot/openos/boot/00_base.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/00_base.lua index 87311875c..581584347 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/boot/00_base.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/boot/00_base.lua @@ -15,7 +15,8 @@ function loadfile(filename, mode, env) end table.insert(buffer, data) end - buffer = table.concat(buffer):gsub("^#![^\n]+", "") -- remove shebang if any + buffer[1] = (buffer[1] or ""):gsub("^#![^\n]+", "") -- remove shebang if any + buffer = table.concat(buffer) return load(buffer, "=" .. filename, mode, env) end diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua index 297fbd890..b936ac261 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua @@ -390,7 +390,13 @@ function term.drawText(value, wrap, window) local function scroll(_sy,_y) return _sy + term.internal.scroll(window,_y-h), math.min(_y,h) end + local uptime = computer.uptime + local last_sleep = uptime() while index <= vlen do + if uptime() - last_sleep > 4 then + os.sleep(0) + last_sleep = uptime() + end local si,ei = value:find("[\t\r\n\a]", index) si = si or vlen+1 if index==si then @@ -401,7 +407,7 @@ function term.drawText(value, wrap, window) x,y=1,y+1 sy,y = scroll(sy,y) elseif delim=="\a" and not beeped then - require("computer").beep() + computer.beep() beeped = true end cr_last = delim == "\r" diff --git a/src/main/scala/li/cil/oc/common/entity/Drone.scala b/src/main/scala/li/cil/oc/common/entity/Drone.scala index a1873a020..aeabb8a59 100644 --- a/src/main/scala/li/cil/oc/common/entity/Drone.scala +++ b/src/main/scala/li/cil/oc/common/entity/Drone.scala @@ -583,6 +583,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern } override def writeEntityToNBT(nbt: NBTTagCompound) { + if (worldObj.isRemote) return components.saveComponents() info.storedEnergy = control.node.localBuffer.toInt nbt.setNewCompoundTag("info", info.save) diff --git a/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala b/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala index 7d563a06d..a771dc054 100644 --- a/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala +++ b/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala @@ -1,5 +1,6 @@ package li.cil.oc.server.component.traits +import cpw.mods.fml.common.eventhandler.Event.Result import li.cil.oc.Settings import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -10,7 +11,9 @@ import li.cil.oc.util.InventoryUtils import li.cil.oc.util.ResultWrapper.result import net.minecraft.entity.item.EntityItem import net.minecraft.item.ItemBlock +import net.minecraftforge.common.MinecraftForge import net.minecraftforge.common.util.ForgeDirection +import net.minecraftforge.event.entity.item.ItemTossEvent trait InventoryWorldControl extends InventoryAware with WorldAware with SideRestricted { @Callback(doc = "function(side:number[, fuzzy:boolean=false]):boolean -- Compare the block on the specified side with the one in the selected slot. Returns true if equal.") @@ -54,8 +57,15 @@ trait InventoryWorldControl extends InventoryAware with WorldAware with SideRest case _ => // No inventory to drop into, drop into the world. val dropped = inventory.decrStackSize(selectedSlot, count) + val validator = (item: EntityItem) => { + val event = new ItemTossEvent(item, fakePlayer) + val canceled = MinecraftForge.EVENT_BUS.post(event) + val denied = event.hasResult && event.getResult == Result.DENY + !canceled && !denied + } if (dropped != null && dropped.stackSize > 0) { - InventoryUtils.spawnStackInWorld(position, dropped, Some(facing)) + if (InventoryUtils.spawnStackInWorld(position, dropped, Some(facing), Some(validator)) == null) + fakePlayer.inventory.addItemStackToInventory(dropped) } } diff --git a/src/main/scala/li/cil/oc/util/InventoryUtils.scala b/src/main/scala/li/cil/oc/util/InventoryUtils.scala index ef4c5a2b5..731926027 100644 --- a/src/main/scala/li/cil/oc/util/InventoryUtils.scala +++ b/src/main/scala/li/cil/oc/util/InventoryUtils.scala @@ -227,14 +227,14 @@ object InventoryUtils { } /** - * Extracts an item stack from an inventory. - *

- * This will try to remove items of the same type as the specified item stack - * up to the number of the stack's size for all slots in the specified inventory. - *

- * This uses the extractFromInventorySlot method, and therefore - * handles special cases such as sided inventories and stack size limits. - */ + * Extracts an item stack from an inventory. + *

+ * This will try to remove items of the same type as the specified item stack + * up to the number of the stack's size for all slots in the specified inventory. + *

+ * This uses the extractFromInventorySlot method, and therefore + * handles special cases such as sided inventories and stack size limits. + */ def extractFromInventory(stack: ItemStack, inventory: IInventory, side: ForgeDirection, simulate: Boolean = false) = { val range = inventory match { case sided: ISidedInventory => sided.getAccessibleSlotsFromSide(side.ordinal).toIterable @@ -362,7 +362,7 @@ object InventoryUtils { /** * Utility method for spawning an item stack in the world. */ - def spawnStackInWorld(position: BlockPosition, stack: ItemStack, direction: Option[ForgeDirection] = None): EntityItem = position.world match { + def spawnStackInWorld(position: BlockPosition, stack: ItemStack, direction: Option[ForgeDirection] = None, validator: Option[EntityItem => Boolean] = None): EntityItem = position.world match { case Some(world) if stack != null && stack.stackSize > 0 => val rng = world.rand val (ox, oy, oz) = direction.fold((0, 0, 0))(d => (d.offsetX, d.offsetY, d.offsetZ)) @@ -376,8 +376,11 @@ object InventoryUtils { entity.motionY = 0.0125 * (rng.nextDouble - 0.5) + oy * 0.08 + (ox + oz) * 0.03 entity.motionZ = 0.0125 * (rng.nextDouble - 0.5) + oz * 0.03 entity.delayBeforeCanPickup = 15 - world.spawnEntityInWorld(entity) - entity + if (validator.fold(true)(_(entity))) { + world.spawnEntityInWorld(entity) + entity + } + else null case _ => null } }