Advertisement
SergOmarov

Untitled

Apr 9th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.43 KB | None | 0 0
  1. @EventHandler
  2.  def preInit(e:FMLPreInitializationEvent): Unit ={
  3.    val item=new Item(){
  4.      setUnlocalizedName("TestItem")
  5.      override def onItemUse(p_77648_1_ : ItemStack, p_77648_2_ : EntityPlayer, p_77648_3_ : World, p_77648_4_ : Int, p_77648_5_ : Int, p_77648_6_ : Int, p_77648_7_ : Int, p_77648_8_ : Float, p_77648_9_ : Float, p_77648_10_ : Float):Boolean={
  6.        if(p_77648_2_.worldObj.isRemote)
  7.          return
  8.        regen(p_77648_2_)//регенить когда кликнул
  9.         //p_77648_2_.worldObj.setBlock(p_77648_2_.posX.toInt,p_77648_2_.posY.toInt,p_77648_2_.posZ.toInt,Blocks.clay)//вот это пашет
  10.  
  11.        true
  12.      }
  13.  
  14.    }
  15.    GameRegistry.registerItem(item,"TestItem")
  16.  
  17.  }
  18.  
  19.  
  20. def regen(player: EntityPlayer): Unit = {
  21.    val x=player.posX.asInstanceOf[Int] >> 4
  22.    val y=player.posY.asInstanceOf[Int] >> 4
  23.    //Чанк-провайдер юзается из мода RTG, но не думаю, что это влияет: массив же заполняется как надо
  24.    val chunkLocation = new PlaneLocation.Invariant(x,y)
  25.  
  26.    val mapRand=new Random(worldSeed)
  27.    val rand=new Random(worldSeed)
  28.    rand.setSeed(x.asInstanceOf[Long] * 0x4f9939f508L + y.asInstanceOf[Long] * 0x1ef1565bd5L)
  29.  
  30.    var blocks = new Array[Block](65536)
  31.    var metadata = new Array[Byte](65536)
  32.  
  33.    var k:Int=0
  34.    val worldObj=DimensionManager.getWorld(0)
  35.    val cmr=DimensionManager.getWorld(0).getWorldChunkManager.asInstanceOf[WorldChunkManagerRTG]
  36.  
  37.    val landscape = landscapeGenerator.get(WorldTypeRTG.chunkProvider).asInstanceOf[LandscapeGenerator].landscape(cmr, x *16, y*16)
  38.  
  39.    WorldTypeRTG.chunkProvider.generateTerrain(cmr, x, y, blocks, metadata, landscape.biome, landscape.noise)//заполняются массивы, это происходит дольше тика, но игра не фризит
  40.    val cx=x<<4
  41.    val cy=y<<4//коорды начала чанка
  42.    for(i <- 0 until 16)
  43.    {
  44.      for(j <- 0 until 16)
  45.      {
  46.        for(k <- 0 until 256)
  47.        {
  48.          val p = (j * 16 + i) * 256 + k//я уверен в этой формуле
  49.          player.worldObj.setBlock(cx+i,k,cy+j,blocks(p),metadata(p),3)
  50.          player.worldObj.markBlockForUpdate(cx+i,k,cy+j)//если юзать worldObj, который берется из DimensionManager, эффект не изменяется
  51.        }
  52.      }
  53.    }
  54.    println("test")//до этого момента доходит
  55.  
  56.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement