Problème de Model avec un nouveau bateau

gbreuil1

Expert minecraftien
23 Juillet 2011
422
9
57
Voilà je suis en train de créer un nouveau bateau pour mon gros mod 'DarkWorld' qui est pour l'instant inclus dans un petit mod.
J'ai créer l'item du bateau, la class mod central, le render du bateau, le model (!) du bateau et l'entity du bateau.
Donc tout ce qu'il faut quand j'ai copié le code de base (oui je sais c'était TRÈS dur et c'était SOULANT avec plein de bugs ^^ ).
J'ai fait les deux textures : une pour l'item et une pour l’entité.
Le mod ne présente aucune erreur dans éclipse, j'ai mis modloader et supprimé META-INF et j'ai bien rajouté les textures.
Le jeu démarre normalement et le monde aussi.
L'item présente bien la texture quand je démarre et il y a son nom.
Voilà mais malgré tout quand je fait clique droit sur le sol ou dans l'eau, il y a mon bateau mais il est...invisible.
Ça m'as fait bizarre quand je suis monté dans le bateau invisible (on flotte a 2cm du sol :o ).
Donc voilà je vous montre mon code ET mes textures (c'est peut-être de la que vient le bug) pour m'aider à comprendre ce bug.
Attention par contre.....le code est TRÈS long.

le class principal mod_zarboat:

Code:
package net.minecraft.src;

import java.util.Map;

public class mod_zarboat extends BaseMod
{
public mod_zarboat()
{
    ModLoader.AddRecipe(new ItemStack(zarBoat, 1), new Object[]
    {"# #","###", Character.valueOf('#'), Block.netherrack});
    ModLoader.AddRecipe(new ItemStack(zarBoat, 1), new Object[]
            {"#", Character.valueOf('#'), Block.dirt});
    ModLoader.RegisterEntityID(EntityZarBoat.class, "EntityZarBoat ", ModLoader.getUniqueEntityId());
    ModLoader.AddName(zarBoat, "ZarBoat");
}

public static final int zarBoatIcon = ModLoader.addOverride("/gui/items.png", "/mod_zarboat/item_zarboat.png");
public static final Item zarBoat = (new ItemZarBoat(1700)).setItemName("Zarboat").setMaxStackSize(1).setIconIndex(zarBoatIcon);

public void AddRenderer(Map paramMap)
{
 paramMap.put(EntityZarBoat.class, new RenderZarBoat());
}

public String getVersion() 
{
    return "1.1";
}

public void load() 
{
    
}
}

L'item:

Code:
package net.minecraft.src;

import java.util.List;

public class ItemZarBoat extends Item
{
    public ItemZarBoat(int i)
    {
        super(i);
        maxStackSize = 1;
    }

    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
    {
        float f = 1.0F;
        float f1 = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f;
        float f2 = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
        double d = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * (double)f;
        double d1 = (entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * (double)f + 1.6200000000000001D) - (double)entityplayer.yOffset;
        double d2 = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * (double)f;
        Vec3D vec3d = Vec3D.createVector(d, d1, d2);
        float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
        float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
        float f5 = -MathHelper.cos(-f1 * 0.01745329F);
        float f6 = MathHelper.sin(-f1 * 0.01745329F);
        float f7 = f4 * f5;
        float f8 = f6;
        float f9 = f3 * f5;
        double d3 = 5D;
        Vec3D vec3d1 = vec3d.addVector((double)f7 * d3, (double)f8 * d3, (double)f9 * d3);
        MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do(vec3d, vec3d1, true);
        if (movingobjectposition == null)
        {
            return itemstack;
        }
        Vec3D vec3d2 = entityplayer.getLook(f);
        boolean flag = false;
        float f10 = 1.0F;
        List list = world.getEntitiesWithinAABBExcludingEntity(entityplayer, entityplayer.boundingBox.addCoord(vec3d2.xCoord * d3, vec3d2.yCoord * d3, vec3d2.zCoord * d3).expand(f10, f10, f10));
        for (int l = 0; l < list.size(); l++)
        {
            Entity entity = (Entity)list.get(l);
            if (!entity.canBeCollidedWith())
            {
                continue;
            }
            float f11 = entity.getCollisionBorderSize();
            AxisAlignedBB axisalignedbb = entity.boundingBox.expand(f11, f11, f11);
            if (axisalignedbb.isVecInside(vec3d))
            {
                flag = true;
            }
        }

        if (flag)
        {
            return itemstack;
        }
        if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
        {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            if (!world.multiplayerWorld)
            {
                if (world.getBlockId(i, j, k) == Block.snow.blockID)
                {
                    j--;
                }
                world.spawnEntityInWorld(new EntityZarBoat(world, (float)i + 0.5F, (float)j + 1.0F, (float)k + 0.5F));
            }
            if (!entityplayer.capabilities.depleteBuckets)
            {
                itemstack.stackSize--;
            }
        }
        return itemstack;
    }
}

Le render:
Code:
package net.minecraft.src;

import org.lwjgl.opengl.GL11;

public class RenderZarBoat extends Render
{

    public RenderZarBoat()
    {
        shadowSize = 0.5F;
    }

    public void renderZarBoat(EntityZarBoat entityzarboat, double d, double d1, double d2,
            float f, float f1)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)d, (float)d1, (float)d2);
        GL11.glRotatef(180F - f, 0.0F, 1.0F, 0.0F);
        float f2 = (float)entityzarboat.getTimeSinceHit() - f1;
        float f3 = (float)entityzarboat.getDamageTaken() - f1;
        if (f3 < 0.0F)
        {
            f3 = 0.0F;
        }
        if (f2 > 0.0F)
        {
            GL11.glRotatef(((MathHelper.sin(f2) * f2 * f3) / 10F) * (float)entityzarboat.getForwardDirection(), 1.0F, 0.0F, 0.0F);
        }
        loadTexture("/terrain.png");
        float f4 = 0.75F;
        GL11.glScalef(f4, f4, f4);
        GL11.glScalef(1.0F / f4, 1.0F / f4, 1.0F / f4);
        loadTexture("/mod_zarboat/zarboat.png");
        GL11.glScalef(-1F, -1F, 1.0F);
        ModelZarBoat.RenderZarBoat(entityzarboat, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
    }

    public void doRender(Entity entity, double d, double d1, double d2,
            float f, float f1)
    {
        renderZarBoat((EntityZarBoat)entity, d, d1, d2, f, f1);
    }
}

