diff --git a/build.properties b/build.properties index 982388f16..aeb92b702 100644 --- a/build.properties +++ b/build.properties @@ -1,5 +1,5 @@ minecraft.version=1.8.8 -forge.version=11.15.0.1612-1.8.8 +forge.version=11.15.0.1617-1.8.8 oc.version=1.5.20 oc.subversion=dev diff --git a/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java b/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java index 857c19a34..415a295ed 100644 --- a/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java +++ b/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java @@ -4,6 +4,7 @@ import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -27,11 +28,11 @@ public class TextureTabIconRenderer implements TabIconRenderer { GL11.glBindTexture(GL11.GL_TEXTURE_2D, Minecraft.getMinecraft().getTextureManager().getTexture(location).getGlTextureId()); final Tessellator t = Tessellator.getInstance(); final WorldRenderer r = t.getWorldRenderer(); - r.startDrawingQuads(); - r.addVertexWithUV(0, 16, 0, 0, 1); - r.addVertexWithUV(16, 16, 0, 1, 1); - r.addVertexWithUV(16, 0, 0, 1, 0); - r.addVertexWithUV(0, 0, 0, 0, 0); + r.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + r.pos(0, 16, 0).tex(0, 1).endVertex(); + r.pos(16, 16, 0).tex(1, 1).endVertex(); + r.pos(16, 0, 0).tex(1, 0).endVertex(); + r.pos(0, 0, 0).tex(0, 0).endVertex(); t.draw(); } } diff --git a/src/main/scala/li/cil/oc/client/CommandHandler.scala b/src/main/scala/li/cil/oc/client/CommandHandler.scala index c196c934e..79aa183ed 100644 --- a/src/main/scala/li/cil/oc/client/CommandHandler.scala +++ b/src/main/scala/li/cil/oc/client/CommandHandler.scala @@ -13,7 +13,7 @@ object CommandHandler { object SetClipboardCommand extends SimpleCommand("oc_setclipboard") { override def getCommandUsage(source: ICommandSender): String = name + " " - override def execute(source: ICommandSender, command: Array[String]): Unit = { + override def processCommand(source: ICommandSender, command: Array[String]): Unit = { if (source.getEntityWorld.isRemote && command != null && command.length > 0) { GuiScreen.setClipboardString(command(0)) } diff --git a/src/main/scala/li/cil/oc/client/PacketHandler.scala b/src/main/scala/li/cil/oc/client/PacketHandler.scala index 6a3fbff57..67697e95c 100644 --- a/src/main/scala/li/cil/oc/client/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/client/PacketHandler.scala @@ -32,8 +32,9 @@ import org.lwjgl.input.Keyboard object PacketHandler extends CommonPacketHandler { @SubscribeEvent - def onPacket(e: ClientCustomPacketEvent) = - onPacketData(e.packet.payload, Minecraft.getMinecraft.thePlayer) + def onPacket(e: ClientCustomPacketEvent) = { + onPacketData(e.manager.getNetHandler, e.packet.payload, Minecraft.getMinecraft.thePlayer) + } protected override def world(player: EntityPlayer, dimension: Int) = { val world = player.worldObj diff --git a/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala b/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala index 4df4b633b..8be8e89fb 100644 --- a/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala +++ b/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala @@ -28,18 +28,18 @@ abstract class CustomGuiContainer[C <: Container](val inventoryContainer: C) ext protected def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) // Pretty much Scalaified copy-pasta from base-class. - override def drawHoveringText(text: util.List[_], x: Int, y: Int, font: FontRenderer): Unit = { + override def drawHoveringText(text: util.List[String], x: Int, y: Int, font: FontRenderer): Unit = { copiedDrawHoveringText(text, x, y, font) } - protected def copiedDrawHoveringText(text: util.List[_], x: Int, y: Int, font: FontRenderer): Unit = { + protected def copiedDrawHoveringText(text: util.List[String], x: Int, y: Int, font: FontRenderer): Unit = { if (!text.isEmpty) { GlStateManager.disableRescaleNormal() RenderHelper.disableStandardItemLighting() GlStateManager.disableLighting() GlStateManager.disableDepth() - val textWidth = text.map(line => font.getStringWidth(line.asInstanceOf[String])).max + val textWidth = text.map(line => font.getStringWidth(line)).max var posX = x + 12 var posY = y - 12 diff --git a/src/main/scala/li/cil/oc/client/renderer/block/CableModel.scala b/src/main/scala/li/cil/oc/client/renderer/block/CableModel.scala index bf5e15a70..216260dc1 100644 --- a/src/main/scala/li/cil/oc/client/renderer/block/CableModel.scala +++ b/src/main/scala/li/cil/oc/client/renderer/block/CableModel.scala @@ -9,6 +9,7 @@ import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedWorld._ import net.minecraft.block.state.IBlockState import net.minecraft.client.renderer.block.model.BakedQuad +import net.minecraft.client.renderer.texture.TextureAtlasSprite import net.minecraft.item.EnumDyeColor import net.minecraft.item.ItemStack import net.minecraft.tileentity.TileEntity diff --git a/src/main/scala/li/cil/oc/client/renderer/block/SmartBlockModelBase.scala b/src/main/scala/li/cil/oc/client/renderer/block/SmartBlockModelBase.scala index 00e96308b..c46a48acd 100644 --- a/src/main/scala/li/cil/oc/client/renderer/block/SmartBlockModelBase.scala +++ b/src/main/scala/li/cil/oc/client/renderer/block/SmartBlockModelBase.scala @@ -22,9 +22,9 @@ trait SmartBlockModelBase extends ISmartBlockModel with ISmartItemModel { override def handleItemState(stack: ItemStack) = missingModel - override def getFaceQuads(side: EnumFacing): java.util.List[_] = Collections.emptyList() + override def getFaceQuads(side: EnumFacing): java.util.List[BakedQuad] = Collections.emptyList() - override def getGeneralQuads: java.util.List[_] = Collections.emptyList() + override def getGeneralQuads: java.util.List[BakedQuad] = Collections.emptyList() override def isAmbientOcclusion = true @@ -34,7 +34,7 @@ trait SmartBlockModelBase extends ISmartBlockModel with ISmartItemModel { // Note: we don't care about the actual texture here, we just need the block // texture atlas. So any of our textures we know is loaded into it will do. - override def getTexture = Textures.getSprite(Textures.Block.GenericTop) + override def getParticleTexture = Textures.getSprite(Textures.Block.GenericTop) override def getItemCameraTransforms = DefaultBlockCameraTransforms diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala index 18af64ef6..08203354a 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala @@ -39,6 +39,7 @@ object ScreenRenderer extends TileEntitySpecialRenderer[Screen] { override def renderTileEntityAt(screen: Screen, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") + this.screen = screen if (!screen.isOrigin) { return } diff --git a/src/main/scala/li/cil/oc/common/PacketHandler.scala b/src/main/scala/li/cil/oc/common/PacketHandler.scala index 6e8ba78c3..60c8662e1 100644 --- a/src/main/scala/li/cil/oc/common/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/common/PacketHandler.scala @@ -15,16 +15,30 @@ import li.cil.oc.util.ExtendedWorld._ import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.nbt.CompressedStreamTools +import net.minecraft.network.INetHandler import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.World +import net.minecraftforge.fml.common.FMLCommonHandler import scala.reflect.ClassTag import scala.reflect.classTag abstract class PacketHandler { /** Top level dispatcher based on packet type. */ - protected def onPacketData(data: ByteBuf, player: EntityPlayer) { + protected def onPacketData(handler: INetHandler, data: ByteBuf, player: EntityPlayer) { + val thread = FMLCommonHandler.instance.getWorldThread(handler) + if (thread.isCallingFromMinecraftThread) { + process(data, player) + } + else { + thread.addScheduledTask(new Runnable { + override def run(): Unit = process(data, player) + }) + } + } + + private def process(data: ByteBuf, player: EntityPlayer): Unit = { // Don't crash on badly formatted packets (may have been altered by a // malicious client, in which case we don't want to allow it to kill the // server like this). Just spam the log a bit... ;) diff --git a/src/main/scala/li/cil/oc/common/block/Cable.scala b/src/main/scala/li/cil/oc/common/block/Cable.scala index d8817f77d..1895f27b5 100644 --- a/src/main/scala/li/cil/oc/common/block/Cable.scala +++ b/src/main/scala/li/cil/oc/common/block/Cable.scala @@ -15,7 +15,7 @@ import li.cil.oc.api.network.SidedEnvironment import li.cil.oc.common.tileentity import li.cil.oc.integration.Mods import net.minecraft.block.Block -import net.minecraft.block.properties.IProperty +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.item.EnumDyeColor import net.minecraft.tileentity.TileEntity @@ -24,14 +24,12 @@ import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.IBlockAccess import net.minecraft.world.World +import net.minecraftforge.common.property.ExtendedBlockState import net.minecraftforge.common.property.IExtendedBlockState -import net.minecraftforge.common.property.IUnlistedProperty import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import scala.collection.mutable.ArrayBuffer - -class Cable extends SimpleBlock with traits.Extended { +class Cable extends SimpleBlock { // For Immibis Microblock support. val ImmibisMicroblocks_TransformableBlockMarker = null @@ -40,20 +38,15 @@ class Cable extends SimpleBlock with traits.Extended { // ----------------------------------------------------------------------- // - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) + override def createBlockState(): BlockState = new ExtendedBlockState(this, Array.empty, Array(property.PropertyTile.Tile)) - override protected def addExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = + override def getActualState(state: IBlockState, world: IBlockAccess, pos: BlockPos): IBlockState = (state, world.getTileEntity(pos)) match { case (extendedState: IExtendedBlockState, cable: tileentity.Cable) => - super.addExtendedState(extendedState.withProperty(property.PropertyTile.Tile, cable), world, pos) - case _ => None + extendedState.withProperty(property.PropertyTile.Tile, cable) + case _ => state } - override protected def createProperties(listed: ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]) { - super.createProperties(listed, unlisted) - unlisted += property.PropertyTile.Tile.asInstanceOf[IUnlistedProperty[_ <: Comparable[AnyRef]]] - } - // ----------------------------------------------------------------------- // override def isOpaqueCube = false diff --git a/src/main/scala/li/cil/oc/common/block/Case.scala b/src/main/scala/li/cil/oc/common/block/Case.scala index 7b90d6104..9cbddaefb 100644 --- a/src/main/scala/li/cil/oc/common/block/Case.scala +++ b/src/main/scala/li/cil/oc/common/block/Case.scala @@ -4,44 +4,27 @@ import java.util import li.cil.oc.Settings import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.tileentity import li.cil.oc.util.Color import li.cil.oc.util.Rarity import li.cil.oc.util.Tooltip -import net.minecraft.block.properties.IProperty -import net.minecraft.block.properties.PropertyBool +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.World -import net.minecraftforge.common.property.IUnlistedProperty import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import scala.collection.mutable +class Case(val tier: Int) extends RedstoneAware with traits.PowerAcceptor with traits.StateAware with traits.GUI { + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Facing, property.PropertyRunning.Running) -object Case { - final val Running = PropertyBool.create("running") -} + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta >> 1)) -class Case(val tier: Int) extends RedstoneAware with traits.PowerAcceptor with traits.Rotatable with traits.StateAware with traits.GUI { - def getRunning(state: IBlockState) = - if (state.getBlock == this) - state.getValue(Case.Running).asInstanceOf[Boolean] - else - false - - def withRunning(state: IBlockState, running: Boolean) = state. - withProperty(Case.Running, boolean2Boolean(running)) - - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) - - override protected def createProperties(listed: mutable.ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: mutable.ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]): Unit = { - super.createProperties(listed, unlisted) - listed += Case.Running.asInstanceOf[IProperty[_ <: Comparable[AnyRef]]] - } + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex << 1 | (if (state.getValue(property.PropertyRunning.Running)) 1 else 0) // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala b/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala index bd773e942..6e840ec0c 100644 --- a/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala +++ b/src/main/scala/li/cil/oc/common/block/ChameliumBlock.scala @@ -25,7 +25,7 @@ class ChameliumBlock extends SimpleBlock(Material.rock) { getDefaultState.withProperty(ChameliumBlock.Color, EnumDyeColor.byDyeDamage(meta)) override def getMetaFromState(state: IBlockState): Int = - state.getValue(ChameliumBlock.Color).asInstanceOf[EnumDyeColor].getDyeDamage + state.getValue(ChameliumBlock.Color).getDyeDamage override def createBlockState(): BlockState = new BlockState(this, ChameliumBlock.Color) } diff --git a/src/main/scala/li/cil/oc/common/block/Charger.scala b/src/main/scala/li/cil/oc/common/block/Charger.scala index 1b21d92f1..4ef0ad1fe 100644 --- a/src/main/scala/li/cil/oc/common/block/Charger.scala +++ b/src/main/scala/li/cil/oc/common/block/Charger.scala @@ -2,10 +2,12 @@ package li.cil.oc.common.block import li.cil.oc.Settings import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.tileentity import li.cil.oc.integration.util.Wrench import li.cil.oc.server.PacketSender import net.minecraft.block.Block +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.BlockPos @@ -13,8 +15,14 @@ import net.minecraft.util.EnumFacing import net.minecraft.world.IBlockAccess import net.minecraft.world.World -class Charger extends RedstoneAware with traits.PowerAcceptor with traits.Rotatable with traits.StateAware with traits.GUI { - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) +class Charger extends RedstoneAware with traits.PowerAcceptor with traits.StateAware with traits.GUI { + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Facing) + + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta)) + + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex + + // ----------------------------------------------------------------------- // override def energyThroughput = Settings.get.chargerRate diff --git a/src/main/scala/li/cil/oc/common/block/DiskDrive.scala b/src/main/scala/li/cil/oc/common/block/DiskDrive.scala index 031dd181f..f7a0be367 100644 --- a/src/main/scala/li/cil/oc/common/block/DiskDrive.scala +++ b/src/main/scala/li/cil/oc/common/block/DiskDrive.scala @@ -1,9 +1,11 @@ package li.cil.oc.common.block import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.tileentity import li.cil.oc.integration.Mods import li.cil.oc.util.Tooltip +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack @@ -11,8 +13,14 @@ import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.World -class DiskDrive extends SimpleBlock with traits.Rotatable with traits.GUI { - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) +class DiskDrive extends SimpleBlock with traits.GUI { + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Facing) + + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta)) + + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex + + // ----------------------------------------------------------------------- // override protected def tooltipTail(metadata: Int, stack: ItemStack, player: EntityPlayer, tooltip: java.util.List[String], advanced: Boolean) { super.tooltipTail(metadata, stack, player, tooltip, advanced) diff --git a/src/main/scala/li/cil/oc/common/block/Keyboard.scala b/src/main/scala/li/cil/oc/common/block/Keyboard.scala index 21c022a34..7601e5d72 100644 --- a/src/main/scala/li/cil/oc/common/block/Keyboard.scala +++ b/src/main/scala/li/cil/oc/common/block/Keyboard.scala @@ -4,12 +4,14 @@ import java.util.Random import li.cil.oc.Constants import li.cil.oc.api +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.tileentity import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedEnumFacing._ import li.cil.oc.util.InventoryUtils import net.minecraft.block.Block import net.minecraft.block.material.Material +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.AxisAlignedBB @@ -19,12 +21,18 @@ import net.minecraft.world.IBlockAccess import net.minecraft.world.World import org.lwjgl.opengl.GL11 -class Keyboard extends SimpleBlock(Material.rock) with traits.OmniRotatable { +class Keyboard extends SimpleBlock(Material.rock) { setLightOpacity(0) // For Immibis Microblock support. val ImmibisMicroblocks_TransformableBlockMarker = null + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Pitch, PropertyRotatable.Yaw) + + override def getMetaFromState(state: IBlockState): Int = (state.getValue(PropertyRotatable.Pitch).ordinal() << 8) | state.getValue(PropertyRotatable.Yaw).getHorizontalIndex + + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Pitch, EnumFacing.getFront(meta >> 8)).withProperty(PropertyRotatable.Yaw, EnumFacing.getHorizontal(meta & 0xF)) + // ----------------------------------------------------------------------- // override def isOpaqueCube = false @@ -35,8 +43,6 @@ class Keyboard extends SimpleBlock(Material.rock) with traits.OmniRotatable { // ----------------------------------------------------------------------- // - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) - override def shouldSideBeRendered(world: IBlockAccess, pos: BlockPos, side: EnumFacing) = true override def setBlockBoundsForItemRender(metadata: Int) = setBlockBounds(EnumFacing.NORTH, EnumFacing.WEST) diff --git a/src/main/scala/li/cil/oc/common/block/Microcontroller.scala b/src/main/scala/li/cil/oc/common/block/Microcontroller.scala index 36d8c3ad4..1b0b46e16 100644 --- a/src/main/scala/li/cil/oc/common/block/Microcontroller.scala +++ b/src/main/scala/li/cil/oc/common/block/Microcontroller.scala @@ -7,6 +7,7 @@ import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.client.KeyBindings import li.cil.oc.common.Tier +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.item.data.MicrocontrollerData import li.cil.oc.common.tileentity import li.cil.oc.integration.util.NEI @@ -14,6 +15,7 @@ import li.cil.oc.integration.util.Wrench import li.cil.oc.util.InventoryUtils import li.cil.oc.util.Rarity import net.minecraft.block.Block +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.player.EntityPlayer @@ -25,11 +27,15 @@ import net.minecraft.world.World import scala.reflect.ClassTag -class Microcontroller(protected implicit val tileTag: ClassTag[tileentity.Microcontroller]) extends RedstoneAware with traits.PowerAcceptor with traits.Rotatable with traits.StateAware with traits.CustomDrops[tileentity.Microcontroller] { +class Microcontroller(protected implicit val tileTag: ClassTag[tileentity.Microcontroller]) extends RedstoneAware with traits.PowerAcceptor with traits.StateAware with traits.CustomDrops[tileentity.Microcontroller] { setCreativeTab(null) NEI.hide(this) - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Facing) + + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta)) + + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/block/NetSplitter.scala b/src/main/scala/li/cil/oc/common/block/NetSplitter.scala index 4b75d97d5..48e334db1 100644 --- a/src/main/scala/li/cil/oc/common/block/NetSplitter.scala +++ b/src/main/scala/li/cil/oc/common/block/NetSplitter.scala @@ -1,34 +1,28 @@ package li.cil.oc.common.block +import li.cil.oc.common.block.property.PropertyTile import li.cil.oc.common.tileentity import li.cil.oc.integration.util.Wrench -import net.minecraft.block.properties.IProperty +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.IBlockAccess import net.minecraft.world.World +import net.minecraftforge.common.property.ExtendedBlockState import net.minecraftforge.common.property.IExtendedBlockState -import net.minecraftforge.common.property.IUnlistedProperty -import scala.collection.mutable.ArrayBuffer +class NetSplitter extends RedstoneAware { + override def createBlockState(): BlockState = new ExtendedBlockState(this, Array.empty, Array(PropertyTile.Tile)) -class NetSplitter extends RedstoneAware with traits.Extended { - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) - - override protected def addExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = + override def getActualState(state: IBlockState, world: IBlockAccess, pos: BlockPos): IBlockState = (state, world.getTileEntity(pos)) match { case (extendedState: IExtendedBlockState, t: tileentity.NetSplitter) => - super.addExtendedState(extendedState.withProperty(property.PropertyTile.Tile, t), world, pos) - case _ => None + extendedState.withProperty(property.PropertyTile.Tile, t) + case _ => state } - override protected def createProperties(listed: ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]) { - super.createProperties(listed, unlisted) - unlisted += property.PropertyTile.Tile.asInstanceOf[IUnlistedProperty[_ <: Comparable[AnyRef]]] - } - // ----------------------------------------------------------------------- // override def isSideSolid(world: IBlockAccess, pos: BlockPos, side: EnumFacing): Boolean = false diff --git a/src/main/scala/li/cil/oc/common/block/Print.scala b/src/main/scala/li/cil/oc/common/block/Print.scala index 2ff9f9a15..7bb6734b5 100644 --- a/src/main/scala/li/cil/oc/common/block/Print.scala +++ b/src/main/scala/li/cil/oc/common/block/Print.scala @@ -6,13 +6,14 @@ import java.util.Random import com.google.common.base.Strings import li.cil.oc.Localization import li.cil.oc.Settings +import li.cil.oc.common.block.property.PropertyTile import li.cil.oc.common.item.data.PrintData import li.cil.oc.common.tileentity import li.cil.oc.integration.util.NEI import li.cil.oc.util.ExtendedAABB import li.cil.oc.util.ExtendedAABB._ import li.cil.oc.util.InventoryUtils -import net.minecraft.block.properties.IProperty +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.Entity import net.minecraft.entity.EntityLiving.SpawnPlacementType @@ -27,16 +28,15 @@ import net.minecraft.util.MovingObjectPosition import net.minecraft.util.Vec3 import net.minecraft.world.IBlockAccess import net.minecraft.world.World +import net.minecraftforge.common.property.ExtendedBlockState import net.minecraftforge.common.property.IExtendedBlockState -import net.minecraftforge.common.property.IUnlistedProperty import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly import scala.collection.convert.WrapAsJava._ -import scala.collection.mutable.ArrayBuffer import scala.reflect.ClassTag -class Print(protected implicit val tileTag: ClassTag[tileentity.Print]) extends RedstoneAware with traits.CustomDrops[tileentity.Print] with traits.Extended { +class Print(protected implicit val tileTag: ClassTag[tileentity.Print]) extends RedstoneAware with traits.CustomDrops[tileentity.Print] { setLightOpacity(1) setHardness(1) setCreativeTab(null) @@ -44,20 +44,15 @@ class Print(protected implicit val tileTag: ClassTag[tileentity.Print]) extends // ----------------------------------------------------------------------- // - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) + override def createBlockState(): BlockState = new ExtendedBlockState(this, Array.empty, Array(PropertyTile.Tile)) - override protected def addExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = + override def getActualState(state: IBlockState, world: IBlockAccess, pos: BlockPos): IBlockState = (state, world.getTileEntity(pos)) match { case (extendedState: IExtendedBlockState, t: tileentity.Print) => - super.addExtendedState(extendedState.withProperty(property.PropertyTile.Tile, t), world, pos) - case _ => None + extendedState.withProperty(property.PropertyTile.Tile, t) + case _ => state } - override protected def createProperties(listed: ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]) { - super.createProperties(listed, unlisted) - unlisted += property.PropertyTile.Tile.asInstanceOf[IUnlistedProperty[_ <: Comparable[AnyRef]]] - } - // ----------------------------------------------------------------------- // override def canRenderInLayer(layer: EnumWorldBlockLayer): Boolean = layer == EnumWorldBlockLayer.CUTOUT_MIPPED diff --git a/src/main/scala/li/cil/oc/common/block/Raid.scala b/src/main/scala/li/cil/oc/common/block/Raid.scala index 837389a5c..cb9d137d3 100644 --- a/src/main/scala/li/cil/oc/common/block/Raid.scala +++ b/src/main/scala/li/cil/oc/common/block/Raid.scala @@ -4,22 +4,27 @@ import java.util import li.cil.oc.client.KeyBindings import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.item.data.RaidData import li.cil.oc.common.tileentity import net.minecraft.block.Block +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.util.BlockPos +import net.minecraft.util.EnumFacing import net.minecraft.world.World import scala.reflect.ClassTag -class Raid(protected implicit val tileTag: ClassTag[tileentity.Raid]) extends SimpleBlock with traits.Rotatable with traits.GUI with traits.CustomDrops[tileentity.Raid] { - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) +class Raid(protected implicit val tileTag: ClassTag[tileentity.Raid]) extends SimpleBlock with traits.GUI with traits.CustomDrops[tileentity.Raid] { + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Facing) - override def hasTileEntity(state: IBlockState) = true + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta)) + + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex override protected def tooltipTail(metadata: Int, stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) { super.tooltipTail(metadata, stack, player, tooltip, advanced) @@ -35,6 +40,8 @@ class Raid(protected implicit val tileTag: ClassTag[tileentity.Raid]) extends Si override def guiType = GuiType.Raid + override def hasTileEntity(state: IBlockState) = true + override def createNewTileEntity(world: World, metadata: Int) = new tileentity.Raid() // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/block/Screen.scala b/src/main/scala/li/cil/oc/common/block/Screen.scala index d819d5af4..7b7b17fc7 100644 --- a/src/main/scala/li/cil/oc/common/block/Screen.scala +++ b/src/main/scala/li/cil/oc/common/block/Screen.scala @@ -7,6 +7,8 @@ import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable +import li.cil.oc.common.block.property.PropertyTile import li.cil.oc.common.tileentity import li.cil.oc.integration.coloredlights.ModColoredLights import li.cil.oc.integration.util.Wrench @@ -14,7 +16,7 @@ import li.cil.oc.util.Color import li.cil.oc.util.PackedColor import li.cil.oc.util.Rarity import li.cil.oc.util.Tooltip -import net.minecraft.block.properties.IProperty +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.client.Minecraft import net.minecraft.entity.Entity @@ -26,31 +28,31 @@ import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.IBlockAccess import net.minecraft.world.World +import net.minecraftforge.common.property.ExtendedBlockState import net.minecraftforge.common.property.IExtendedBlockState -import net.minecraftforge.common.property.IUnlistedProperty import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import scala.collection.mutable.ArrayBuffer - -class Screen(val tier: Int) extends RedstoneAware with traits.OmniRotatable { +class Screen(val tier: Int) extends RedstoneAware { ModColoredLights.setLightLevel(this, 5, 5, 5) - override def isSideSolid(world: IBlockAccess, pos: BlockPos, side: EnumFacing) = toLocal(world, pos, side) != EnumFacing.SOUTH + override def createBlockState(): BlockState = new ExtendedBlockState(this, Array(PropertyRotatable.Pitch, PropertyRotatable.Yaw), Array(PropertyTile.Tile)) - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) + override def getMetaFromState(state: IBlockState): Int = (state.getValue(PropertyRotatable.Pitch).ordinal() << 8) | state.getValue(PropertyRotatable.Yaw).getHorizontalIndex - override protected def addExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Pitch, EnumFacing.getFront(meta >> 8)).withProperty(PropertyRotatable.Yaw, EnumFacing.getHorizontal(meta & 0xF)) + + override def getActualState(state: IBlockState, world: IBlockAccess, pos: BlockPos): IBlockState = (state, world.getTileEntity(pos)) match { - case (extendedState: IExtendedBlockState, tile: tileentity.traits.TileEntity) => - super.addExtendedState(extendedState.withProperty(property.PropertyTile.Tile, tile), world, pos) - case _ => None + case (extendedState: IExtendedBlockState, tile: tileentity.Screen) => + extendedState. + withProperty(property.PropertyTile.Tile, tile). + withProperty(PropertyRotatable.Pitch, tile.pitch). + withProperty(PropertyRotatable.Yaw, tile.yaw) + case _ => state } - override protected def createProperties(listed: ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]) { - super.createProperties(listed, unlisted) - unlisted += property.PropertyTile.Tile.asInstanceOf[IUnlistedProperty[_ <: Comparable[AnyRef]]] - } + override def isSideSolid(world: IBlockAccess, pos: BlockPos, side: EnumFacing) = toLocal(world, pos, side) != EnumFacing.SOUTH // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/block/ServerRack.scala b/src/main/scala/li/cil/oc/common/block/ServerRack.scala index 3f23e2374..d31def9de 100644 --- a/src/main/scala/li/cil/oc/common/block/ServerRack.scala +++ b/src/main/scala/li/cil/oc/common/block/ServerRack.scala @@ -2,21 +2,34 @@ package li.cil.oc.common.block import li.cil.oc.Settings import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.tileentity -import net.minecraft.block.properties.IProperty +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.IBlockAccess import net.minecraft.world.World +import net.minecraftforge.common.property.ExtendedBlockState import net.minecraftforge.common.property.IExtendedBlockState -import net.minecraftforge.common.property.IUnlistedProperty import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -import scala.collection.mutable.ArrayBuffer +class ServerRack extends RedstoneAware with traits.PowerAcceptor with traits.StateAware with traits.GUI { + override def createBlockState(): BlockState = new ExtendedBlockState(this, Array(PropertyRotatable.Facing), Array(property.PropertyTile.Tile)) + + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta)) + + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex + + override def getActualState(state: IBlockState, world: IBlockAccess, pos: BlockPos): IBlockState = { + ((state, world.getTileEntity(pos)) match { + case (extendedState: IExtendedBlockState, tile: tileentity.traits.TileEntity) => + extendedState.withProperty(property.PropertyTile.Tile, tile) + case _ => state + }).withProperty(PropertyRotatable.Facing, getFacing(world, pos)) + } -class ServerRack extends RedstoneAware with traits.PowerAcceptor with traits.Rotatable with traits.StateAware with traits.GUI { @SideOnly(Side.CLIENT) override def getMixedBrightnessForBlock(world: IBlockAccess, pos: BlockPos) = { if (pos.getY >= 0 && pos.getY < 256) world.getTileEntity(pos) match { @@ -39,20 +52,6 @@ class ServerRack extends RedstoneAware with traits.PowerAcceptor with traits.Rot override def isSideSolid(world: IBlockAccess, pos: BlockPos, side: EnumFacing) = toLocal(world, pos, side) != EnumFacing.SOUTH - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) - - override protected def addExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = - (state, world.getTileEntity(pos)) match { - case (extendedState: IExtendedBlockState, tile: tileentity.traits.TileEntity) => - super.addExtendedState(extendedState.withProperty(property.PropertyTile.Tile, tile), world, pos) - case _ => None - } - - override protected def createProperties(listed: ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]) { - super.createProperties(listed, unlisted) - unlisted += property.PropertyTile.Tile.asInstanceOf[IUnlistedProperty[_ <: Comparable[AnyRef]]] - } - // ----------------------------------------------------------------------- // override def energyThroughput = Settings.get.serverRackRate diff --git a/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala b/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala index f03624d52..1c1adf5d7 100644 --- a/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala +++ b/src/main/scala/li/cil/oc/common/block/SimpleBlock.scala @@ -164,6 +164,8 @@ abstract class SimpleBlock(material: Material = Material.iron) extends BlockCont override def canHarvestBlock(world: IBlockAccess, pos: BlockPos, player: EntityPlayer) = true + override def getHarvestTool(state: IBlockState): String = null + override def canBeReplacedByLeaves(world: IBlockAccess, pos: BlockPos) = false override def canCreatureSpawn(world: IBlockAccess, pos: BlockPos, `type`: SpawnPlacementType) = false diff --git a/src/main/scala/li/cil/oc/common/block/Waypoint.scala b/src/main/scala/li/cil/oc/common/block/Waypoint.scala index 832d099c3..2304ecbf7 100644 --- a/src/main/scala/li/cil/oc/common/block/Waypoint.scala +++ b/src/main/scala/li/cil/oc/common/block/Waypoint.scala @@ -2,15 +2,23 @@ package li.cil.oc.common.block import li.cil.oc.OpenComputers import li.cil.oc.common.GuiType +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.common.tileentity +import net.minecraft.block.state.BlockState import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.World -class Waypoint extends RedstoneAware with traits.Rotatable { - override protected def setDefaultExtendedState(state: IBlockState) = setDefaultState(state) +class Waypoint extends RedstoneAware { + override def createBlockState(): BlockState = new BlockState(this, PropertyRotatable.Facing) + + override def getStateFromMeta(meta: Int): IBlockState = getDefaultState.withProperty(PropertyRotatable.Facing, EnumFacing.getHorizontal(meta)) + + override def getMetaFromState(state: IBlockState): Int = state.getValue(PropertyRotatable.Facing).getHorizontalIndex + + // ----------------------------------------------------------------------- // override def createNewTileEntity(world: World, metadata: Int) = new tileentity.Waypoint() diff --git a/src/main/scala/li/cil/oc/common/block/property/PropertyRotatable.scala b/src/main/scala/li/cil/oc/common/block/property/PropertyRotatable.scala new file mode 100644 index 000000000..930e337e4 --- /dev/null +++ b/src/main/scala/li/cil/oc/common/block/property/PropertyRotatable.scala @@ -0,0 +1,14 @@ +package li.cil.oc.common.block.property + +import com.google.common.base.Predicate +import com.google.common.base.Predicates +import net.minecraft.block.properties.PropertyDirection +import net.minecraft.util.EnumFacing + +import scala.collection.convert.WrapAsJava._ + +object PropertyRotatable { + final val Facing = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL.asInstanceOf[Predicate[EnumFacing]]) + final val Pitch = PropertyDirection.create("pitch", Predicates.in(Set(EnumFacing.DOWN, EnumFacing.UP, EnumFacing.NORTH))) + final val Yaw = PropertyDirection.create("yaw", EnumFacing.Plane.HORIZONTAL.asInstanceOf[Predicate[EnumFacing]]) +} diff --git a/src/main/scala/li/cil/oc/common/block/property/PropertyRunning.scala b/src/main/scala/li/cil/oc/common/block/property/PropertyRunning.scala new file mode 100644 index 000000000..f9ad0a7d2 --- /dev/null +++ b/src/main/scala/li/cil/oc/common/block/property/PropertyRunning.scala @@ -0,0 +1,7 @@ +package li.cil.oc.common.block.property + +import net.minecraft.block.properties.PropertyBool + +object PropertyRunning { + final val Running = PropertyBool.create("running") +} diff --git a/src/main/scala/li/cil/oc/common/block/traits/Extended.scala b/src/main/scala/li/cil/oc/common/block/traits/Extended.scala deleted file mode 100644 index 8cc984c60..000000000 --- a/src/main/scala/li/cil/oc/common/block/traits/Extended.scala +++ /dev/null @@ -1,124 +0,0 @@ -package li.cil.oc.common.block.traits - -import net.minecraft.block.Block -import net.minecraft.block.properties._ -import net.minecraft.block.state.IBlockState -import net.minecraft.util.BlockPos -import net.minecraft.world.IBlockAccess -import net.minecraftforge.common.property.ExtendedBlockState -import net.minecraftforge.common.property.IExtendedBlockState -import net.minecraftforge.common.property.IUnlistedProperty - -import scala.collection.convert.WrapAsScala._ -import scala.collection.mutable - -// Utility trait for blocks that use properties (e.g. for rotation). -// Provides automatic conversion to and from metadata and takes care of generic -// setup of stateful blocks with listed and unlisted properties. -trait Extended extends Block { - // Keep track of our properties, used for automatic metadata conversion. - private lazy val (listedProperties, unlistedProperties) = { - val listed = mutable.ArrayBuffer.empty[IProperty[_ <: Comparable[AnyRef]]] - val unlisted = mutable.ArrayBuffer.empty[IUnlistedProperty[_ <: Comparable[AnyRef]]] - createProperties(listed, unlisted) - (listed.toArray, unlisted.toArray) - } - - // Some metadata one the properties we cache for performance. - private lazy val propertyData: Map[IProperty[_ <: Comparable[AnyRef]], (Int, Array[_ <: Comparable[AnyRef]])] = - listedProperties.map(property => (property, (propertySize(property), property.getAllowedValues.toArray.map(_.asInstanceOf[Comparable[AnyRef]]).sortWith((a, b) => a.compareTo(b.asInstanceOf[AnyRef]) < 0)))).toMap - - // Check if property<->meta conversions work as expected. - // performSelfTest() - - // Gnaah, implementation limitations :-/ Can't access protected methods from - // traits, so we require subclasses to implement this methods which simply - // forwards to setDefaultState... - protected def setDefaultExtendedState(state: IBlockState): Unit - - setDefaultExtendedState(getBlockState.getBaseState) - - override def createBlockState() = { - new ExtendedBlockState(this, listedProperties.map(_.asInstanceOf[IProperty[_]]), unlistedProperties.map(_.asInstanceOf[IUnlistedProperty[_]])) - } - - // We basically store state information as a packed struct in the metadata - // bits. For each property we determine the number of bits required to store - // it (using the number of allowed values) and shift per property. - override def getMetaFromState(state: IBlockState): Int = { - var meta = 0 - for (property <- listedProperties) { - val (bits, values) = propertyData(property) - if (bits > 0) { - val value = state.getValue(property.asInstanceOf[IProperty[_]]) - meta = (meta << bits) | values.indexOf(value) - } - } - meta - } - - override def getStateFromMeta(meta: Int): IBlockState = { - var currentMeta = meta - var state = getDefaultState - // When unpacking we work from back to front, so iterate backwards. - for (property <- listedProperties.reverseIterator) { - val (bits, values) = propertyData(property) - if (bits > 0) { - val value = currentMeta & (0xFFFF >>> (16 - bits)) - state = state.withProperty(property.asInstanceOf[IProperty[_]], values(value).asInstanceOf[Comparable[AnyRef]]) - currentMeta = currentMeta >>> bits - } - } - state - } - - // Delegates to subclasses to accumulate state information. - override def getExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = - addExtendedState(state.asInstanceOf[IExtendedBlockState], world, pos). - getOrElse(super.getExtendedState(state, world, pos)) - - // Overridden in subclasses such that each subclass returns - // state.withProperty for each of their properties, then calls - // the parent with that modified. Call chain eventually returns - // fully built state, or None if one fails. - protected def addExtendedState(state: IBlockState, world: IBlockAccess, pos: BlockPos): Option[IBlockState] = Some(state) - - // Overridden in subclasses to accumulate properties used by this block type, - // result is stored (this is only called once) and used for state generation - // and metadata computation. - protected def createProperties(listed: mutable.ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: mutable.ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]): Unit = {} - - // Called during construction to ensure all our states map properly to - // metadata and back, to avoid unpleasant surprises during runtime. - private def performSelfTest(): Unit = { - val metas = mutable.Set.empty[Int] - getBlockState.getValidStates.collect { - case state: IBlockState => - val meta = getMetaFromState(state) - if ((meta & 0xF) != meta) { - throw new IllegalArgumentException("Invalid block definition, meta data out of bounds (uses more than 4 bits).") - } - if (metas.contains(meta)) { - throw new IllegalArgumentException("Invalid block definition, duplicate metadata for different block states.") - } - metas += meta - val stateFromMeta = getStateFromMeta(meta & 0xF) - if (state.hashCode() != stateFromMeta.hashCode()) { - throw new IllegalArgumentException("Invalid block definition, state from meta does not match state meta was from.") - } - } - } - - // Computes number of bits required to store a property. Uses the naive and - // slow but readable and understandable approach because it is only called - // once per property during construction anyway. - private def propertySize(property: IProperty[_]) = { - var maxIndex = property.getAllowedValues.size - 1 - var bits = 0 - while (maxIndex > 0) { - bits += 1 - maxIndex >>= 1 - } - bits - } -} diff --git a/src/main/scala/li/cil/oc/common/block/traits/OmniRotatable.scala b/src/main/scala/li/cil/oc/common/block/traits/OmniRotatable.scala deleted file mode 100644 index 46cbef5fe..000000000 --- a/src/main/scala/li/cil/oc/common/block/traits/OmniRotatable.scala +++ /dev/null @@ -1,45 +0,0 @@ -package li.cil.oc.common.block.traits - -import com.google.common.base.Predicate -import com.google.common.base.Predicates -import net.minecraft.block.Block -import net.minecraft.block.properties.IProperty -import net.minecraft.block.properties.PropertyDirection -import net.minecraft.block.state.IBlockState -import net.minecraft.util.EnumFacing -import net.minecraftforge.common.property.IUnlistedProperty - -import scala.collection.convert.WrapAsJava._ -import scala.collection.mutable - -// Provides 2-axis rotation for blocks (pitch and yaw) using metadata to store the rotation. -trait OmniRotatable extends Block with Extended { - def getPitch(state: IBlockState) = - if (state.getBlock == this) - state.getValue(OmniRotatable.Pitch) - else - EnumFacing.NORTH - - def getYaw(state: IBlockState) = - if (state.getBlock == this) - state.getValue(OmniRotatable.Yaw) - else - EnumFacing.SOUTH - - def withPitchAndYaw(state: IBlockState, pitch: EnumFacing, yaw: EnumFacing) = - (if (state.getBlock == this) state else getDefaultState). - withProperty(OmniRotatable.Pitch, pitch). - withProperty(OmniRotatable.Yaw, yaw) - - - override protected def createProperties(listed: mutable.ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: mutable.ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]): Unit = { - super.createProperties(listed, unlisted) - listed += OmniRotatable.Pitch.asInstanceOf[IProperty[_ <: Comparable[AnyRef]]] - listed += OmniRotatable.Yaw.asInstanceOf[IProperty[_ <: Comparable[AnyRef]]] - } -} - -object OmniRotatable { - final val Pitch = PropertyDirection.create("pitch", Predicates.in(Set(EnumFacing.DOWN, EnumFacing.UP, EnumFacing.NORTH))) - final val Yaw = PropertyDirection.create("yaw", EnumFacing.Plane.HORIZONTAL.asInstanceOf[Predicate[EnumFacing]]) -} diff --git a/src/main/scala/li/cil/oc/common/block/traits/Rotatable.scala b/src/main/scala/li/cil/oc/common/block/traits/Rotatable.scala deleted file mode 100644 index 4e43ccae3..000000000 --- a/src/main/scala/li/cil/oc/common/block/traits/Rotatable.scala +++ /dev/null @@ -1,33 +0,0 @@ -package li.cil.oc.common.block.traits - -import com.google.common.base.Predicate -import net.minecraft.block.Block -import net.minecraft.block.properties.IProperty -import net.minecraft.block.properties.PropertyDirection -import net.minecraft.block.state.IBlockState -import net.minecraft.util.EnumFacing -import net.minecraftforge.common.property.IUnlistedProperty - -import scala.collection.mutable - -// Provides 4-way rotation for blocks using metadata to store the rotation. -trait Rotatable extends Block with Extended { - def getFacing(state: IBlockState) = - if (state.getBlock == this) - state.getValue(Rotatable.Facing) - else - EnumFacing.SOUTH - - def withFacing(state: IBlockState, facing: EnumFacing) = - (if (state.getBlock == this) state else getDefaultState). - withProperty(Rotatable.Facing, facing) - - override protected def createProperties(listed: mutable.ArrayBuffer[IProperty[_ <: Comparable[AnyRef]]], unlisted: mutable.ArrayBuffer[IUnlistedProperty[_ <: Comparable[AnyRef]]]): Unit = { - super.createProperties(listed, unlisted) - listed += Rotatable.Facing.asInstanceOf[IProperty[_ <: Comparable[AnyRef]]] - } -} - -object Rotatable { - final val Facing = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL.asInstanceOf[Predicate[EnumFacing]]) -} diff --git a/src/main/scala/li/cil/oc/common/entity/Drone.scala b/src/main/scala/li/cil/oc/common/entity/Drone.scala index 9f5e5c316..1651d26f2 100644 --- a/src/main/scala/li/cil/oc/common/entity/Drone.scala +++ b/src/main/scala/li/cil/oc/common/entity/Drone.scala @@ -325,7 +325,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern def lightColor_=(value: Int) = dataWatcher.updateObject(15, Int.box(value)) @SideOnly(Side.CLIENT) - override def func_180426_a(x: Double, y: Double, z: Double, yaw: Float, pitch: Float, data: Int, unused: Boolean) { + override def setPositionAndRotation2(x: Double, y: Double, z: Double, yaw: Float, pitch: Float, posRotationIncrements: Int, p_180426_10_ : Boolean): Unit = { // Only set exact position if we're too far away from the server's // position, otherwise keep interpolating. This removes jitter and // is good enough for drones. diff --git a/src/main/scala/li/cil/oc/common/init/Items.scala b/src/main/scala/li/cil/oc/common/init/Items.scala index 81c668b34..8d536de8e 100644 --- a/src/main/scala/li/cil/oc/common/init/Items.scala +++ b/src/main/scala/li/cil/oc/common/init/Items.scala @@ -526,9 +526,9 @@ object Items extends ItemAPI { Items.createChargedHoverBoots() ) ++ Loot.disksForClient ++ registeredItems - override def getSubItems(item: Item, tab: CreativeTabs, list: util.List[_]): Unit = { + override def getSubItems(item: Item, tab: CreativeTabs, list: util.List[ItemStack]): Unit = { super.getSubItems(item, tab, list) - configuredItems.foreach(Items.add(list, _)) + configuredItems.foreach(list.add) } }, "misc") @@ -551,7 +551,4 @@ object Items extends ItemAPI { GameRegistry.registerItem(item, name) item } - - // Workaround for MC's untyped lists... - private final def add[T](list: java.util.List[T], value: Any) = list.add(value.asInstanceOf[T]) } diff --git a/src/main/scala/li/cil/oc/common/item/Delegator.scala b/src/main/scala/li/cil/oc/common/item/Delegator.scala index e0bd26837..a68298c36 100644 --- a/src/main/scala/li/cil/oc/common/item/Delegator.scala +++ b/src/main/scala/li/cil/oc/common/item/Delegator.scala @@ -67,13 +67,12 @@ class Delegator extends Item with driver.item.UpgradeRenderer with Chargeable { case _ => None } - override def getSubItems(item: Item, tab: CreativeTabs, list: util.List[_]) { + override def getSubItems(item: Item, tab: CreativeTabs, list: util.List[ItemStack]) { // Workaround for MC's untyped lists... - def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) subItems.indices.filter(subItems(_).showInItemList). map(subItems(_).createItemStack()). sortBy(_.getUnlocalizedName). - foreach(add(list, _)) + foreach(list.add) } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/item/traits/SimpleItem.scala b/src/main/scala/li/cil/oc/common/item/traits/SimpleItem.scala index 9a83c3d46..b1f257b60 100644 --- a/src/main/scala/li/cil/oc/common/item/traits/SimpleItem.scala +++ b/src/main/scala/li/cil/oc/common/item/traits/SimpleItem.scala @@ -38,16 +38,15 @@ trait SimpleItem extends Item { } @SideOnly(Side.CLIENT) - override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[_], advanced: Boolean): Unit = { - val tt = tooltip.asInstanceOf[util.List[String]] - tt.addAll(Tooltip.get(getClass.getSimpleName)) + override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean): Unit = { + tooltip.addAll(Tooltip.get(getClass.getSimpleName)) if (ItemCosts.hasCosts(stack)) { if (KeyBindings.showMaterialCosts) { - ItemCosts.addTooltip(stack, tt) + ItemCosts.addTooltip(stack, tooltip) } else { - tt.add(Localization.localizeImmediately( + tooltip.add(Localization.localizeImmediately( Settings.namespace + "tooltip.MaterialCosts", KeyBindings.getKeyBindingName(KeyBindings.materialCosts))) } @@ -55,7 +54,7 @@ trait SimpleItem extends Item { if (stack.hasTagCompound && stack.getTagCompound.hasKey(Settings.namespace + "data")) { val data = stack.getTagCompound.getCompoundTag(Settings.namespace + "data") if (data.hasKey("node") && data.getCompoundTag("node").hasKey("address")) { - tt.add("§8" + data.getCompoundTag("node").getString("address").substring(0, 13) + "...§7") + tooltip.add("§8" + data.getCompoundTag("node").getString("address").substring(0, 13) + "...§7") } } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Case.scala b/src/main/scala/li/cil/oc/common/tileentity/Case.scala index 2904a4870..f4810fc42 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Case.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Case.scala @@ -8,6 +8,7 @@ import li.cil.oc.common import li.cil.oc.common.InventorySlots import li.cil.oc.common.Slot import li.cil.oc.common.Tier +import li.cil.oc.common.block.property.PropertyRunning import li.cil.oc.util.Color import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack @@ -55,7 +56,7 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with override protected def onRunningChanged(): Unit = { super.onRunningChanged() getBlockType match { - case block: common.block.Case => world.setBlockState(getPos, block.withRunning(world.getBlockState(getPos), isRunning)) + case block: common.block.Case => world.setBlockState(getPos, world.getBlockState(getPos).withProperty(PropertyRunning.Running, Boolean.box(isRunning))) case _ => } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala index d7cb725a3..b887ce3e2 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala @@ -1,7 +1,7 @@ package li.cil.oc.common.tileentity.traits import li.cil.oc.api.internal -import li.cil.oc.common.block +import li.cil.oc.common.block.property.PropertyRotatable import li.cil.oc.server.{PacketSender => ServerPacketSender} import li.cil.oc.util.ExtendedEnumFacing._ import li.cil.oc.util.ExtendedWorld._ @@ -25,7 +25,7 @@ trait Rotatable extends RotationAware with internal.Rotatable { // ----------------------------------------------------------------------- // def pitch = if (world != null) getBlockType match { - case rotatable: block.traits.OmniRotatable => rotatable.getPitch(world.getBlockState(getPos)) + case rotatable if world.getBlockState(getPos).getProperties.containsKey(PropertyRotatable.Pitch) => world.getBlockState(getPos).getValue(PropertyRotatable.Pitch) case _ => EnumFacing.NORTH } else EnumFacing.NORTH @@ -36,8 +36,8 @@ trait Rotatable extends RotationAware with internal.Rotatable { }, yaw) def yaw = if (world != null) getBlockType match { - case rotatable: block.traits.OmniRotatable => rotatable.getYaw(world.getBlockState(getPos)) - case rotatable: block.traits.Rotatable => rotatable.getFacing(world.getBlockState(getPos)) + case rotatable if world.getBlockState(getPos).getProperties.containsKey(PropertyRotatable.Yaw) => world.getBlockState(getPos).getValue(PropertyRotatable.Yaw) + case rotatable if world.getBlockState(getPos).getProperties.containsKey(PropertyRotatable.Facing) => world.getBlockState(getPos).getValue(PropertyRotatable.Facing) case _ => EnumFacing.SOUTH } else EnumFacing.SOUTH @@ -127,10 +127,10 @@ trait Rotatable extends RotationAware with internal.Rotatable { else false } getBlockType match { - case rotatable: block.traits.OmniRotatable => - setState(rotatable.withPitchAndYaw(oldState, pitch, yaw)) - case rotatable: block.traits.Rotatable => - setState(rotatable.withFacing(oldState, yaw)) + case rotatable if oldState.getProperties.containsKey(PropertyRotatable.Pitch) && oldState.getProperties.containsKey(PropertyRotatable.Yaw) => + setState(oldState.withProperty(PropertyRotatable.Pitch, pitch).withProperty(PropertyRotatable.Yaw, yaw)) + case rotatable if oldState.getProperties.containsKey(PropertyRotatable.Facing) => + setState(oldState.withProperty(PropertyRotatable.Facing, yaw)) case _ => false } } diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala index 73ce208ca..050e973b5 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala @@ -48,7 +48,6 @@ import net.minecraft.util.BlockPos import net.minecraft.world.World import net.minecraftforge.common.ForgeChunkManager import net.minecraftforge.common.MinecraftForge -import net.minecraftforge.fml.common.FMLCommonHandler object ModOpenComputers extends ModProxy { override def getMod = Mods.OpenComputers @@ -73,10 +72,10 @@ object ModOpenComputers extends ModProxy { ForgeChunkManager.setForcedChunkLoadingCallback(OpenComputers, ChunkloaderUpgradeHandler) - FMLCommonHandler.instance.bus.register(EventHandler) - FMLCommonHandler.instance.bus.register(NanomachinesHandler.Common) - FMLCommonHandler.instance.bus.register(SimpleComponentTickHandler.Instance) - FMLCommonHandler.instance.bus.register(Tablet) + MinecraftForge.EVENT_BUS.register(EventHandler) + MinecraftForge.EVENT_BUS.register(NanomachinesHandler.Common) + MinecraftForge.EVENT_BUS.register(SimpleComponentTickHandler.Instance) + MinecraftForge.EVENT_BUS.register(Tablet) MinecraftForge.EVENT_BUS.register(Analyzer) MinecraftForge.EVENT_BUS.register(AngelUpgradeHandler) diff --git a/src/main/scala/li/cil/oc/integration/vanilla/DriverCommandBlock.java b/src/main/scala/li/cil/oc/integration/vanilla/DriverCommandBlock.java index c46ea9ee7..4c55f091e 100644 --- a/src/main/scala/li/cil/oc/integration/vanilla/DriverCommandBlock.java +++ b/src/main/scala/li/cil/oc/integration/vanilla/DriverCommandBlock.java @@ -51,7 +51,7 @@ public final class DriverCommandBlock extends DriverTileEntity implements Enviro @Callback(direct = true, doc = "function():string -- Get the command currently set in this command block.") public Object[] getCommand(final Context context, final Arguments args) { - return new Object[]{tileEntity.getCommandBlockLogic().getCustomName()}; + return new Object[]{tileEntity.getCommandBlockLogic().getCommand()}; } @Callback(doc = "function(value:string) -- Set the specified command for the command block.") diff --git a/src/main/scala/li/cil/oc/server/PacketHandler.scala b/src/main/scala/li/cil/oc/server/PacketHandler.scala index 25ade044f..472544815 100644 --- a/src/main/scala/li/cil/oc/server/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/server/PacketHandler.scala @@ -32,7 +32,7 @@ import net.minecraftforge.common.DimensionManager object PacketHandler extends CommonPacketHandler { @SubscribeEvent def onPacket(e: ServerCustomPacketEvent) = - onPacketData(e.packet.payload, e.handler.asInstanceOf[NetHandlerPlayServer].playerEntity) + onPacketData(e.manager.getNetHandler, e.packet.payload, e.handler.asInstanceOf[NetHandlerPlayServer].playerEntity) override protected def world(player: EntityPlayer, dimension: Int) = Option(DimensionManager.getWorld(dimension)) diff --git a/src/main/scala/li/cil/oc/server/agent/Inventory.scala b/src/main/scala/li/cil/oc/server/agent/Inventory.scala index 548b3d66c..2b7bdb53f 100644 --- a/src/main/scala/li/cil/oc/server/agent/Inventory.scala +++ b/src/main/scala/li/cil/oc/server/agent/Inventory.scala @@ -26,7 +26,7 @@ class Inventory(val agent: internal.Agent) extends InventoryPlayer(null) { override def changeCurrentItem(direction: Int) {} - override def func_174925_a(item: Item, damage: Int, count: Int, tag: NBTTagCompound) = 0 + override def clearMatchingItems(item: Item, damage: Int, count: Int, tag: NBTTagCompound): Int = 0 override def decrementAnimations() { for (slot <- 0 until getSizeInventory) { @@ -56,11 +56,7 @@ class Inventory(val agent: internal.Agent) extends InventoryPlayer(null) { InventoryUtils.insertIntoInventory(stack, this, slots = Option(slots)) } - override def func_146025_b(block: Block) = canHarvestBlock(block) - - def canHarvestBlock(block: Block): Boolean = { - block.getMaterial.isToolNotRequired || (getCurrentItem != null && getCurrentItem.canHarvestBlock(block)) - } + override def canHeldItemHarvest(block: Block): Boolean = block.getMaterial.isToolNotRequired || (getCurrentItem != null && getCurrentItem.canHarvestBlock(block)) override def getStrVsBlock(block: Block) = Option(getCurrentItem).fold(1f)(_.getStrVsBlock(block)) diff --git a/src/main/scala/li/cil/oc/server/agent/Player.scala b/src/main/scala/li/cil/oc/server/agent/Player.scala index 08f83311a..3aa2272e6 100644 --- a/src/main/scala/li/cil/oc/server/agent/Player.scala +++ b/src/main/scala/li/cil/oc/server/agent/Player.scala @@ -49,7 +49,6 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper import net.minecraftforge.fml.common.eventhandler.Event import scala.collection.convert.WrapAsScala._ -import scala.reflect.ClassTag object Player { def profileFor(agent: internal.Agent) = { @@ -491,7 +490,7 @@ class Player(val agent: internal.Agent) extends FakePlayer(agent.world.asInstanc override def swingItem() {} - override def canUseCommand(level: Int, command: String): Boolean = { + override def canCommandSenderUseCommand(level: Int, command: String): Boolean = { ("seed" == command && !mcServer.isDedicatedServer) || "tell" == command || "help" == command || diff --git a/src/main/scala/li/cil/oc/server/command/DebugNanomachinesCommand.scala b/src/main/scala/li/cil/oc/server/command/DebugNanomachinesCommand.scala index d516dc8d7..c37f3c540 100644 --- a/src/main/scala/li/cil/oc/server/command/DebugNanomachinesCommand.scala +++ b/src/main/scala/li/cil/oc/server/command/DebugNanomachinesCommand.scala @@ -13,7 +13,7 @@ object DebugNanomachinesCommand extends SimpleCommand("oc_debugNanomachines") { override def getCommandUsage(source: ICommandSender): String = name - override def execute(source: ICommandSender, args: Array[String]): Unit = { + override def processCommand(source: ICommandSender, args: Array[String]): Unit = { source match { case player: EntityPlayer => api.Nanomachines.installController(player) match { diff --git a/src/main/scala/li/cil/oc/server/command/LogNanomachinesCommand.scala b/src/main/scala/li/cil/oc/server/command/LogNanomachinesCommand.scala index 0c4daface..107f21bce 100644 --- a/src/main/scala/li/cil/oc/server/command/LogNanomachinesCommand.scala +++ b/src/main/scala/li/cil/oc/server/command/LogNanomachinesCommand.scala @@ -13,7 +13,7 @@ object LogNanomachinesCommand extends SimpleCommand("oc_nanomachines") { override def getCommandUsage(source: ICommandSender): String = name + " [player]" - override def execute(source: ICommandSender, command: Array[String]): Unit = { + override def processCommand(source: ICommandSender, command: Array[String]): Unit = { (if (command.length > 0) { val player = command(0) val config = MinecraftServer.getServer.getConfigurationManager diff --git a/src/main/scala/li/cil/oc/server/command/NonDisassemblyAgreementCommand.scala b/src/main/scala/li/cil/oc/server/command/NonDisassemblyAgreementCommand.scala index 09a758fff..a82bd4594 100644 --- a/src/main/scala/li/cil/oc/server/command/NonDisassemblyAgreementCommand.scala +++ b/src/main/scala/li/cil/oc/server/command/NonDisassemblyAgreementCommand.scala @@ -14,7 +14,7 @@ object NonDisassemblyAgreementCommand extends SimpleCommand("oc_preventDisassemb override def getCommandUsage(source: ICommandSender) = name + " " - override def execute(source: ICommandSender, command: Array[String]) { + override def processCommand(source: ICommandSender, command: Array[String]) { source match { case player: EntityPlayer => val stack = player.getHeldItem diff --git a/src/main/scala/li/cil/oc/server/command/SpawnComputerCommand.scala b/src/main/scala/li/cil/oc/server/command/SpawnComputerCommand.scala index f3d240ac6..a50fbcb59 100644 --- a/src/main/scala/li/cil/oc/server/command/SpawnComputerCommand.scala +++ b/src/main/scala/li/cil/oc/server/command/SpawnComputerCommand.scala @@ -22,7 +22,7 @@ object SpawnComputerCommand extends SimpleCommand("oc_spawnComputer") { override def getCommandUsage(source: ICommandSender): String = name - override def execute(source: ICommandSender, command: Array[String]) { + override def processCommand(source: ICommandSender, command: Array[String]) { source match { case player: EntityPlayer => val world = player.getEntityWorld diff --git a/src/main/scala/li/cil/oc/server/command/WirelessRenderingCommand.scala b/src/main/scala/li/cil/oc/server/command/WirelessRenderingCommand.scala index 52b07eeab..a042aac9a 100644 --- a/src/main/scala/li/cil/oc/server/command/WirelessRenderingCommand.scala +++ b/src/main/scala/li/cil/oc/server/command/WirelessRenderingCommand.scala @@ -10,7 +10,7 @@ object WirelessRenderingCommand extends SimpleCommand("oc_renderWirelessNetwork" override def getCommandUsage(source: ICommandSender) = name + " " - override def execute(source: ICommandSender, command: Array[String]) { + override def processCommand(source: ICommandSender, command: Array[String]) { Settings.rTreeDebugRenderer = if (command != null && command.length > 0) CommandBase.parseBoolean(command(0)) diff --git a/src/main/scala/li/cil/oc/server/component/DebugCard.scala b/src/main/scala/li/cil/oc/server/component/DebugCard.scala index 2cc672142..88aab0245 100644 --- a/src/main/scala/li/cil/oc/server/component/DebugCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DebugCard.scala @@ -595,7 +595,7 @@ object DebugCard { override def getPosition = underlying.getPosition - override def canUseCommand(level: Int, commandName: String) = { + override def canCommandSenderUseCommand(level: Int, commandName: String) = { val profile = underlying.getGameProfile val server = underlying.mcServer val config = server.getConfigurationManager diff --git a/src/main/scala/li/cil/oc/util/Audio.scala b/src/main/scala/li/cil/oc/util/Audio.scala index 144ecffa8..4bfe291cf 100644 --- a/src/main/scala/li/cil/oc/util/Audio.scala +++ b/src/main/scala/li/cil/oc/util/Audio.scala @@ -8,7 +8,7 @@ import net.minecraft.client.Minecraft import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.audio.SoundCategory import net.minecraft.util.ResourceLocation -import net.minecraftforge.fml.common.FMLCommonHandler +import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent import org.lwjgl.BufferUtils @@ -19,12 +19,12 @@ import org.lwjgl.openal.OpenALException import scala.collection.mutable /** - * This class contains the logic used by computers' internal "speakers". - * It can generate square waves with a specific frequency and duration - * and will play them through OpenAL, acquiring sources as necessary. - * Tones that have finished playing are disposed automatically in the - * tick handler. - */ + * This class contains the logic used by computers' internal "speakers". + * It can generate square waves with a specific frequency and duration + * and will play them through OpenAL, acquiring sources as necessary. + * Tones that have finished playing are disposed automatically in the + * tick handler. + */ object Audio { private def sampleRate = Settings.get.beepSampleRate @@ -185,7 +185,7 @@ object Audio { } } - FMLCommonHandler.instance.bus.register(this) + MinecraftForge.EVENT_BUS.register(this) @SubscribeEvent def onTick(e: ClientTickEvent) {