From 3f2757ad93b42f627117837c1afffa52dcfa3e21 Mon Sep 17 00:00:00 2001 From: payonel Date: Fri, 23 Aug 2019 15:07:23 -0700 Subject: [PATCH] adding angle upgrade support to drones closes #985 only for 1.12 --- .../scala/li/cil/oc/server/component/Agent.scala | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/Agent.scala b/src/main/scala/li/cil/oc/server/component/Agent.scala index 652506b01..633ef7e77 100644 --- a/src/main/scala/li/cil/oc/server/component/Agent.scala +++ b/src/main/scala/li/cil/oc/server/component/Agent.scala @@ -14,6 +14,8 @@ import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedArguments._ import li.cil.oc.util.ExtendedWorld._ import li.cil.oc.util.InventoryUtils +import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityMinecart @@ -279,8 +281,16 @@ trait Agent extends traits.WorldControl with traits.InventoryControl with traits // but for a drone, the block at its position is air, which is replaceable, and thus // ItemBlock does not offset the position. We can do it here to correct that, and the code // here is still correct for the robot's use case - val adjustedPos = blockPos.offset(facing) - player.placeBlock(agent.selectedSlot, adjustedPos, facing, hx, hy, hz) + val adjustedPos: BlockPos = blockPos.offset(facing) + // adjustedPos is the position we want to place the block + // but onItemUse will try to adjust the placement if the target position is not replaceable + // we don't want that + val block: Block = world.getBlockState(adjustedPos).getBlock + if (block.isReplaceable(world, adjustedPos)) { + player.placeBlock(agent.selectedSlot, adjustedPos, facing, hx, hy, hz) + } else { + false + } case _ => false } player.setSneaking(false)