Le model (regardez bien celui là svp):

Code:
package net.minecraft.src;

public class ModelZarBoat extends ModelBase
{
    public ModelRenderer boatSides[];

    public ModelZarBoat()
    {
        boatSides = new ModelRenderer[5];
        boatSides[0] = new ModelRenderer(this, 0, 8);
        boatSides[1] = new ModelRenderer(this, 0, 0);
        boatSides[2] = new ModelRenderer(this, 0, 0);
        boatSides[3] = new ModelRenderer(this, 0, 0);
        boatSides[4] = new ModelRenderer(this, 0, 0);
        byte byte0 = 24;
        byte byte1 = 6;
        byte byte2 = 20;
        byte byte3 = 4;
        boatSides[0].addBox(-byte0 / 2, -byte2 / 2 + 2, -3F, byte0, byte2 - 4, 4, 0.0F);
        boatSides[0].setRotationPoint(0.0F, 0 + byte3, 0.0F);
        boatSides[1].addBox(-byte0 / 2 + 2, -byte1 - 1, -1F, byte0 - 4, byte1, 2, 0.0F);
        boatSides[1].setRotationPoint(-byte0 / 2 + 1, 0 + byte3, 0.0F);
        boatSides[2].addBox(-byte0 / 2 + 2, -byte1 - 1, -1F, byte0 - 4, byte1, 2, 0.0F);
        boatSides[2].setRotationPoint(byte0 / 2 - 1, 0 + byte3, 0.0F);
        boatSides[3].addBox(-byte0 / 2 + 2, -byte1 - 1, -1F, byte0 - 4, byte1, 2, 0.0F);
        boatSides[3].setRotationPoint(0.0F, 0 + byte3, -byte2 / 2 + 1);
        boatSides[4].addBox(-byte0 / 2 + 2, -byte1 - 1, -1F, byte0 - 4, byte1, 2, 0.0F);
        boatSides[4].setRotationPoint(0.0F, 0 + byte3, byte2 / 2 - 1);
        boatSides[0].rotateAngleX = 1.570796F;
        boatSides[1].rotateAngleY = 4.712389F;
        boatSides[2].rotateAngleY = 1.570796F;
        boatSides[3].rotateAngleY = 3.141593F;
    }


    public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
    {
        for (int i = 0; i < 5; i++)
        {
            boatSides[i].render(f5);
        }
    }

    public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
    {
    }

    public static void RenderZarBoat(EntityZarBoat entityzarboat, float f,float g, float h, float i, float j, float k) 
    {
        
    }
}

Et enfin le entity:
Code:
package net.minecraft.src;

import java.util.List;
import java.util.Random;

public class EntityZarBoat extends Entity
{
    private int boatPosRotationIncrements;
    private double boatX;
    private double boatY;
    private double boatZ;
    private double boatYaw;
    private double boatPitch;
    private double velocityX;
    private double velocityY;
    private double velocityZ;

    public EntityZarBoat(World world)
    {
        super(world);
        preventEntitySpawning = true;
        setSize(1.5F, 0.6F);
        yOffset = height / 2.0F;
    }

    protected boolean canTriggerWalking()
    {
        return false;
    }

    protected void entityInit()
    {
        dataWatcher.addObject(17, new Integer(0));
        dataWatcher.addObject(18, new Integer(1));
        dataWatcher.addObject(19, new Integer(0));
    }

    public AxisAlignedBB getCollisionBox(Entity entity)
    {
        return entity.boundingBox;
    }

    public AxisAlignedBB getBoundingBox()
    {
        return boundingBox;
    }

    public boolean canBePushed()
    {
        return true;
    }

    public EntityZarBoat(World world, double d, double d1, double d2)
    {
        this(world);
        setPosition(d, d1 + (double)yOffset, d2);
        motionX = 0.0D;
        motionY = 0.0D;
        motionZ = 0.0D;
        prevPosX = d;
        prevPosY = d1;
        prevPosZ = d2;
    }

    public double getMountedYOffset()
    {
        return (double)height * 0.0D - 0.30000001192092896D;
    }
    
    public boolean attackEntityFrom(DamageSource damagesource, int i)
    {
        if (worldObj.multiplayerWorld || isDead)
        {
            return true;
        }
        setForwardDirection(-getForwardDirection());
        setTimeSinceHit(10);
        setDamageTaken(getDamageTaken() + i * 10);
        setBeenAttacked();
        if (getDamageTaken() > 40)
        {
            if (riddenByEntity != null)
            {
                riddenByEntity.mountEntity(this);
            }
            for (int j = 0; j < 3; j++)
            {
                
            }

            setEntityDead();
        }
        return true;
    }

    public void performHurtAnimation()
    {
        setForwardDirection(-getForwardDirection());
        setTimeSinceHit(10);
        setDamageTaken(getDamageTaken() * 11);
    }

    public boolean canBeCollidedWith()
    {
        return !isDead;
    }

    public void setPositionAndRotation2(double d, double d1, double d2, float f,
            float f1, int i)
    {
        boatX = d;
        boatY = d1;
        boatZ = d2;
        boatYaw = f;
        boatPitch = f1;
        boatPosRotationIncrements = i + 4;
        motionX = velocityX;
        motionY = velocityY;
        motionZ = velocityZ;
    }

    public void setVelocity(double d, double d1, double d2)
    {
        velocityX = motionX = d;
        velocityY = motionY = d1;
        velocityZ = motionZ = d2;
    }

