Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

I found the problem. Mysteriously my Java version was set to Java 6 when it should be Java 8. Now all the errors are gone and minecraft runs without problem.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.