Jump to content

Recommended Posts

Posted

Hello everyone. I'm having difficulties with my water mob. For some reason it will just stand there and after a little bit, they'll just die. Here is all the code for my fish mob:

 

Model Class:

 

// Date: 7/11/2014 10:29:28 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX

package com.MagZAquaticLifeExperience.common.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelFish extends ModelBase
{
  //fields
    ModelRenderer body001;
    ModelRenderer mouth001;
    ModelRenderer top001;
    ModelRenderer body002;
    ModelRenderer body003;
    ModelRenderer mouth002;
    ModelRenderer body004;
    ModelRenderer body005;
    ModelRenderer body006;
    ModelRenderer body007;
    ModelRenderer sidefin001;
    ModelRenderer sidefin002;
    ModelRenderer topfin001;
    ModelRenderer bottomfin001;
  
  public ModelFish()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      body001 = new ModelRenderer(this, 0, 0);
      body001.addBox(-1F, 0F, 0F, 3, 3, 6);
      body001.setRotationPoint(0F, 20F, -3F);
      body001.setTextureSize(64, 32);
      body001.mirror = true;
      setRotation(body001, 0F, 0F, 0F);
      mouth001 = new ModelRenderer(this, 56, 0);
      mouth001.addBox(0F, 0F, 0F, 3, 2, 1);
      mouth001.setRotationPoint(-1F, 20.5F, -3.6F);
      mouth001.setTextureSize(64, 32);
      mouth001.mirror = true;
      setRotation(mouth001, 0F, 0F, 0F);
      top001 = new ModelRenderer(this, 41, 0);
      top001.addBox(0F, -1F, 0F, 3, 1, 4);
      top001.setRotationPoint(-1F, 20.6F, -2F);
      top001.setTextureSize(64, 32);
      top001.mirror = true;
      setRotation(top001, 0F, 0F, 0F);
      body002 = new ModelRenderer(this, 56, 4);
      body002.addBox(0F, 0F, 0F, 3, 2, 1);
      body002.setRotationPoint(-1F, 20.5F, 2.7F);
      body002.setTextureSize(64, 32);
      body002.mirror = true;
      setRotation(body002, 0F, 0F, 0F);
      body003 = new ModelRenderer(this, 47, 6);
      body003.addBox(0F, 0F, 0F, 3, 2, 1);
      body003.setRotationPoint(-1F, 20.5F, 3.2F);
      body003.setTextureSize(64, 32);
      body003.mirror = true;
      setRotation(body003, 0F, 0F, 0F);
      mouth002 = new ModelRenderer(this, 56, ;
      mouth002.addBox(0F, 0F, 0F, 3, 1, 1);
      mouth002.setRotationPoint(-1F, 21F, -4F);
      mouth002.setTextureSize(64, 32);
      mouth002.mirror = true;
      setRotation(mouth002, 0F, 0F, 0F);
      body004 = new ModelRenderer(this, 56, 11);
      body004.addBox(0F, 0F, 0F, 3, 1, 1);
      body004.setRotationPoint(-1F, 21F, 3.7F);
      body004.setTextureSize(64, 32);
      body004.mirror = true;
      setRotation(body004, 0F, 0F, 0F);
      body005 = new ModelRenderer(this, 49, 10);
      body005.addBox(0F, 0F, 0F, 2, 1, 1);
      body005.setRotationPoint(-0.5F, 20F, 2.6F);
      body005.setTextureSize(64, 32);
      body005.mirror = true;
      setRotation(body005, 0F, 0F, 0F);
      body006 = new ModelRenderer(this, 51, 13);
      body006.addBox(0F, 0F, 0F, 1, 1, 1);
      body006.setRotationPoint(0F, 19.6F, 2F);
      body006.setTextureSize(64, 32);
      body006.mirror = true;
      setRotation(body006, 0F, 0F, 0F);
      body007 = new ModelRenderer(this, 60, 14);
      body007.addBox(0F, -1F, 0F, 1, 1, 1);
      body007.setRotationPoint(0F, 20.6F, -2.6F);
      body007.setTextureSize(64, 32);
      body007.mirror = true;
      setRotation(body007, 0F, 0F, 0F);
      sidefin001 = new ModelRenderer(this, 34, 0);
      sidefin001.addBox(0F, 0F, 0F, 0, 3, 3);
      sidefin001.setRotationPoint(2F, 19.9F, -2F);
      sidefin001.setTextureSize(64, 32);
      sidefin001.mirror = true;
      setRotation(sidefin001, 0F, 0.4461433F, 0F);
      sidefin002 = new ModelRenderer(this, 27, 0);
      sidefin002.addBox(0F, 0F, 0F, 0, 3, 3);
      sidefin002.setRotationPoint(-1F, 19.9F, -2F);
      sidefin002.setTextureSize(64, 32);
      sidefin002.mirror = true;
      setRotation(sidefin002, 0F, -0.4461411F, 0F);
      topfin001 = new ModelRenderer(this, 32, 7);
      topfin001.addBox(0F, -3F, 0F, 0, 3, 4);
      topfin001.setRotationPoint(0.5F, 20.5F, -2F);
      topfin001.setTextureSize(64, 32);
      topfin001.mirror = true;
      setRotation(topfin001, 0F, 0F, 0F);
      bottomfin001 = new ModelRenderer(this, 20, 0);
      bottomfin001.addBox(0F, -1F, 0F, 0, 3, 3);
      bottomfin001.setRotationPoint(0.5F, 21F, 4.5F);
      bottomfin001.setTextureSize(64, 32);
      bottomfin001.mirror = true;
      setRotation(bottomfin001, 0F, 0F, 0F);
  }
  
  public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)
  {
    setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
    body001.render(par7);
    mouth001.render(par7);
    top001.render(par7);
    body002.render(par7);
    body003.render(par7);
    mouth002.render(par7);
    body004.render(par7);
    body005.render(par7);
    body006.render(par7);
    body007.render(par7);
    sidefin001.render(par7);
    sidefin002.render(par7);
    topfin001.render(par7);
    bottomfin001.render(par7);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float par2, float par3, float par4, float par5, float par6, Entity par7Entity) {
  
  

  }
  
}

 

Render Class:

 

package com.MagZAquaticLifeExperience.common.render;

import com.MagZAquaticLifeExperience.common.entity.EntityFishMob;
import com.MagZAquaticLifeExperience.common.model.ModelFish;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.ResourceLocation;

public class RenderFish extends RenderLiving {
private static final ResourceLocation EntityTexture = new ResourceLocation("magzaquaticlifeexperience:/textures/mobs/Fish.png");

protected ModelFish model;

public RenderFish(ModelBase par1ModelBase, float par2) {
	super(par1ModelBase, par2);
	model = ((ModelFish)mainModel);
}

public void RenderFish(EntityFishMob entity, double par2, double par4, double par6, float par8, float par9) {
	super.doRender(entity, par2, par4, par6, par8, par9);
}

public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9) {
	RenderFish((EntityFishMob)par1EntityLiving, par2, par4, par6, par8, par9);
}

public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {
	RenderFish((EntityFishMob)par1Entity, par2, par4, par6, par8, par9);
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return EntityTexture;
}

}

 

Entity Class:

 

package com.MagZAquaticLifeExperience.common.entity;

import com.MagZAquaticLifeExperience.common.MagzAquaticLifeExperience;

import net.minecraft.block.material.Material;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.passive.EntityWaterMob;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityFishMob extends EntityWaterMob {

    private float randomMotionSpeed;
    private float randomMotionVecX;
    private float randomMotionVecY;
    private float randomMotionVecZ;

public EntityFishMob(World par1World) {
	super(par1World);
	 this.setSize(1.0F, 0.5F);
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
    this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(2.0D);
}

    protected boolean canTriggerWalking()
    {
        return false;
    }
    
    public boolean isInWater()
    {
        return this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.6000000238418579D, 0.0D), Material.water, this);
    }
    
    public void onLivingUpdate()
    {
        super.onLivingUpdate();

        if (this.isInWater())
        {
            float f= 0;

                if ((double)f > 0.75D)
                {
                    this.randomMotionSpeed = 1.0F;
                }
                else
                {
                }
            }
            else
            {
                this.randomMotionSpeed *= 0.9F;
            }

            if (!this.worldObj.isRemote)
            {
                this.motionX = (double)(this.randomMotionVecX * this.randomMotionSpeed);
                this.motionY = (double)(this.randomMotionVecY * this.randomMotionSpeed);
                this.motionZ = (double)(this.randomMotionVecZ * this.randomMotionSpeed);
            }

            float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);

        }
        
        {

            if (!this.worldObj.isRemote)
            {
                this.motionX = 0.0D;
                this.motionY -= 0.08D;
                this.motionY *= 0.9800000190734863D;
                this.motionZ = 0.0D;
            }

        }
    
    
    public void moveEntityWithHeading(float par1, float par2)
    {
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
    }
    
    protected void updateEntityActionState()
    {
        ++this.entityAge;

        if (this.entityAge > 100)
        {
            this.randomMotionVecX = this.randomMotionVecY = this.randomMotionVecZ = 0.0F;
        }
        else if (this.rand.nextInt(50) == 0 || !this.inWater || this.randomMotionVecX == 0.0F && this.randomMotionVecY == 0.0F && this.randomMotionVecZ == 0.0F)
        {
            float f = this.rand.nextFloat() * (float)Math.PI * 2.0F;
            this.randomMotionVecX = MathHelper.cos(f) * 0.2F;
            this.randomMotionVecY = -0.1F + this.rand.nextFloat() * 0.2F;
            this.randomMotionVecZ = MathHelper.sin(f) * 0.2F;
        }

        this.despawnEntity();
    }
    
    public boolean getCanSpawnHere()
    {
        return this.posY > 45.0D && this.posY < 63.0D && super.getCanSpawnHere();
    }
    
    protected void dropFewItems(boolean par1, int par2)
    {
        int j = this.rand.nextInt(3 + par2) + 1;

        for (int k = 0; k < j; ++k)
        {
            this.entityDropItem(new ItemStack(MagzAquaticLifeExperience.SaltwaterFish, 1, 0), 0.0F);
        }
    }


    protected Item getDropItem()
    {
        return Item.getItemById(349);
    }

