Posted May 29, 20169 yr 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; } }
May 29, 20169 yr Author 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; } }
May 30, 20169 yr Author 1) isn't needed, removed. 2) as said isn't needed anymore. 3) will change that. 4) yes i have registered it.
May 30, 20169 yr Author 1) isn't needed, removed. 2) as said isn't needed anymore. 3) will change that. 4) yes i have registered it.
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.