Jump to content

[SOLVED] [1.7.10] TileEntity does not update after leaving world.


Recommended Posts

Posted

Hello,

I have a TileEntity in my mod. It's main objective is to detect if certain player is in range and if it's true, then change an int. It works well when it's first placed, but after log off log on into world, it does not update till i hit it with something. Any ideas why is it so? Here's code:

 

package com.lessoner.angelsdemons.TileEntities;

import com.lessoner.angelsdemons.Blocks.AVDBlocks;
import com.lessoner.angelsdemons.IEEP.AVDPlayerStats;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

/**
* Created by Anguarmas on 1/15/2016.
*/
public class TileEntityAltar extends TileEntity {
     private static final String ALTAR_NBT = "altar";

    private static EntityPlayer player;
    /* Rotation */
    public float rotation = 0;
    /* Scale */
    public float scale = 0;

    private int altarLevel;
    private float altarExperience;
    public static String owner;
    private int activatingRangeFromPlayer = 20;
    private int cooldown = 21;

    public TileEntityAltar(){
        this.player = Minecraft.getMinecraft().thePlayer;
        altarLevel = 0;
    }

    @Override
    public void updateEntity() {
        super.updateEntity();
        if (worldObj.isRemote){
            rotation += 0.5f;
            scale = 0.5f;
        }
        if (!worldObj.isRemote) {
            if(cooldown > 0 ){
               --cooldown;

                if(cooldown <= 1) {
                    System.out.println(isActivated());
                    if (isActivated()) {
                        AVDPlayerStats props = AVDPlayerStats.get(this.worldObj.getPlayerEntityByName(owner));
                        props.changeAVD(0.1f);
                        AVDPlayerStats.get(this.worldObj.getPlayerEntityByName(owner)).sync();
                        System.out.println(props.getCurrentAVDLevel());
                    }
                    cooldown = 21;
                }
            }

        }
    }
    public boolean isActivated()
    {
        if(this.worldObj.getClosestPlayer((double)this.xCoord + 0.5D,(double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D, (double)this.activatingRangeFromPlayer) != null){
            if(this.worldObj.getClosestPlayer((double)this.xCoord + 0.5D,(double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D, (double)this.activatingRangeFromPlayer) == this.worldObj.getPlayerEntityByName(owner)){
              return true;
            }
        }
        return false;
    }
    public void readFromNBT(NBTTagCompound tagCompound)
    {
        NBTTagCompound stats = (NBTTagCompound) tagCompound.getTag(ALTAR_NBT);
        this.altarLevel = stats.getInteger("Level");
        this.owner = stats.getString("Owner");
        this.altarExperience = stats.getFloat("Experience");
    }

    public void writeToNBT(NBTTagCompound tagCompound)
    {
        NBTTagCompound stats = new NBTTagCompound();
        stats.setInteger("Level", altarLevel);
        stats.setString("Owner", owner);
        stats.setFloat("Experience", altarExperience);
        tagCompound.setTag(ALTAR_NBT,stats);
    }

    public void changeXP(float amount) {
        this.altarExperience= this.altarExperience + amount;
    }





}

Posted

Hello,

I have a TileEntity in my mod. It's main objective is to detect if certain player is in range and if it's true, then change an int. It works well when it's first placed, but after log off log on into world, it does not update till i hit it with something. Any ideas why is it so? Here's code:

 

package com.lessoner.angelsdemons.TileEntities;

import com.lessoner.angelsdemons.Blocks.AVDBlocks;
import com.lessoner.angelsdemons.IEEP.AVDPlayerStats;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

/**
* Created by Anguarmas on 1/15/2016.
*/
public class TileEntityAltar extends TileEntity {
     private static final String ALTAR_NBT = "altar";

    private static EntityPlayer player;
    /* Rotation */
    public float rotation = 0;
    /* Scale */
    public float scale = 0;

    private int altarLevel;
    private float altarExperience;
    public static String owner;
    private int activatingRangeFromPlayer = 20;
    private int cooldown = 21;

    public TileEntityAltar(){
        this.player = Minecraft.getMinecraft().thePlayer;
        altarLevel = 0;
    }

    @Override
    public void updateEntity() {
        super.updateEntity();
        if (worldObj.isRemote){
            rotation += 0.5f;
            scale = 0.5f;
        }
        if (!worldObj.isRemote) {
            if(cooldown > 0 ){
               --cooldown;

                if(cooldown <= 1) {
                    System.out.println(isActivated());
                    if (isActivated()) {
                        AVDPlayerStats props = AVDPlayerStats.get(this.worldObj.getPlayerEntityByName(owner));
                        props.changeAVD(0.1f);
                        AVDPlayerStats.get(this.worldObj.getPlayerEntityByName(owner)).sync();
                        System.out.println(props.getCurrentAVDLevel());
                    }
                    cooldown = 21;
                }
            }

        }
    }
    public boolean isActivated()
    {
        if(this.worldObj.getClosestPlayer((double)this.xCoord + 0.5D,(double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D, (double)this.activatingRangeFromPlayer) != null){
            if(this.worldObj.getClosestPlayer((double)this.xCoord + 0.5D,(double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D, (double)this.activatingRangeFromPlayer) == this.worldObj.getPlayerEntityByName(owner)){
              return true;
            }
        }
        return false;
    }
    public void readFromNBT(NBTTagCompound tagCompound)
    {
        NBTTagCompound stats = (NBTTagCompound) tagCompound.getTag(ALTAR_NBT);
        this.altarLevel = stats.getInteger("Level");
        this.owner = stats.getString("Owner");
        this.altarExperience = stats.getFloat("Experience");
    }

    public void writeToNBT(NBTTagCompound tagCompound)
    {
        NBTTagCompound stats = new NBTTagCompound();
        stats.setInteger("Level", altarLevel);
        stats.setString("Owner", owner);
        stats.setFloat("Experience", altarExperience);
        tagCompound.setTag(ALTAR_NBT,stats);
    }

    public void changeXP(float amount) {
        this.altarExperience= this.altarExperience + amount;
    }





}

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



×
×
  • Create New...

Important Information

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