Jump to content

[1.7.2] problem with entities spawning from thrown... [Fixed]


KoadMaster

Recommended Posts

Ok, so the title isn't exactly long enough for me to say my entire problem, but basically I have a throwable entity that works like any other throwable entity, with the following as a the onImpact method:

    protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
    {
    	EntityNetOut entity = new EntityNetOut(this.worldObj, this.posX, this.posY, this.posZ);
    	
        if (par1MovingObjectPosition.entityHit != null)
        {
        	System.out.println( "Entity" );
            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
        }  
        
        if (!this.worldObj.isRemote)
        {
        	entity.rotationYaw = this.rotationYaw;
        	entity.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
        	this.worldObj.spawnEntityInWorld(entity);
        	this.setDead();
        }
    }
}

basically if it hits anything it should spawn a "EntityNetOut" which is a entity that I have made, now the basic problem is that it doesn't appear to actually do it, after some effort I found that if I take away the "if (!this.worldObj.isRemote)" line it will kinda spawn, but it will have all kinds of problems (which is kinda expected). This leads me to think that it is probably a problem with client/server relations and my entity. However, after further tests, I found that the entity did in fact spawn but simply didn't effect anything, (entitynetout class:)

package kodithemaster.Pirates;

import java.util.Iterator;
import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class EntityNetOut extends Entity
{	
public EntityNetOut(World par1World, double x, double y, double z)
    {	
	super(par1World);
        this.setPosition(x, y, z);
        this.setSize(2F, 2F);
}

public void onCollideWithPlayer(EntityPlayer par1EntityPlayer)
{
	par1EntityPlayer.setInWeb();
}
    
    public AxisAlignedBB getCollisionBox(Entity par1Entity)
    {
        return null;
    }

    /**
     * returns the bounding box for this entity
     */
    public AxisAlignedBB getBoundingBox()
    {
        return null;
    }
    
    public void onUpdate()
    {    	
        float f = 1.0F;
        List list = this.worldObj.getEntitiesWithinAABB(Entity.class, this.boundingBox.expand((double)f, (double)f, (double)f));
        Iterator iterator = list.iterator();
        
        while (iterator.hasNext())
        {
        	((Entity) iterator.next()).setInWeb();
        }
    }

@Override
    protected void entityInit() {}

@Override
public void readEntityFromNBT(NBTTagCompound var1) {}

@Override
public void writeEntityToNBT(NBTTagCompound var1) {}
}

as you can see, the onUpdate method should cause surrounding entities to be slowed, however, it only does that if I have the EntityNet spawn a new one on the client side.

Additionally, if I set the EntityNet to spawn a boat, or any other vanilla entity, it works fine, which leads me to think that the problem actually has something to do with my EntityNetOut, but I don't know what would actually be wrong with it. Right now I am trying to get it to actually render properly if only spawned on the server side, after which I plan to work on actually getting it to slow things properly, so here is my Render file:


package kodithemaster.Pirates;

import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBoat;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;

import org.lwjgl.opengl.GL11;


public class RenderNetOut extends Render
{
    protected ModelBase modelNet;
    private ResourceLocation tex = new ResourceLocation("koadpirates", "textures/entity/NetOut.png");

    public RenderNetOut()
    {
        this.modelNet = new ModelNetOut();
    }