    public void onUpdate()
    {
        super.onUpdate();
        if (getTimeSinceHit() > 0)
        {
            setTimeSinceHit(getTimeSinceHit() - 1);
        }
        if (getDamageTaken() > 0)
        {
            setDamageTaken(getDamageTaken() - 1);
        }
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;
        int i = 5;
        double d = 0.0D;
        for (int j = 0; j < i; j++)
        {
            double d2 = (boundingBox.minY + ((boundingBox.maxY - boundingBox.minY) * (double)(j + 0)) / (double)i) - 0.125D;
            double d8 = (boundingBox.minY + ((boundingBox.maxY - boundingBox.minY) * (double)(j + 1)) / (double)i) - 0.125D;
            AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBoxFromPool(boundingBox.minX, d2, boundingBox.minZ, boundingBox.maxX, d8, boundingBox.maxZ);
            if (worldObj.isAABBInMaterial(axisalignedbb, Material.water))
            {
                d += 1.0D / (double)i;
            }
        }

        double d1 = Math.sqrt(motionX * motionX + motionZ * motionZ);
        if (d1 > 0.14999999999999999D)
        {
            double d3 = Math.cos(((double)rotationYaw * 3.1415926535897931D) / 180D);
            double d9 = Math.sin(((double)rotationYaw * 3.1415926535897931D) / 180D);
            for (int i1 = 0; (double)i1 < 1.0D + d1 * 60D; i1++)
            {
                double d16 = rand.nextFloat() * 2.0F - 1.0F;
                double d19 = (double)(rand.nextInt(2) * 2 - 1) * 0.69999999999999996D;
                if (rand.nextBoolean())
                {
                    double d21 = (posX - d3 * d16 * 0.80000000000000004D) + d9 * d19;
                    double d23 = posZ - d9 * d16 * 0.80000000000000004D - d3 * d19;
                    worldObj.spawnParticle("splash", d21, posY - 0.125D, d23, motionX, motionY, motionZ);
                }
                else
                {
                    double d22 = posX + d3 + d9 * d16 * 0.69999999999999996D;
                    double d24 = (posZ + d9) - d3 * d16 * 0.69999999999999996D;
                    worldObj.spawnParticle("splash", d22, posY - 0.125D, d24, motionX, motionY, motionZ);
                }
            }
        }
        if (worldObj.multiplayerWorld)
        {
            if (boatPosRotationIncrements > 0)
            {
                double d4 = posX + (boatX - posX) / (double)boatPosRotationIncrements;
                double d10 = posY + (boatY - posY) / (double)boatPosRotationIncrements;
                double d13 = posZ + (boatZ - posZ) / (double)boatPosRotationIncrements;
                double d17;
                for (d17 = boatYaw - (double)rotationYaw; d17 < -180D; d17 += 360D) { }
                for (; d17 >= 180D; d17 -= 360D) { }
                rotationYaw += d17 / (double)boatPosRotationIncrements;
                rotationPitch += (boatPitch - (double)rotationPitch) / (double)boatPosRotationIncrements;
                boatPosRotationIncrements--;
                setPosition(d4, d10, d13);
                setRotation(rotationYaw, rotationPitch);
            }
            else
            {
                double d5 = posX + motionX;
                double d11 = posY + motionY;
                double d14 = posZ + motionZ;
                setPosition(d5, d11, d14);
                if (onGround)
                {
                    motionX *= 0.5D;
                    motionY *= 0.5D;
                    motionZ *= 0.5D;
                }
                motionX *= 0.99000000953674316D;
                motionY *= 0.94999998807907104D;
                motionZ *= 0.99000000953674316D;
            }
            return;
        }
        if (d < 1.0D)
        {
            double d6 = d * 2D - 1.0D;
            motionY += 0.039999999105930328D * d6;
        }
        else
        {
            if (motionY < 0.0D)
            {
                motionY /= 2D;
            }
            motionY += 0.0070000002160668373D;
        }
        if (riddenByEntity != null)
        {
            motionX += riddenByEntity.motionX * 0.20000000000000001D;
            motionZ += riddenByEntity.motionZ * 0.20000000000000001D;
        }
        double d7 = 0.40000000000000002D;
        if (motionX < -d7)
        {
            motionX = -d7;
        }
        if (motionX > d7)
        {
            motionX = d7;
        }
        if (motionZ < -d7)
        {
            motionZ = -d7;
        }
        if (motionZ > d7)
        {
            motionZ = d7;
        }
        if (onGround)
        {
            motionX *= 0.5D;
            motionY *= 0.5D;
            motionZ *= 0.5D;
        }
        moveEntity(motionX, motionY, motionZ);
        if (isCollidedHorizontally && d1 > 0.20000000000000001D)
        {
            if (!worldObj.multiplayerWorld)
            {
                setEntityDead();
                for (int k = 0; k < 3; k++)
                {
                    dropItemWithOffset(Block.planks.blockID, 1, 0.0F);
                }

                for (int l = 0; l < 2; l++)
                {
                    dropItemWithOffset(Item.stick.shiftedIndex, 1, 0.0F);
                }
            }
        }
        else
        {
            motionX *= 0.99000000953674316D;
            motionY *= 0.94999998807907104D;
            motionZ *= 0.99000000953674316D;
        }
        rotationPitch = 0.0F;
        double d12 = rotationYaw;
        double d15 = prevPosX - posX;
        double d18 = prevPosZ - posZ;
        if (d15 * d15 + d18 * d18 > 0.001D)
        {
            d12 = (float)((Math.atan2(d18, d15) * 180D) / 3.1415926535897931D);
        }
        double d20;
        for (d20 = d12 - (double)rotationYaw; d20 >= 180D; d20 -= 360D) { }
        for (; d20 < -180D; d20 += 360D) { }
        if (d20 > 20D)
        {
            d20 = 20D;
        }
        if (d20 < -20D)
        {
            d20 = -20D;
        }
        rotationYaw += d20;
        setRotation(rotationYaw, rotationPitch);
        List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
        if (list != null && list.size() > 0)
        {
            for (int j1 = 0; j1 < list.size(); j1++)
            {
                Entity entity = (Entity)list.get(j1);
                if (entity != riddenByEntity && entity.canBePushed() && (entity instanceof EntityBoat))
                {
                    entity.applyEntityCollision(this);
                }
            }
        }
        for (int k1 = 0; k1 < 4; k1++)
        {
            int l1 = MathHelper.floor_double(posX + ((double)(k1 % 2) - 0.5D) * 0.80000000000000004D);
            int i2 = MathHelper.floor_double(posY);
            int j2 = MathHelper.floor_double(posZ + ((double)(k1 / 2) - 0.5D) * 0.80000000000000004D);
            if (worldObj.getBlockId(l1, i2, j2) == Block.snow.blockID)
            {
                worldObj.setBlockWithNotify(l1, i2, j2, 0);
            }
        }

        if (riddenByEntity != null && riddenByEntity.isDead)
        {
            riddenByEntity = null;
        }
    }

