-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'adapter-sides' of https://github.com/Vexatos/OpenComputers
- Loading branch information
Showing
7 changed files
with
122 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/scala/li/cil/oc/common/tileentity/traits/OpenSides.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package li.cil.oc.common.tileentity.traits | ||
|
||
import cpw.mods.fml.relauncher.{Side, SideOnly} | ||
import li.cil.oc.Settings | ||
import net.minecraft.nbt.NBTTagCompound | ||
import net.minecraftforge.common.util.ForgeDirection | ||
|
||
/** | ||
* @author Vexatos | ||
*/ | ||
trait OpenSides extends TileEntity { | ||
protected def SideCount = ForgeDirection.VALID_DIRECTIONS.length | ||
|
||
protected def defaultState: Boolean = false | ||
|
||
var openSides = Array.fill(SideCount)(defaultState) | ||
|
||
def compressSides = (ForgeDirection.VALID_DIRECTIONS, openSides).zipped.foldLeft(0)((acc, entry) => acc | (if (entry._2) entry._1.flag else 0)).toByte | ||
|
||
def uncompressSides(byte: Byte) = ForgeDirection.VALID_DIRECTIONS.map(d => (d.flag & byte) != 0) | ||
|
||
def isSideOpen(side: ForgeDirection) = side != ForgeDirection.UNKNOWN && openSides(side.ordinal()) | ||
|
||
def setSideOpen(side: ForgeDirection, value: Boolean): Unit = if (side != ForgeDirection.UNKNOWN && openSides(side.ordinal()) != value) { | ||
openSides(side.ordinal()) = value | ||
} | ||
|
||
override def readFromNBTForServer(nbt: NBTTagCompound) { | ||
super.readFromNBTForServer(nbt) | ||
openSides = uncompressSides(nbt.getByte(Settings.namespace + "openSides")) | ||
} | ||
|
||
override def writeToNBTForServer(nbt: NBTTagCompound) { | ||
super.writeToNBTForServer(nbt) | ||
nbt.setByte(Settings.namespace + "openSides", compressSides) | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
override def readFromNBTForClient(nbt: NBTTagCompound) { | ||
super.readFromNBTForClient(nbt) | ||
openSides = uncompressSides(nbt.getByte(Settings.namespace + "openSides")) | ||
} | ||
|
||
override def writeToNBTForClient(nbt: NBTTagCompound) { | ||
super.writeToNBTForClient(nbt) | ||
nbt.setByte(Settings.namespace + "openSides", compressSides) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters