Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8.9] Block with metadata in scala


octonion
 Share

Recommended Posts

I am trying to implement a block with metadata in scala. Here is my code:

 

[pre]package generic.block

 

import java.util

import scala.collection.JavaConversions._

 

import net.minecraft.block.Block

import net.minecraft.block.material.Material

import net.minecraft.block.properties.{IProperty, PropertyDirection, PropertyInteger}

import net.minecraft.block.state.{BlockState, IBlockState}

import net.minecraft.creativetab.CreativeTabs

import net.minecraft.item.{Item, ItemStack}

import net.minecraft.util.{AxisAlignedBB, BlockPos, EnumFacing, EnumWorldBlockLayer}

import net.minecraft.world.{IBlockAccess, World}

import net.minecraftforge.fml.relauncher.{Side, SideOnly}

 

object BlockIndexful extends Block(Material.cloth) {

 

  // Renders like glass

  // Each pixel is either completely transparent or opaque

  @SideOnly(Side.CLIENT)

  override val getBlockLayer = EnumWorldBlockLayer.CUTOUT

 

  override val isOpaqueCube = false

  override val isFullCube = false

  override def getCollisionBoundingBox(world: World, pos: BlockPos, state: IBlockState): AxisAlignedBB = null

 

  final val propertyFacing = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL)

  final val propertyIndex = PropertyInteger.create("index", 0, 3)

 

  @SideOnly(Side.CLIENT)

  override def getSubBlocks(item: Item, tab: CreativeTabs, list: util.List[itemStack]): Unit = {

    for (i <- 0 to 3)

      list.add(new ItemStack(item, 1, i))

  }

 

  override def getStateFromMeta(meta: Int) = {

val facing = EnumFacing.getHorizontal(meta)

val index = (meta & 0x0c) >> 2

getDefaultState.withProperty(propertyFacing, facing).withProperty(propertyIndex, index)

                // (1)

  }

override def getMetaFromState(state: IBlockState) = {

val facing = state.getValue(propertyFacing)

val index = state.getValue(propertyIndex)

facing.getHorizontalIndex | index << 2

}

override def getActualState(state: IBlockState, world: IBlockAccess, pos: BlockPos) = state

override def createBlockState = {

val properties = Array(

propertyFacing,

propertyIndex)

new BlockState(this, properties)

                // (2)

}

 

}[/pre]

 

 

There seems to be some problems. At (1), The compiler says that

 

[pre]Error:(45, 56) inferred type arguments [Any,Int] do not conform to method withProperty's type parameter bounds [T <: Comparable[T],V <: T]

getDefaultState.withProperty(propertyFacing, facing).withProperty(propertyIndex, index)

                                                    ^[/pre]

 

At (2), it says [pre]Error:(57, 33) type mismatch;

found  : Array[net.minecraft.block.properties.PropertyHelper[_ >: Integer with net.minecraft.util.EnumFacing <: Comparable[_ >: Integer with net.minecraft.util.EnumFacing <: java.io.Serializable] with java.io.Serializable]]

required: net.minecraft.block.properties.IProperty[?0] forSome { type ?0 <: Comparable[?0] }

new BlockStateContainer(this, properties)

                              ^[/pre]

 

These codes are from MinecraftByExamples and work perfectly fine in Java. What should I change to fix the problem? For (2), I have tried casting the elements to type [pre]IProperty[_ <: Comparable[_]][/pre] and to [pre]IProperty[_][/pre], but that did not solve the problem.

 

Are there any examples/tutorials of scala modding? Thanks in advance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.