protected String getLivingSound() {
	return "";
}

protected String getDeathSound() {
	return "";
}

}

 

ProxyClient Class:

 

package com.MagZAquaticLifeExperience.common.lib;


import com.MagZAquaticLifeExperience.common.entity.EntityFishMob;
import com.MagZAquaticLifeExperience.common.model.ModelFish;
import com.MagZAquaticLifeExperience.common.render.RenderFish;

import cpw.mods.fml.client.registry.RenderingRegistry;


public class ProxyClient extends ProxyCommon{

public void RegisterInformation() {
	RenderingRegistry.registerEntityRenderingHandler(EntityFishMob.class, new RenderFish(new ModelFish(), 0.2F));
}
}

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

bump  :(

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

Because I didn't have the code inserts so the post was extremly long.

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

I already put it in my client proxy. Do you have to put it in the common proxy or not?

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

that is just the part for rendering the mob, but you forgot the part where you register the entity itself with an id

 

Yeah, it is interesting but if you don't register an entity it can do some funky stuff.  Surprisingly you can still spawn entities without registering them, so sometimes it is hard to realize you made the mistake of not spawning them.

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

Posted

Is this what your talking about?

 

private static int startEntityId = 300;

 

Because if it is, then that's not the problem :P

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

Is this what your talking about?

 

private static int startEntityId = 300;

 

Because if it is, then that's not the problem :P

 

No:

https://github.com/SanAndreasP/ClaySoldiersMod/blob/master/java/de/sanandrew/mods/claysoldiers/util/ModEntities.java#L36-L45

 

Also I register them inside init.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

this is what I meant, i'm working on 1.6.4 so it might be different in 1.7

 

EntityRegistry.registerGlobalEntityID(EntityThrowingAxe.class, "ThrowingAxe", EntityRegistry.findGlobalUniqueEntityId());

EntityRegistry.registerModEntity(EntityThrowingAxe.class, "ThrowingAxe", 0, instance, 128, 1, true);

Posted

this is what I meant, i'm working on 1.6.4 so it might be different in 1.7

 

EntityRegistry.registerGlobalEntityID(EntityThrowingAxe.class, "ThrowingAxe", EntityRegistry.findGlobalUniqueEntityId());

EntityRegistry.registerModEntity(EntityThrowingAxe.class, "ThrowingAxe", 0, instance, 128, 1, true);

 

You can (and should) omit the line with the global entity ID.

Even if you want to register your mobs to the spawn eggs, you should make your own, mimicing the vanilla ones; there are ca. 32000 item IDs available.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Well I have this in my main mod class:

 

	private static int startEntityId = 300;	

                EntityRegistry.registerGlobalEntityID(EntityFishMob.class, "Fish", EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.addSpawn(EntityFishMob.class, 10, 2, 4, EnumCreatureType.waterCreature);
	EntityRegistry.findGlobalUniqueEntityId();
	registerEntityEgg(EntityFishMob.class, 0x0033FF, 0x003399);

 

That and this to register a unique entity id and to register an entity egg:

 

	private void registerEntityEgg(Class<? extends Entity> entity, int primaryColor, int secondaryColor) {
	int id = getUniqueEntityId();
	EntityList.IDtoClassMapping.put(id, entity);
	EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));
}


