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

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;
    }





}

  • 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;
    }





}

  • Author

1) isn't needed, removed.

2) as said isn't needed anymore.

3) will change that.

4) yes i have registered it.

  • 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.

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.