From 234651592e71153985f8900423ec1bc7ae9b4061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 20 Mar 2014 11:18:14 +0100 Subject: [PATCH] made hardmode.recipes include default.recipes to avoid missing recipes when players comment out the default recipes in the user.recipes; additionally using block break event to check if robots may break blocks (either by "clicking" them or by moving into them), making it compatible with WorldGuard, e.g. --- .../opencomputers/recipes/hardmode.recipes | 2 ++ .../oc/server/component/robot/Player.scala | 24 ++++++++++--------- .../cil/oc/server/component/robot/Robot.scala | 12 +++++++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/resources/assets/opencomputers/recipes/hardmode.recipes b/src/main/resources/assets/opencomputers/recipes/hardmode.recipes index 571ef0346..bb6fc78dc 100644 --- a/src/main/resources/assets/opencomputers/recipes/hardmode.recipes +++ b/src/main/resources/assets/opencomputers/recipes/hardmode.recipes @@ -1,6 +1,8 @@ # Do not change this file, it is rewritten each time you start the game. # Instead, use the user.recipes file to edit recipes by redefining them there. +include file("default.recipes") + analyzer { input: [["", torchRedstoneActive, ""] ["oc:craftingTransistor", "oc:circuitTier1", nuggetGold] 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 a60cc34cd..a62e4f2ae 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 @@ -1,11 +1,10 @@ package li.cil.oc.server.component.robot import cpw.mods.fml.common.Loader -import li.cil.oc.Settings import li.cil.oc.common.tileentity +import li.cil.oc.Settings import li.cil.oc.util.mods.{UniversalElectricity, TinkersConstruct, PortalGun} import net.minecraft.block.{BlockPistonBase, BlockFluid, Block} -import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.entity.item.EntityItem import net.minecraft.entity.player.{EnumStatus, EntityPlayer} import net.minecraft.entity.{IMerchant, EntityLivingBase, Entity} @@ -14,8 +13,9 @@ import net.minecraft.potion.PotionEffect import net.minecraft.server.MinecraftServer import net.minecraft.util._ import net.minecraft.world.World -import net.minecraftforge.common.{ForgeHooks, ForgeDirection} +import net.minecraftforge.common.{MinecraftForge, ForgeHooks, ForgeDirection} import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action +import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.event.{Event, ForgeEventFactory} import net.minecraftforge.fluids.FluidRegistry import scala.collection.convert.WrapAsScala._ @@ -183,7 +183,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett def placeBlock(slot: Int, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = { callUsingItemInSlot(slot, stack => { val event = ForgeEventFactory.onPlayerInteract(this, Action.RIGHT_CLICK_BLOCK, x, y, z, side) - if (event.isCanceled || event.useBlock == Event.Result.DENY) { + if (event.isCanceled || event.useBlock == Event.Result.DENY || event.useItem == Event.Result.DENY) { return false } @@ -194,7 +194,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett def clickBlock(x: Int, y: Int, z: Int, side: Int): Double = { callUsingItemInSlot(0, stack => { val event = ForgeEventFactory.onPlayerInteract(this, Action.LEFT_CLICK_BLOCK, x, y, z, side) - if (event.isCanceled) { + if (event.isCanceled || event.useBlock == Event.Result.DENY || event.useItem == Event.Result.DENY) { return 0 } @@ -206,7 +206,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett val blockId = world.getBlockId(x, y, z) val block = Block.blocksList(blockId) val metadata = world.getBlockMetadata(x, y, z) - val mayClickBlock = event.useBlock != Event.Result.DENY && blockId > 0 && block != null + val mayClickBlock = blockId > 0 && block != null val canClickBlock = mayClickBlock && !block.isAirBlock(world, x, y, z) && FluidRegistry.lookupFluidForBlock(block) == null && @@ -215,6 +215,12 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett return 0 } + val breakEvent = new BlockEvent.BreakEvent(x, y, z, world, block, metadata, this) + MinecraftForge.EVENT_BUS.post(breakEvent) + if (breakEvent.isCanceled) { + return 0 + } + block.onBlockClicked(world, x, y, z, this) world.extinguishFire(this, x, y, z, side) @@ -272,11 +278,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett // check only serves to test whether the block can drop anything at all. if (block.canHarvestBlock(this, metadata)) { block.harvestBlock(world, this, x, y, z, metadata) - if (!EnchantmentHelper.getSilkTouchModifier(this)) { - val fortune = EnchantmentHelper.getFortuneModifier(this) - val xp = block.getExpDrop(world, metadata, fortune) - robot.addXp(xp * Settings.get.robotOreXpRate) - } + robot.addXp(breakEvent.getExpToDrop * Settings.get.robotOreXpRate) } if (stack != null) { robot.addXp(Settings.get.robotActionXp) diff --git a/src/main/scala/li/cil/oc/server/component/robot/Robot.scala b/src/main/scala/li/cil/oc/server/component/robot/Robot.scala index 17db12887..e48d092d2 100644 --- a/src/main/scala/li/cil/oc/server/component/robot/Robot.scala +++ b/src/main/scala/li/cil/oc/server/component/robot/Robot.scala @@ -15,7 +15,8 @@ import net.minecraft.item.{ItemStack, ItemBlock} import net.minecraft.nbt.NBTTagCompound import net.minecraft.tileentity.TileEntityChest import net.minecraft.util.{MovingObjectPosition, EnumMovingObjectType} -import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.common.{MinecraftForge, ForgeDirection} +import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.fluids.FluidRegistry import scala.collection.convert.WrapAsScala._ @@ -586,14 +587,19 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { val (bx, by, bz) = (x + side.offsetX, y + side.offsetY, z + side.offsetZ) val id = world.getBlockId(bx, by, bz) val block = Block.blocksList(id) + val metadata = world.getBlockMetadata(bx, by, bz) if (id == 0 || block == null || block.isAirBlock(world, bx, by, bz)) { (false, "air") } else if (FluidRegistry.lookupFluidForBlock(block) != null || block.isInstanceOf[BlockFluid]) { - (false, "liquid") + val event = new BlockEvent.BreakEvent(bx, by, bz, world, block, metadata, player) + MinecraftForge.EVENT_BUS.post(event) + (event.isCanceled, "liquid") } else if (block.isBlockReplaceable(world, bx, by, bz)) { - (false, "replaceable") + val event = new BlockEvent.BreakEvent(bx, by, bz, world, block, metadata, player) + MinecraftForge.EVENT_BUS.post(event) + (event.isCanceled, "replaceable") } else { (true, "solid")