From e27b7bf7f1889e7ff16d62914c7ad1cb98a1d082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 14 May 2015 15:07:33 +0200 Subject: [PATCH 1/2] Slow block breaking for robots and drones. Beware: this means that swing() may now return true even though the robot didn't really break the block (in case something else broke it before the robot finished). --- .../renderer/tileentity/RobotRenderer.scala | 7 +++- .../li/cil/oc/common/tileentity/Robot.scala | 4 +- .../scala/li/cil/oc/server/agent/Player.scala | 40 ++++++++++++++++++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala index 874dd6eee..d034b5e49 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala @@ -350,8 +350,11 @@ object RobotRenderer extends TileEntitySpecialRenderer { GL11.glTranslatef(0, -8 * 0.0625F - 0.0078125F, -0.5F) if (robot.isAnimatingSwing) { - val remaining = (robot.animationTicksLeft - f) / robot.animationTicksTotal.toDouble - GL11.glRotatef((Math.sin(remaining * Math.PI) * 45).toFloat, 1, 0, 0) + val wantedTicksPerCycle = 10 + val cycles = math.max(robot.animationTicksTotal / wantedTicksPerCycle, 1) + val ticksPerCycle = robot.animationTicksTotal / cycles + val remaining = (robot.animationTicksLeft - f) / ticksPerCycle.toDouble + GL11.glRotatef((Math.sin((remaining - remaining.toInt) * Math.PI) * 45).toFloat, 1, 0, 0) } val customRenderer = MinecraftForgeClient.getItemRenderer(stack, EQUIPPED) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala index 0da64046e..2062041fe 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -329,7 +329,7 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand } def setAnimateSwing(ticks: Int) { - animationTicksTotal = ticks + animationTicksTotal = math.max(ticks, 5) prepareForAnimation() swingingTool = true } @@ -854,5 +854,5 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand override def getTankInfo(from: ForgeDirection) = components.collect { case Some(t: IFluidTank) => t.getInfo - }.toArray + } } diff --git a/src/main/scala/li/cil/oc/server/agent/Player.scala b/src/main/scala/li/cil/oc/server/agent/Player.scala index a0ba23533..569a44569 100644 --- a/src/main/scala/li/cil/oc/server/agent/Player.scala +++ b/src/main/scala/li/cil/oc/server/agent/Player.scala @@ -10,6 +10,7 @@ import li.cil.oc.Settings import li.cil.oc.api.event._ import li.cil.oc.api.internal import li.cil.oc.api.network.Connector +import li.cil.oc.common.EventHandler import li.cil.oc.integration.Mods import li.cil.oc.integration.util.PortalGun import li.cil.oc.integration.util.TinkersConstruct @@ -269,7 +270,7 @@ class Player(val agent: internal.Agent) extends FakePlayer(agent.world.asInstanc }, repair = false) } - def clickBlock(x: Int, y: Int, z: Int, side: Int): Double = { + def clickBlock(x: Int, y: Int, z: Int, side: Int, immediate: Boolean = false): Double = { callUsingItemInSlot(agent.equipmentInventory, 0, stack => { if (shouldCancel(() => ForgeEventFactory.onPlayerInteract(this, Action.LEFT_CLICK_BLOCK, x, y, z, side, world))) { return 0 @@ -345,6 +346,13 @@ class Player(val agent: internal.Agent) extends FakePlayer(agent.world.asInstanc return 0 } + if (!immediate) { + EventHandler.schedule(() => new DamageOverTime(this, x, y, z, side, (adjustedBreakTime * 20).toInt).tick()) + return adjustedBreakTime + } + + world.destroyBlockInWorldPartially(-1, x, y, z, -1) + world.playAuxSFXAtEntity(this, 2001, x, y, z, Block.getIdFromBlock(block) + (metadata << 12)) if (stack != null) { @@ -549,4 +557,34 @@ class Player(val agent: internal.Agent) extends FakePlayer(agent.world.asInstanc override def func_146101_a(tileEntity: TileEntityFurnace) {} override def func_146093_a(tileEntity: TileEntityHopper) {} + + // ----------------------------------------------------------------------- // + + class DamageOverTime(val player: Player, val x: Int, val y: Int, val z: Int, val side: Int, val ticksTotal: Int) { + val world = player.world + var ticks = 0 + var lastDamageSent = 0 + + def tick(): Unit = { + // Cancel if the agent stopped or our action is invalidated some other way. + if (world != player.world || !world.blockExists(x, y, z) || world.isAirBlock(x, y, z) || !player.agent.machine.isRunning) { + world.destroyBlockInWorldPartially(-1, x, y, z, -1) + return + } + + val damage = 10 * ticks / math.max(ticksTotal, 1) + if (damage >= 10) { + player.clickBlock(x, y, z, side, immediate = true) + } + else { + ticks += 1 + if (damage != lastDamageSent) { + lastDamageSent = damage + world.destroyBlockInWorldPartially(-1, x, y, z, damage) + } + EventHandler.schedule(() => tick()) + } + } + } + } From 611f76c15807d061a8a01dac58e4ff0919bb41e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 14 May 2015 16:07:30 +0200 Subject: [PATCH 2/2] Added fake endstone, oredicted that and normal endstone for use in drone recipe. Because someone was nagging about vanilla MC balance. As if there were such a thing :P --- .../assets/opencomputers/lang/en_US.lang | 2 ++ .../opencomputers/recipes/default.recipes | 24 +++++++++---------- src/main/scala/li/cil/oc/Constants.scala | 1 + src/main/scala/li/cil/oc/common/Proxy.scala | 3 +++ .../cil/oc/common/block/ChameliumBlock.scala | 3 ++- .../li/cil/oc/common/block/FakeEndstone.scala | 17 +++++++++++++ .../li/cil/oc/common/block/Keyboard.scala | 3 ++- .../li/cil/oc/common/block/SimpleBlock.scala | 4 +++- .../scala/li/cil/oc/common/init/Blocks.scala | 3 +++ 9 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 src/main/scala/li/cil/oc/common/block/FakeEndstone.scala diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index aabaf1bab..ef78cebd6 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -16,6 +16,7 @@ tile.oc.chameliumBlock.name=Block of Chamelium tile.oc.charger.name=Charger tile.oc.disassembler.name=Disassembler tile.oc.diskDrive.name=Disk Drive +tile.oc.endstone.name=End Stone tile.oc.geolyzer.name=Geolyzer tile.oc.hologram1.name=Hologram Projector (Tier 1) tile.oc.hologram2.name=Hologram Projector (Tier 2) @@ -261,6 +262,7 @@ oc:tooltip.DiskDrive=Allows reading and writing floppies. Can be installed in ro oc:tooltip.Drone=Drones are light-weight, fast reconnaissance units with limited cargo space. oc:tooltip.DroneCase=This casing is used to build Drones in the assembler. It has room for a small amount of components and provides endstone-powered levitation. oc:tooltip.EEPROM=Small, programmable storage that contains the BIOS computers use to boot. +oc:tooltip.FakeEndstone=Almost as good as the real thing, even emulates its floatiness! oc:tooltip.Geolyzer=Allows scanning the surrounding area's blocks' hardness. This information can be useful for generating holograms of the area or for detecting ores. oc:tooltip.GraphicsCard=Used to change what's displayed on screens.[nl] Maximum resolution: §f%sx%s§7[nl] Maximum color depth: §f%s§7[nl] Operations/tick: §f%s§7 oc:tooltip.InkCartridge=Used to refill ink in 3D printers. For mysterious reasons it does not have to remain in the printer. diff --git a/src/main/resources/assets/opencomputers/recipes/default.recipes b/src/main/resources/assets/opencomputers/recipes/default.recipes index 83f905aff..b5399f3e0 100644 --- a/src/main/resources/assets/opencomputers/recipes/default.recipes +++ b/src/main/resources/assets/opencomputers/recipes/default.recipes @@ -36,25 +36,16 @@ luaBios { type: shapeless input: ["oc:eeprom", "oc:manual"] } -generic: [ - { - result: {block="minecraft:end_stone"} - input: [[enderPearl, sandstone, enderPearl] - [sandstone, blockCoal, sandstone] - [enderPearl, sandstone, enderPearl]] - output: 4 - } -] droneCase1 { - input: [[{block="minecraft:end_stone"}, compass, {block="minecraft:end_stone"}] + input: [["oc:stoneEndstone", compass, "oc:stoneEndstone"] ["oc:circuitChip1", "oc:microcontrollerCase1", "oc:circuitChip1"] - [{block="minecraft:end_stone"}, "oc:componentBus2", {block="minecraft:end_stone"}]] + ["oc:stoneEndstone", "oc:componentBus2", "oc:stoneEndstone"]] } droneCase2 { - input: [[{block="minecraft:end_stone"}, compass, {block="minecraft:end_stone"}] + input: [["oc:stoneEndstone", compass, "oc:stoneEndstone"] ["oc:circuitChip2", "oc:microcontrollerCase2", "oc:circuitChip2"] - [{block="minecraft:end_stone"}, "oc:componentBus3", {block="minecraft:end_stone"}]] + ["oc:stoneEndstone", "oc:componentBus3", "oc:stoneEndstone"]] } microcontrollerCase1 { input: [[nuggetIron, "oc:circuitChip1", nuggetIron] @@ -373,6 +364,13 @@ chameliumBlock { ["oc:chamelium", "oc:chamelium", "oc:chamelium"], ["oc:chamelium", "oc:chamelium", "oc:chamelium"]] } + +endstone { + input: [[enderPearl, "oc:chameliumBlock", enderPearl] + ["oc:chameliumBlock", enderPearl, "oc:chameliumBlock"] + [enderPearl, "oc:chameliumBlock", enderPearl]] + output: 4 +} inkCartridgeEmpty { input: [[nuggetIron, dispenser, nuggetIron], ["oc:materialTransistor", bucket, "oc:materialTransistor"], diff --git a/src/main/scala/li/cil/oc/Constants.scala b/src/main/scala/li/cil/oc/Constants.scala index 881c65c3c..cb00dea32 100644 --- a/src/main/scala/li/cil/oc/Constants.scala +++ b/src/main/scala/li/cil/oc/Constants.scala @@ -18,6 +18,7 @@ object Constants { final val Charger = "charger" final val Disassembler = "disassembler" final val DiskDrive = "diskDrive" + final val Endstone = "endstone" final val Geolyzer = "geolyzer" final val HologramTier1 = "hologram1" final val HologramTier2 = "hologram2" diff --git a/src/main/scala/li/cil/oc/common/Proxy.scala b/src/main/scala/li/cil/oc/common/Proxy.scala index 1f2d0e71e..9f1de9090 100644 --- a/src/main/scala/li/cil/oc/common/Proxy.scala +++ b/src/main/scala/li/cil/oc/common/Proxy.scala @@ -55,6 +55,9 @@ class Proxy { // oredict entry, but not normal obsidian, breaking some recipes. OreDictionary.registerOre("obsidian", net.minecraft.init.Blocks.obsidian) + // To still allow using normal endstone for crafting drones. + OreDictionary.registerOre("oc:stoneEndstone", net.minecraft.init.Blocks.end_stone) + OpenComputers.log.info("Initializing OpenComputers API.") api.CreativeTab.instance = CreativeTab diff --git a/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala b/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala index 3de90f632..18f69c865 100644 --- a/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala +++ b/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala @@ -1,8 +1,9 @@ package li.cil.oc.common.block import li.cil.oc.util.Color +import net.minecraft.block.material.Material -class ChameliumBlock extends SimpleBlock { +class ChameliumBlock extends SimpleBlock(Material.rock) { override protected def customTextures = Array( Some("White"), Some("White"), diff --git a/src/main/scala/li/cil/oc/common/block/FakeEndstone.scala b/src/main/scala/li/cil/oc/common/block/FakeEndstone.scala new file mode 100644 index 000000000..791459abd --- /dev/null +++ b/src/main/scala/li/cil/oc/common/block/FakeEndstone.scala @@ -0,0 +1,17 @@ +package li.cil.oc.common.block + +import net.minecraft.block.material.Material + +class FakeEndstone extends SimpleBlock(Material.rock) { + setHardness(3) + setResistance(15) + + override protected def customTextures = Array( + Some("minecraft:end_stone"), + Some("minecraft:end_stone"), + Some("minecraft:end_stone"), + Some("minecraft:end_stone"), + Some("minecraft:end_stone"), + Some("minecraft:end_stone") + ) +} diff --git a/src/main/scala/li/cil/oc/common/block/Keyboard.scala b/src/main/scala/li/cil/oc/common/block/Keyboard.scala index 7c8d8fb2e..bbef0dc2d 100644 --- a/src/main/scala/li/cil/oc/common/block/Keyboard.scala +++ b/src/main/scala/li/cil/oc/common/block/Keyboard.scala @@ -7,13 +7,14 @@ import li.cil.oc.common.tileentity import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedWorld._ import net.minecraft.block.Block +import net.minecraft.block.material.Material import net.minecraft.entity.player.EntityPlayer import net.minecraft.world.IBlockAccess import net.minecraft.world.World import net.minecraftforge.common.util.ForgeDirection import org.lwjgl.opengl.GL11 -class Keyboard extends SimpleBlock with traits.SpecialBlock { +class Keyboard extends SimpleBlock(Material.rock) with traits.SpecialBlock { setLightOpacity(0) // For Immibis Microblock support. diff --git a/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala b/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala index 31d83ee3e..e272d0b9d 100644 --- a/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala +++ b/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala @@ -77,7 +77,9 @@ class SimpleBlock(material: Material = Material.iron) extends Block(material) { val custom = customTextures for (side <- ForgeDirection.VALID_DIRECTIONS) { custom(side.ordinal) match { - case Some(name) => icons(side.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":" + name) + case Some(name) => + if (name.contains(":")) icons(side.ordinal) = iconRegister.registerIcon(name) + else icons(side.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":" + name) case _ => } } diff --git a/src/main/scala/li/cil/oc/common/init/Blocks.scala b/src/main/scala/li/cil/oc/common/init/Blocks.scala index 95bd32d88..fd5161737 100644 --- a/src/main/scala/li/cil/oc/common/init/Blocks.scala +++ b/src/main/scala/li/cil/oc/common/init/Blocks.scala @@ -72,5 +72,8 @@ object Blocks { Recipes.addBlock(new Printer(), "printer", "oc:printer") Recipes.addBlock(new ChameliumBlock(), "chameliumBlock", "oc:chameliumBlock") Recipes.addBlock(new Waypoint(), Constants.BlockName.Waypoint, "oc:waypoint") + + // v1.5.10 + Recipes.addBlock(new FakeEndstone(), Constants.BlockName.Endstone, "oc:stoneEndstone") } }