Jump to content

Entity Server/Client update issues


allout58

Recommended Posts

I am having some issues with the server updating the client as to its position.

 

 

My full project can be view here: https://github.com/allout58/SpaceCraft

 

 

Here is the code file for the entity in question:

EntityRocket.java


package allout58.mods.SpaceCraft.Rockets.Entity;


import java.util.Random;



import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import allout58.mods.SpaceCraft.Rockets.Rocket;


public class EntityRocket extends Entity
{
    Rocket rocketLogic;


    public EntityRocket(World world)
    {
        super(world);
        // this.preventEntitySpawning = true;
    }


    public EntityRocket(World par1World, Rocket rLogic, double x, double y, double z)
    {
        this(par1World);
        this.setPosition(x, y, z);
        rocketLogic = rLogic;
        rocketLogic.Launch();
    }


    @Override
    protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
         rocketLogic = new Rocket();
         rocketLogic.readFromNBT(nbttagcompound);
    }


    @Override
    protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
         rocketLogic.writeToNBT(nbttagcompound);
    }


    @Override
    public void onUpdate()
    {
        super.onUpdate();
        if (ticksExisted > 500) this.kill();
        if (rocketLogic == null) return;
        if (!worldObj.isRemote)
        {
            rocketLogic.tick();
            this.motionX = rocketLogic.velX;
            this.motionY = rocketLogic.velY;
            this.motionZ = rocketLogic.velZ;
        }
        setPosition(posX + motionX, posY + motionY, posZ + motionZ);
        if (worldObj.isRemote)
        {
            Random rand = new Random();
            for (int i = 0; i < (rocketLogic.Size.ordinal() + 1) * (2 - Minecraft.getMinecraft().gameSettings.particleSetting); i++)
            {
                worldObj.spawnParticle("flame", this.posX + rand.nextDouble() * (rand.nextBoolean() ? -1 : 1), this.posY - rand.nextDouble(), this.posZ + rand.nextDouble() * (rand.nextBoolean() ? -1 : 1), rand.nextInt(35) / 100 * (rand.nextBoolean() ? -1 : 1), -rand.nextDouble(), rand.nextInt(35) / 100 * (rand.nextBoolean() ? -1 : 1));
            }
        }
        System.out.println("Rocket entity-" + (worldObj.isRemote ? "Client" : "Server") + " x:" + posX + " y:" + posY + " z:" + posZ);


    }


    @Override
    protected void entityInit()
    {


    }
}

 

 

FYI, the class Rocket updates "velY" on "tick()". See the github for the full file.

 

 

Here is some of the output:


2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Server x:-594.5 y:246.40848585690674 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Client x:-594.5 y:231.5 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Server x:-594.5 y:246.40848585690674 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Client x:-594.5 y:231.5 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Server x:-594.5 y:246.40848585690674 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Client x:-594.5 y:231.5 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Server x:-594.5 y:246.40848585690674 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Client x:-594.5 y:231.5 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Server x:-594.5 y:246.40848585690674 z:-165.5
2013-09-02 23:24:43 [iNFO] [sTDOUT] Rocket entity-Client x:-594.5 y:231.5 z:-165.5

 

 

Thanks for any help you can give!

allout58

Link to comment
Share on other sites

thebest108: the y is the only one I am changing, but I set the motionX, motionY and motionZ to constants > 0 and client still wasn't moving. I can get the client to move, but not with the server.

 

 

GotoLink: yes, but after running a world.isRemote check. How else am I going to get the particle settings? The particles can only be spawned client side.

 

 

The particles are the real reason I want both client and server side. If I make sure that only the serverside entity is spawned, everything works fine but I can't spawn particles, and I really want particles...

allout58

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



×
×
  • Create New...

Important Information

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