mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Only pass X and Y to RackMountable.onActivate, adjusted to the actual surface area of the mountable (in [0, 1] for both, on the 14x3 pixel surface). Closes #1794.
This commit is contained in:
parent
af07508587
commit
ca5d95cff5
@ -7,7 +7,6 @@ import li.cil.oc.api.util.StateAware;
|
|||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this interface on environments provided by drivers for items that can
|
* Use this interface on environments provided by drivers for items that can
|
||||||
@ -63,11 +62,9 @@ public interface RackMountable extends ManagedEnvironment, StateAware {
|
|||||||
* pointlessly compressed fashion (because MC is a dummy like that).
|
* pointlessly compressed fashion (because MC is a dummy like that).
|
||||||
*
|
*
|
||||||
* @param player the player activating the mountable.
|
* @param player the player activating the mountable.
|
||||||
* @param side the side (in global coordinate space) of the rack that was activated.
|
* @param hitX the relative x coordinate of the activation on the mountable.
|
||||||
* @param hitX the relative x coordinate of the activation.
|
* @param hitY the relative y coordinate of the activation on the mountable.
|
||||||
* @param hitY the relative y coordinate of the activation.
|
|
||||||
* @param hitZ the relative z coordinate of the activation.
|
|
||||||
* @return whether the activation was handled (e.g. GUI opened).
|
* @return whether the activation was handled (e.g. GUI opened).
|
||||||
*/
|
*/
|
||||||
boolean onActivate(EntityPlayer player, ForgeDirection side, float hitX, float hitY, float hitZ);
|
boolean onActivate(EntityPlayer player, float hitX, float hitY);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import li.cil.oc.common.tileentity
|
|||||||
import net.minecraft.client.renderer.texture.IIconRegister
|
import net.minecraft.client.renderer.texture.IIconRegister
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.util.IIcon
|
import net.minecraft.util.IIcon
|
||||||
|
import net.minecraft.util.Vec3
|
||||||
import net.minecraft.world.IBlockAccess
|
import net.minecraft.world.IBlockAccess
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
import net.minecraftforge.common.util.ForgeDirection
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
@ -73,8 +74,19 @@ class Rack extends RedstoneAware with traits.SpecialBlock with traits.PowerAccep
|
|||||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
||||||
world.getTileEntity(x, y, z) match {
|
world.getTileEntity(x, y, z) match {
|
||||||
case rack: tileentity.Rack => rack.slotAt(side, hitX, hitY, hitZ) match {
|
case rack: tileentity.Rack => rack.slotAt(side, hitX, hitY, hitZ) match {
|
||||||
case Some(slot) => rack.getMountable(slot) match {
|
case Some(slot) =>
|
||||||
case mountable: RackMountable if mountable.onActivate(player, side, hitX, hitY, hitZ) => return true // Activation handled by mountable.
|
val hitVec = Vec3.createVectorHelper(hitX, hitY, hitZ)
|
||||||
|
val rotation = side match {
|
||||||
|
case ForgeDirection.WEST => Math.toRadians(90).toFloat
|
||||||
|
case ForgeDirection.NORTH => Math.toRadians(180).toFloat
|
||||||
|
case ForgeDirection.EAST => Math.toRadians(270).toFloat
|
||||||
|
case _ => 0
|
||||||
|
}
|
||||||
|
val localHitVec = rotate(hitVec.addVector(-0.5, -0.5, -0.5), rotation).addVector(0.5, 0.5, 0.5)
|
||||||
|
localHitVec.xCoord = ((if (side.offsetX != 0) 1 - localHitVec.xCoord else localHitVec.xCoord) * 16 - 1) / 14f
|
||||||
|
localHitVec.yCoord = ((1 - localHitVec.yCoord) * 16 - 2 - 3 * slot) / 3f
|
||||||
|
rack.getMountable(slot) match {
|
||||||
|
case mountable: RackMountable if mountable.onActivate(player, localHitVec.xCoord.toFloat, localHitVec.yCoord.toFloat) => return true // Activation handled by mountable.
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
@ -83,4 +95,10 @@ class Rack extends RedstoneAware with traits.SpecialBlock with traits.PowerAccep
|
|||||||
}
|
}
|
||||||
super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
|
super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def rotate(v: Vec3, t: Float): Vec3 = {
|
||||||
|
val cos = Math.cos(t)
|
||||||
|
val sin = Math.sin(t)
|
||||||
|
Vec3.createVectorHelper(v.xCoord * cos - v.zCoord * sin, v.yCoord, v.xCoord * sin + v.zCoord * cos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class TerminalServer(val rack: api.internal.Rack, val slot: Int) extends Environ
|
|||||||
|
|
||||||
override def getConnectableAt(index: Int): RackBusConnectable = null
|
override def getConnectableAt(index: Int): RackBusConnectable = null
|
||||||
|
|
||||||
override def onActivate(player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
override def onActivate(player: EntityPlayer, hitX: Float, hitY: Float): Boolean = {
|
||||||
val stack = player.getHeldItem
|
val stack = player.getHeldItem
|
||||||
if (api.Items.get(stack) == api.Items.get(Constants.ItemName.Terminal)) {
|
if (api.Items.get(stack) == api.Items.get(Constants.ItemName.Terminal)) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
|
@ -147,7 +147,7 @@ class DiskDriveMountable(val rack: api.internal.Rack, val slot: Int) extends pre
|
|||||||
|
|
||||||
override def getConnectableAt(index: Int): RackBusConnectable = null
|
override def getConnectableAt(index: Int): RackBusConnectable = null
|
||||||
|
|
||||||
override def onActivate(player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
override def onActivate(player: EntityPlayer, hitX: Float, hitY: Float): Boolean = {
|
||||||
if (player.isSneaking) {
|
if (player.isSneaking) {
|
||||||
val isDiskInDrive = getStackInSlot(0) != null
|
val isDiskInDrive = getStackInSlot(0) != null
|
||||||
val isHoldingDisk = isItemValidForSlot(0, player.getHeldItem)
|
val isHoldingDisk = isItemValidForSlot(0, player.getHeldItem)
|
||||||
|
@ -157,7 +157,7 @@ class Server(val rack: api.internal.Rack, val slot: Int) extends Environment wit
|
|||||||
case Some(busConnectable: RackBusConnectable) => busConnectable
|
case Some(busConnectable: RackBusConnectable) => busConnectable
|
||||||
}.apply(index)
|
}.apply(index)
|
||||||
|
|
||||||
override def onActivate(player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
override def onActivate(player: EntityPlayer, hitX: Float, hitY: Float): Boolean = {
|
||||||
if (!player.getEntityWorld.isRemote) {
|
if (!player.getEntityWorld.isRemote) {
|
||||||
if (player.isSneaking) {
|
if (player.isSneaking) {
|
||||||
if (!machine.isRunning && isUseableByPlayer(player)) {
|
if (!machine.isRunning && isUseableByPlayer(player)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user