private int getUniqueEntityId() {
	do {
		startEntityId++;
	}
	while(EntityList.getStringFromID(startEntityId) != null);
	return startEntityId++;
}

}

 

Can anyone tell me what is wrong?

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

again another bump  :(.

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

but doesn't this automatically set a new id for the entity if its been taken already?

 

registerGlobalEntityId registers your entity to the vanilla ID list, which is limited (max. 255 entities)

That's where registerModEntity exists, the ID you provide there is mod-specific, beginning with 0 and counting up for each entity.

 

If you want to make a mob spawn egg, make your own and mimic the function of the vanilla one.

 

 

	private static int startEntityId = 300;	

                EntityRegistry.registerGlobalEntityID(EntityFishMob.class, "Fish", EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.addSpawn(EntityFishMob.class, 10, 2, 4, EnumCreatureType.waterCreature);
	EntityRegistry.findGlobalUniqueEntityId();
	registerEntityEgg(EntityFishMob.class, 0x0033FF, 0x003399);

 

EntityRegistry.registerGlobalEntityID(EntityFishMob.class, "Fish", EntityRegistry.findGlobalUniqueEntityId());

Again: you shouldn't use this, use registerModEntity

EntityRegistry.findGlobalUniqueEntityId();

This line is completely useless and just wastes one of the limited entity IDs

registerEntityEgg(EntityFishMob.class, 0x0033FF, 0x003399);

As stated previously, make your own spawner egg, it's not that hard.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I'm still having trouble understanding this. My mob won't move and it dies after a certain amount of time becuase the entity id isn't registered? Or what? I'm completly lost. I think if I know whats wrong, i'll understand my situation a little bit more.

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

I'm still having trouble understanding this. My mob won't move and it dies after a certain amount of time becuase the entity id isn't registered? Or what? I'm completly lost. I think if I know whats wrong, i'll understand my situation a little bit more.

 

Nothing to do with any entity ID, something in your entity code is wrong, I can't tell what, though.

Maybe see what the EntitySqid class looks like?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I've been looking around in the entity squid class and copying and pasting important info and changing it up a little bit. But my mob still doesn't do anything and it still dies even in water.

 

Here is my entity class:

 

package com.MagZAquaticLifeExperience.common.entity;

import com.MagZAquaticLifeExperience.common.MagzAquaticLifeExperience;

import net.minecraft.block.material.Material;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.passive.EntityWaterMob;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityFishMob extends EntityWaterMob {

    private float randomMotionSpeed;
    private float randomMotionVecX;
    private float randomMotionVecY;
    private float randomMotionVecZ;

public EntityFishMob(World par1World) {
	super(par1World);
	 this.setSize(1.0F, 0.5F);
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
    this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(2.0D);
}

    protected boolean canTriggerWalking()
    {
        return false;
    }
    
    public boolean isInWater()
    {
        return this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.6000000238418579D, 0.0D), Material.water, this);
    }
    
    public void onLivingUpdate()
    {
        super.onLivingUpdate();

        if (this.isInWater())
        {
            float f= 0;

                if ((double)f > 0.75D)
                {
                    this.randomMotionSpeed = 1.0F;
                }
                else
                {
                }
            }
            else
            {
                this.randomMotionSpeed *= 0.9F;
            }

            if (!this.worldObj.isRemote)
            {
                this.motionX = (double)(this.randomMotionVecX * this.randomMotionSpeed);
                this.motionY = (double)(this.randomMotionVecY * this.randomMotionSpeed);
                this.motionZ = (double)(this.randomMotionVecZ * this.randomMotionSpeed);
            }

            float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);

        }
        
        {

            if (!this.worldObj.isRemote)
            {
                this.motionX = 0.0D;
                this.motionY -= 0.08D;
                this.motionY *= 0.9800000190734863D;
                this.motionZ = 0.0D;
            }

        }
    
    
    public void moveEntityWithHeading(float par1, float par2)
    {
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
    }
    
    protected void updateEntityActionState()
    {
        ++this.entityAge;

        if (this.entityAge > 100)
        {
            this.randomMotionVecX = this.randomMotionVecY = this.randomMotionVecZ = 0.0F;
        }
        else if (this.rand.nextInt(50) == 0 || !this.inWater || this.randomMotionVecX == 0.0F && this.randomMotionVecY == 0.0F && this.randomMotionVecZ == 0.0F)
        {
            float f = this.rand.nextFloat() * (float)Math.PI * 2.0F;
            this.randomMotionVecX = MathHelper.cos(f) * 0.2F;
            this.randomMotionVecY = -0.1F + this.rand.nextFloat() * 0.2F;
            this.randomMotionVecZ = MathHelper.sin(f) * 0.2F;
        }

        this.despawnEntity();
    }
    
    public boolean getCanSpawnHere()
    {
        return this.posY > 45.0D && this.posY < 63.0D && super.getCanSpawnHere();
    }
    
    protected void dropFewItems(boolean par1, int par2)
    {
        int j = this.rand.nextInt(3 + par2) + 1;

        for (int k = 0; k < j; ++k)
        {
            this.entityDropItem(new ItemStack(MagzAquaticLifeExperience.SaltwaterFish, 1, 0), 0.0F);
        }
    }


    protected Item getDropItem()
    {
        return Item.getItemById(349);
    }