    public void updateRiderPosition()
    {
        if (riddenByEntity == null)
        {
            return;
        }
        else
        {
            double d = Math.cos(((double)rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
            double d1 = Math.sin(((double)rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
            riddenByEntity.setPosition(posX + d, posY + getMountedYOffset() + riddenByEntity.getYOffset(), posZ + d1);
            return;
        }
    }

    protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
    }

    protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
    }

    public float getShadowSize()
    {
        return 0.0F;
    }

    public boolean interact(EntityPlayer entityplayer)
    {
        if (riddenByEntity != null && (riddenByEntity instanceof EntityPlayer) && riddenByEntity != entityplayer)
        {
            return true;
        }
        if (!worldObj.multiplayerWorld)
        {
            entityplayer.mountEntity(this);
        }
        return true;
    }

    public void setDamageTaken(int i)
    {
        dataWatcher.updateObject(19, Integer.valueOf(i));
    }

    public int getDamageTaken()
    {
        return dataWatcher.getWatchableObjectInt(19);
    }

    public void setTimeSinceHit(int i)
    {
        dataWatcher.updateObject(17, Integer.valueOf(i));
    }

    public int getTimeSinceHit()
    {
        return dataWatcher.getWatchableObjectInt(17);
    }

    public void setForwardDirection(int i)
    {
        dataWatcher.updateObject(18, Integer.valueOf(i));
    }

    public int getForwardDirection()
    {
        return dataWatcher.getWatchableObjectInt(18);
    }
}

Et les deux textures:
item_zarboat: http://imageshack.us/photo/my-images/17/itemzarboat.png
zarboat:http://imageshack.us/photo/my-images/18/zarboat.png
Donc voilà bonne chance pour m'aider ;)
Vous pouvez me répondre aussi sur IronCraft.