    public void doRender(EntityNetOut par1EntityNetOut, double par2, double par4, double par6, float par8, float par9)
    {
    	//
    	//
    	//
    	// I need what goes here!!!!
    	//
    	//
    	//
        GL11.glPushMatrix();
        this.bindEntityTexture(par1EntityNetOut);
        long i = (long)par1EntityNetOut.getEntityId() * 493286711L;
        i = i * i * 4392167121L + i * 98761L;
        float f2 = (((float)(i >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
        float f3 = (((float)(i >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
        float f4 = (((float)(i >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
        GL11.glTranslatef(f2, f3, f4);
        double d3 = par1EntityNetOut.lastTickPosX + (par1EntityNetOut.posX - par1EntityNetOut.lastTickPosX) * (double)par9;
        double d4 = par1EntityNetOut.lastTickPosY + (par1EntityNetOut.posY - par1EntityNetOut.lastTickPosY) * (double)par9;
        double d5 = par1EntityNetOut.lastTickPosZ + (par1EntityNetOut.posZ - par1EntityNetOut.lastTickPosZ) * (double)par9;
        double d6 = 0.30000001192092896D;
        float f5 = par1EntityNetOut.prevRotationPitch + (par1EntityNetOut.rotationPitch - par1EntityNetOut.prevRotationPitch) * par9;

        GL11.glTranslatef((float)par2, (float)par4, (float)par6);
        GL11.glRotatef(180.0F - par8, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(-f5, 0.0F, 0.0F, 1.0F);

        GL11.glScalef(-1.0F, -1.0F, 1.0F);
        this.modelNet.render(par1EntityNetOut, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
    }

    protected ResourceLocation getEntityTexture(EntityNetOut par1Entity)
    {
        return tex; 
    }
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity par1Entity)
    {
        return this.getEntityTexture((EntityNetOut)par1Entity);
    }

@Override
    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    {
        this.doRender((EntityNetOut)par1Entity, par2, par4, par6, par8, par9);
    }
}

(based on render minecart code I think)

 

So any help would be appreciated

 

FIXED :D

Thank You.

 

Link to comment
Share on other sites

As you yourself mention, the spawning code looks correct.  It is probably something else with your actual entity.  Does your entity have a model so you can see it?  Or are you trying to "see" it by noticing its effect?

 

To debug things I usually add console statements throughout the code to help trace the logic.  For example, every time it finds an entity to set in the web, print something out that indicates the entity "set entity X in web" sort of output.  I usually put in a console statement in every method just to confirm it is even being run.  And anywhere you have an if statement it is good to have console statement to indicate which path the code took.

 

Also, it is REALLY important to use @Override annotation.  I usually set up my Eclipse to check (and add) the @Override on save.  This is because any typo or mistake with parameter list means that the method you think is being called won't be called.  Like maybe your onUpdate() is never being called because it might contain a mistake in the override.

 

 

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Uh yes, it does have a model (which is essentially a big square), and it has the texture that should be mapped to it, though, to my knowledge, it doesn't seem to render said model unless I make it spawn a client side net.

 

As far as the debugging, I generally try that as well, though I didn't think to put things in the actual onUpdate statement, that said, upon trying it it does claim to find the entity to set in the web, though it doesn't seem to actually do it, I will have to look into that, however, it still does actually render

 

Yeah, I am kinda lazy about that... Even though I shouldn't be, I will probably try to do better with that in the future.

 

EDIT: So, it seems that how I have it set up right now the net entity will actually effect mobs that are in it, however, these mobs 'lag' as in, if they would be falling while in the net it will fall and then bounce back to where it actually should be due to the nets slow... To my knowledge the net does not effect players whatsoever.

 

EDIT2: So, I have tried to solve one issue at a time and then move on, so I commented out all of the unnecessary code in the EntityNetOut class, so that I could focus on just getting the entity to render properly, thus far I have not been able to get it to work, even when I replaced the render file with a different render file that I have made for a different entity that I know works, so I am not sure what is up with that, but my entity is not rendering properly

 

EDIT3: (and yeah, I edit a lot) So, (and I like leading off with 'so,') I have come to some degree of a conclusion about what is going on, though I don't know how to fix it as of yet, basically the problem is that my netOutEntity, when spawned on the server side, doesn't correctly do anything on the client side, this puzzles me, because basically my netOut entity is a boat, with similar code in the entity file, but it leads me to think that it is possible that the problem is actually that I am missing something the boat does somewhere besides the actual entity file that causes the synergy between sever and client...

 

EDIT4: (for the lols) So, ( :D ) I figured out that the basic problem was that I was registering the entity slightly wrong due to a typo, and that caused all sorts of problems, so, it really wasn't as complicated as I thought, regardless, I have worked it out and fixed it.

Thank you for your time

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.