Skip to content

Commit

Permalink
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComput…
Browse files Browse the repository at this point in the history
…ers into master-MC1.7.10
  • Loading branch information
fnuecke committed Sep 18, 2016
2 parents 8309e52 + e36d8ec commit feb886b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
31 changes: 31 additions & 0 deletions src/main/java/li/cil/oc/api/event/SignChangeEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package li.cil.oc.api.event;

import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.tileentity.TileEntitySign;

/**
* A bit more specific sign change event that holds information about new text of the sign. Used in the sign upgrade.
*/
public abstract class SignChangeEvent extends Event {
public final TileEntitySign sign;
public final String[] lines;

private SignChangeEvent(TileEntitySign sign, String[] lines) {
this.sign = sign;
this.lines = lines;
}

@Cancelable
public static class Pre extends SignChangeEvent {
public Pre(TileEntitySign sign, String[] lines) {
super(sign, lines);
}
}

public static class Post extends SignChangeEvent {
public Post(TileEntitySign sign, String[] lines) {
super(sign, lines);
}
}
}
24 changes: 18 additions & 6 deletions src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,31 @@ function bit32.replace(n, v, field, width)
end

function bit32.lrotate(x, disp)
if disp == 0 then return x
elseif disp < 0 then return bit32.rrotate(x, -disp)
else return trim((x << disp) | (x >> (32 - disp))) end
if disp == 0 then
return x
elseif disp < 0 then
return bit32.rrotate(x, -disp)
else
disp = disp & 31
x = trim(x)
return trim((x << disp) | (x >> (32 - disp)))
end
end

function bit32.lshift(x, disp)
return trim(x << disp)
end

function bit32.rrotate(x, disp)
if disp == 0 then return x
elseif disp < 0 then return bit32.lrotate(x, -disp)
else return trim((x >> disp) | (x << (32 - disp))) end
if disp == 0 then
return x
elseif disp < 0 then
return bit32.lrotate(x, -disp)
else
disp = disp & 31
x = trim(x)
return trim((x >> disp) | (x << (32 - disp)))
end
end

function bit32.rshift(x, disp)
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/li/cil/oc/common/entity/Drone.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
override def interactFirst(player: EntityPlayer) = {
if (player.isSneaking) {
if (Wrench.isWrench(player.getHeldItem)) {
kill()
if(!world.isRemote) {
kill()
}
}
else if (!world.isRemote && !machine.isRunning) {
preparePowerUp()
Expand Down
22 changes: 18 additions & 4 deletions src/main/scala/li/cil/oc/server/component/UpgradeSign.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import li.cil.oc.api.driver.DeviceInfo.DeviceClass
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.api.driver.DeviceInfo
import li.cil.oc.api.event.SignChangeEvent
import li.cil.oc.api.network.EnvironmentHost
import li.cil.oc.api.internal
import li.cil.oc.api.network.Message
Expand Down Expand Up @@ -53,12 +54,18 @@ abstract class UpgradeSign extends prefab.ManagedEnvironment with DeviceInfo {
case robot: internal.Robot => robot.player
case _ => FakePlayerFactory.get(host.world.asInstanceOf[WorldServer], Settings.get.fakePlayerProfile)
}
if (!canChangeSign(player, sign)) {

val lines = text.lines.padTo(4, "").map(line => if (line.length > 15) line.substring(0, 15) else line).toArray

if (!canChangeSign(player, sign, lines)) {
return result(Unit, "not allowed")
}

text.lines.padTo(4, "").map(line => if (line.length > 15) line.substring(0, 15) else line).copyToArray(sign.signText)
lines.copyToArray(sign.signText)
host.world.markBlockForUpdate(sign.xCoord, sign.yCoord, sign.zCoord)

MinecraftForge.EVENT_BUS.post(new SignChangeEvent.Post(sign, lines))

result(sign.signText.mkString("\n"))
case _ => result(Unit, "no sign")
}
Expand All @@ -75,13 +82,20 @@ abstract class UpgradeSign extends prefab.ManagedEnvironment with DeviceInfo {
}
}

private def canChangeSign(player: EntityPlayer, tileEntity: TileEntitySign): Boolean = {
private def canChangeSign(player: EntityPlayer, tileEntity: TileEntitySign, lines: Array[String]): Boolean = {
if (!host.world.canMineBlock(player, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)) {
return false
}

val event = new BlockEvent.BreakEvent(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, host.world, tileEntity.getBlockType, tileEntity.getBlockMetadata, player)
MinecraftForge.EVENT_BUS.post(event)
!(event.isCanceled || event.getResult == Event.Result.DENY)
if (event.isCanceled || event.getResult == Event.Result.DENY) {
return false
}

val signEvent = new SignChangeEvent.Pre(tileEntity, lines)
MinecraftForge.EVENT_BUS.post(signEvent)
!(signEvent.isCanceled || signEvent.getResult == Event.Result.DENY)
}

override def onMessage(message: Message): Unit = {
Expand Down

0 comments on commit feb886b

Please sign in to comment.