Jump to content

[Solved] TileEntity missing from server after world restart


Yagoki

Recommended Posts

I have created a new tile entity which is supposed to detect entities dying around it. This functionality works fine when the tile has just been created, however when the world gets re-loaded the tile does not get created on the server stopping it from working. My assumption is that it is down to my attempted use of block states to define which have tile entities. If anyone has suggestions for fixing this it would be much appreciated

 

Github: TileEntity

package com.yagoki.mtech.block.tileentity

import net.minecraft.entity.boss.{EntityDragon, EntityWither}
import net.minecraft.entity.{EntityCreature, EntityLivingBase}
import net.minecraft.entity.monster.EntityMob
import net.minecraft.entity.passive.{EntityTameable, EntityVillager}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.ITickable
import net.minecraft.util.math.AxisAlignedBB

import scala.collection.JavaConversions._
import com.yagoki.mtech.util.MathUtil._

/**
  * Created by Ben on 06/04/2016.
  */
class TileEntityObelisk extends SimpleTileEntity with ITickable {
  private var _power: Int = 0
  def power = _power
  def power_=(v: Int) = {
    _power = v
    // TODO: remove debug
    println(power)
    if (!this.getWorld.isRemote) this.getWorld.scheduleUpdate(this.getPos, this.getBlockType, 1)
  }

  override def update(): Unit = {
    val ents: List[EntityLivingBase] = this.getWorld.getEntitiesWithinAABB(classOf[EntityLivingBase],
      new AxisAlignedBB(this.getPos-(4, 2, 4), this.getPos+(4, 2, 4)).addCoord(.5, .5, .5)).toList

    ents foreach { e => if (!e.isEntityAlive) power += lifeValForEntity(e) }
  }

  def lifeValForEntity(e: EntityLivingBase): Int = e match {
    case _: EntityPlayer => 0
    case _: EntityDragon => 160
    case _: EntityWither => 80
    case _: EntityTameable => 16
    case _: EntityVillager => 8
    case _: EntityMob => 2
    case _: EntityCreature => 4
    case _ => 1
  }

  override def writeToNBT(compound: NBTTagCompound): Unit = {
    super.writeToNBT(compound)
    compound.setInteger("power", power)
  }

  override def readFromNBT(compound: NBTTagCompound): Unit = {
    super.readFromNBT(compound)
    power = compound.getInteger("power")
  }
}

 

Github: Block

package com.yagoki.mtech.block

import com.yagoki.mtech.block.ModBlocks.SimpleTile
import net.minecraft.block.Block
import net.minecraft.block.state.{BlockStateContainer, IBlockState}
import net.minecraft.init.Blocks
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.math.{AxisAlignedBB, BlockPos}
import net.minecraft.world.{IBlockAccess, World}

/**
  * Created by Ben on 07/04/2016.
  */
trait BlockObelisk extends SimpleTile {
  override def isOpaqueCube(state: IBlockState): Boolean = false
  override def isFullCube(state: IBlockState): Boolean = false

  def bbFromState(state: IBlockState): AxisAlignedBB = getMetaFromState(state) match {
    case 0 => new AxisAlignedBB(1/16D, 0, 1/16D, 15/16D, 1, 15/16D)
    case 1 => new AxisAlignedBB(2/16D, 0, 2/16D, 14/16D, 1, 14/16D)
    case 2 => new AxisAlignedBB(3/16D, 0, 3/16D, 13/16D, 1, 13/16D)
  }

  override def getBoundingBox(state: IBlockState, source: IBlockAccess, pos: BlockPos): AxisAlignedBB = bbFromState(state)

  override def getMetaFromState(state: IBlockState): Int = state.getValue(ModBlocks.TIER)

  override def getStateFromMeta(meta: Int): IBlockState = this.getDefaultState.withProperty[integer, Integer](ModBlocks.TIER, meta)

  override def createBlockState(): BlockStateContainer = new BlockStateContainer(this, ModBlocks.TIER)

  override def onNeighborBlockChange(world: World, pos: BlockPos, state: IBlockState, neighborBlock: Block): Unit = {

    val zeroPoint: Int = -state.getValue(ModBlocks.TIER)
    val obeliskBlocks = (zeroPoint to (zeroPoint+2)).map(i => world.getBlockState(pos.add(0, i, 0)))

    if (!obeliskBlocks.forall(s => s.getBlock == Blocks.sandstone || s.getBlock == ModBlocks("blockObelisk").get))
      world.setBlockState(pos, Blocks.sandstone.getDefaultState)
  }

  override def createTileEntity(world: World, state: IBlockState): TileEntity = this.createNewTileEntity(world, getMetaFromState(state))

  override def createNewTileEntity(world: World, i: Int): TileEntity = i match {
    case 0 => super.createNewTileEntity(world, i)
  }
}

 

all other files are on my github so look as you need

Link to comment
Share on other sites

Tile entity is registered in the ModBlocks object. this is not the issue. I can see assignment happening to the the variable

power

on the client side but no such luck on the server

 

Before world restart

[21:41:50] [21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: tile for 0
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: tile for 0
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:44:33] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:44:33] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 0
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 4
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 8
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 4
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 8
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 12
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 12
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 16
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 16
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 20
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 20
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 24
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 24
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 28
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 28
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 32
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 32
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 36
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 36
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 40
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 40
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 44
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 44
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 48
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 48
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 52
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 52
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 56
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 56
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 60
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 60
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 64
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 64
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 68
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 68
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 72
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 72
[21:44:43] [server thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 76
[21:44:43] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 76

 

[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: tile for 0
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=0]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=1]
[21:42:02] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: mtech:blockObelisk[tier=2]
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 4
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 8
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 12
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 16
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 20
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 24
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 28
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 32
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 36
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 40
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 44
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 48
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 52
[21:42:09] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 56
[21:42:10] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 60
[21:42:10] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 64
[21:42:10] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 68
[21:42:10] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 72
[21:42:10] [Client thread/INFO] [sTDOUT]: [scala.Console$:println:148]: 76

 

you can see that when the world restarts there are no longer updates getting posted from the server thread

 

as for my use of scala, it's nicer to code in (in my opinion) and has a lot of useful tools, a better interface system (see traits), implicit functions, among other things. mostly just a personal preference

Link to comment
Share on other sites

the tile are not getting saved. The client side tile is created at world load and I can force the tile to be loaded on the server by calling world.getTileEntity on the server side from an item use or some such

still no idea what is causing this. receiving no errors stating that the tile entity is missing a mapping so it's not an issue with the registering from what I can tell. The methods createTileEntity and hasTileEntity are not called from the server following world load until world.getTileEntity is called. seems to be true for all my tile entities, but somehow never noticed it before. Possible forge problem?

Link to comment
Share on other sites

Found the issue. was down to a NPE that i wasn't noticing as it wasn't killing the system, kept assuming the stack-trace was part of the authentication exception which always happens when first launched (caused by ). this was causing the readFromNBT to fail every time from the server. fixed it by amending this statement with a check for hasWorldObj in the setter for power

if (this.hasWorldObj && !this.getWorld.isRemote) this.getWorld.scheduleUpdate(this.getPos, this.getBlockType, 1)

it's always the simple things that seem to catch me out the most... :/

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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