protected String getLivingSound() {
	return "";
}

protected String getDeathSound() {
	return "";
}

}

 

 

Is there a specific part i'm missing in my entityfishmob class that i don't have that the entitySquid class has? or what? Please help.

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

Anyone?

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

I guess i'm back to bumping  :(. Can anyone help me? I've been trying all day to try and get this to work, I would search around the minecraft forge forums and find nothing. I would look deeply into any code that involves underwater entity methods and or the entitysquid class and end up with no success. I'm not a noob(even though I kinda sound like one), I know how to code with java, but I have no experience on how underwater mobs work. So even if you don't know how to fix this, can you please point me out in some direction to learning how water mobs work? Any help would be appretiated.  :)

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

1. Don't post Mojang code! It's illegal and also we can just look that up ourselves.

2. Add @Override to all your methods you intend to override, it helps you see if you really override the method and not just declared a new version of it which never gets called.

3. return true in isInWater() and see if it still dies.

4. A bump after 4 hours, really?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

It's illegal to post Mojang code? woops. Sorry if I seem desperate, but thanks for the reply!

Hello everyone! I'm the developer and owner of a mod called MagZ Aquatic Life Experience. Right now it's being worked on, but when it's released, check it out!

 

--[Also Check Out My Website!]--

Posted

It's illegal to post Mojang code? woops. Sorry if I seem desperate, but thanks for the reply!

 

Well, then please edit your post and remove the EntitySquid and EntityWaterMob code.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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