MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Problèmes avec un véhicule

    Planifier Épinglé Verrouillé Déplacé Résolu 1.9.x et 1.10.x
    1.9.4
    20 Messages 4 Publieurs 2.9k Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • AxaurusA Hors-ligne
      Axaurus
      dernière édition par

      Salut
      Ca marche bien. Dans la fonction :

      @Override
         public void updatePassenger(Entity passenger)
         {
             if (this.isPassenger(passenger))
             {
                 float f = 0.0F;
                 float f1 = (float)((this.isDead ? 0.009999999776482582D : this.getMountedYOffset()) + passenger.getYOffset() + 1.15);
      
                 if (this.getPassengers().size() == 1)
                 {
                     int i = this.getPassengers().indexOf(passenger);
      
                     if (i == 0)
                     {
                         f = -0.9F;
                     }
                     else
                     {
                         f = -0.6F;
                     }
      
                     if (passenger instanceof EntityAnimal)
                     {
                         f = (float)((double)f + 0.2D);
                     }
                 }
      
                 Vec3d vec3d = (new Vec3d((double)f, 0.0D, 0.0D)).rotateYaw(-this.rotationYaw * 0.017453292F - ((float)Math.PI / 2F));
                 passenger.setPosition(this.posX + vec3d.xCoord, this.posY + (double)f1 - 0.5, this.posZ + vec3d.zCoord);
      
                 passenger.rotationYaw += this.deltaRotation;
                 passenger.setRotationYawHead(passenger.getRotationYawHead() + this.deltaRotation);
                 this.applyYawToEntity(passenger);
      
                 if (passenger instanceof EntityAnimal && this.getPassengers().size() > 1)
                 {
                     int j = passenger.getEntityId() % 2 == 0 ? 90 : 270;
                     passenger.setRenderYawOffset(((EntityAnimal)passenger).renderYawOffset + (float)j);
                     passenger.setRotationYawHead(passenger.getRotationYawHead() + (float)j);
                 }
             }
         }
      ``` j'ai modifié le f dans ```java
      if (i == 0)
                     {
                         f = -0.9F;
                     }
      
      

      Merci à vous trois 🙂

      1 réponse Dernière réponse Répondre Citer 0
      • AxaurusA Hors-ligne
        Axaurus
        dernière édition par

        Re
        Désolé de vous re-déranger avec ce sujet, mais j’ai un autre problème qui concerne encore le traîneau. Ce problème est plutôt problématique
        En fait, je ne peux pas du tout bouger avec. Que je sois à terre ou dans l’eau, je ne peux rien faire. Pourtant, ce qui est bizarre, c’est que même en copiant/collant le code du bateau, ça ne marche pas. Il doit y avoir un autre truc qui fait déplacer la bâteau, mais je sais pas quoi.

        Voilà l’entité de mon traîneau :

        package This_is_Christmas.Entity;
        
        import java.util.List;
        
        import javax.annotation.Nullable;
        
        import com.google.common.collect.Lists;
        
        import This_is_Christmas.CreateItems;
        import net.minecraft.block.BlockLiquid;
        import net.minecraft.block.BlockPlanks;
        import net.minecraft.block.material.Material;
        import net.minecraft.block.state.IBlockState;
        import net.minecraft.entity.Entity;
        import net.minecraft.entity.EntityLivingBase;
        import net.minecraft.entity.passive.EntityAnimal;
        import net.minecraft.entity.passive.EntityWaterMob;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.init.Blocks;
        import net.minecraft.init.Items;
        import net.minecraft.item.Item;
        import net.minecraft.item.ItemStack;
        import net.minecraft.nbt.NBTTagCompound;
        import net.minecraft.network.datasync.DataParameter;
        import net.minecraft.network.datasync.DataSerializers;
        import net.minecraft.network.datasync.EntityDataManager;
        import net.minecraft.network.play.client.CPacketSteerBoat;
        import net.minecraft.util.DamageSource;
        import net.minecraft.util.EntityDamageSourceIndirect;
        import net.minecraft.util.EntitySelectors;
        import net.minecraft.util.EnumFacing;
        import net.minecraft.util.EnumHand;
        import net.minecraft.util.math.AxisAlignedBB;
        import net.minecraft.util.math.BlockPos;
        import net.minecraft.util.math.MathHelper;
        import net.minecraft.util.math.Vec3d;
        import net.minecraft.world.IBlockAccess;
        import net.minecraft.world.World;
        import net.minecraftforge.fml.relauncher.Side;
        import net.minecraftforge.fml.relauncher.SideOnly;
        
        public class EntitySleigh extends Entity
        {
           private static final DataParameter <integer>TIME_SINCE_HIT = EntityDataManager.<integer>createKey(EntitySleigh.class, DataSerializers.VARINT);
           private static final DataParameter <integer>FORWARD_DIRECTION = EntityDataManager.<integer>createKey(EntitySleigh.class, DataSerializers.VARINT);
           private static final DataParameter <float>DAMAGE_TAKEN = EntityDataManager.<float>createKey(EntitySleigh.class, DataSerializers.FLOAT);
           private static final DataParameter <integer>BOAT_TYPE = EntityDataManager.<integer>createKey(EntitySleigh.class, DataSerializers.VARINT);
           private static final DataParameter<boolean>[] DATA_ID_PADDLE = new DataParameter[] {EntityDataManager.createKey(EntitySleigh.class, DataSerializers.BOOLEAN), EntityDataManager.createKey(EntitySleigh.class, DataSerializers.BOOLEAN)};
           private float[] paddlePositions;
           /** How much of current speed to retain. Value zero to one. */
           private float momentum;
           private float outOfControlTicks;
           private float deltaRotation;
           private int lerpSteps;
           private double boatPitch;
           private double lerpY;
           private double lerpZ;
           private double boatYaw;
           private double lerpXRot;
           private boolean leftInputDown;
           private boolean rightInputDown;
           private boolean forwardInputDown;
           private boolean backInputDown;
           private double waterLevel;
           /**
            * How much the boat should glide given the slippery blocks it's currently gliding over.
            * Halved every tick.
            */
           private float boatGlide;
           private EntitySleigh.Status status;
           private EntitySleigh.Status previousStatus;
           private double lastYd;
        
           public EntitySleigh(World worldIn)
           {
               super(worldIn);
               this.paddlePositions = new float[2];
               this.preventEntitySpawning = true;
               this.setSize(1.375F, 0.5625F);
           }
        
           public EntitySleigh(World worldIn, double x, double y, double z)
           {
               this(worldIn);
               this.setPosition(x, y, z);
               this.motionX = 0.0D;
               this.motionY = 0.0D;
               this.motionZ = 0.0D;
               this.prevPosX = x;
               this.prevPosY = y;
               this.prevPosZ = z;
           }
        
           /**
            * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
            * prevent them from trampling crops
            */
           protected boolean canTriggerWalking()
           {
               return false;
           }
        
           protected void entityInit()
           {
               this.dataManager.register(TIME_SINCE_HIT, Integer.valueOf(0));
               this.dataManager.register(FORWARD_DIRECTION, Integer.valueOf(1));
               this.dataManager.register(DAMAGE_TAKEN, Float.valueOf(0.0F));
               this.dataManager.register(BOAT_TYPE, Integer.valueOf(EntitySleigh.Type.OAK.ordinal()));
        
               for (int i = 0; i < DATA_ID_PADDLE.length; ++i)
               {
                   this.dataManager.register(DATA_ID_PADDLE*, Boolean.valueOf(false));
               }
           }
        
           /**
            * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
            * pushable on contact, like boats or minecarts.
            */
           @Nullable
           public AxisAlignedBB getCollisionBox(Entity entityIn)
           {
               return entityIn.getEntityBoundingBox();
           }
        
           /**
            * Returns the collision bounding box for this entity
            */
           @Nullable
           public AxisAlignedBB getCollisionBoundingBox()
           {
               return this.getEntityBoundingBox();
           }
        
           /**
            * Returns true if this entity should push and be pushed by other entities when colliding.
            */
           public boolean canBePushed()
           {
               return true;
           }
        
           /**
            * Returns the Y offset from the entity's position for any entity riding this one.
            */
           public double getMountedYOffset()
           {
               return -0.1D;
           }
        
           /**
            * Called when the entity is attacked.
            */
           public boolean attackEntityFrom(DamageSource source, float amount)
           {
               if (this.isEntityInvulnerable(source))
               {
                   return false;
               }
               else if (!this.worldObj.isRemote && !this.isDead)
               {
                   if (source instanceof EntityDamageSourceIndirect && source.getEntity() != null && this.isPassenger(source.getEntity()))
                   {
                       return false;
                   }
                   else
                   {
                       this.setForwardDirection(-this.getForwardDirection());
                       this.setTimeSinceHit(10);
                       this.setDamageTaken(this.getDamageTaken() + amount * 10.0F);
                       this.setBeenAttacked();
                       boolean flag = source.getEntity() instanceof EntityPlayer && ((EntityPlayer)source.getEntity()).capabilities.isCreativeMode;
        
                       if (flag || this.getDamageTaken() > 40.0F)
                       {
                               this.dropItemWithOffset(CreateItems.Sleigh, 1, 0.0F);
                           this.setDead();
                       }
        
                       return true;
                   }
               }
               else
               {
                   return true;
               }
           }
        
           /**
            * Applies a velocity to the entities, to push them away from eachother.
            */
           public void applyEntityCollision(Entity entityIn)
           {
               if (entityIn instanceof EntitySleigh)
               {
                   if (entityIn.getEntityBoundingBox().minY < this.getEntityBoundingBox().maxY)
                   {
                       super.applyEntityCollision(entityIn);
                   }
               }
               else if (entityIn.getEntityBoundingBox().minY <= this.getEntityBoundingBox().minY)
               {
                   super.applyEntityCollision(entityIn);
               }
           }
        
           @SideOnly(Side.CLIENT)
           public void performHurtAnimation()
           {
               this.setForwardDirection(-this.getForwardDirection());
               this.setTimeSinceHit(10);
               this.setDamageTaken(this.getDamageTaken() * 11.0F);
           }
        
           /**
            * Returns true if other Entities should be prevented from moving through this Entity.
            */
           public boolean canBeCollidedWith()
           {
               return !this.isDead;
           }
        
           /**
            * Set the position and rotation values directly without any clamping.
            */
           @SideOnly(Side.CLIENT)
           public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
           {
               this.boatPitch = x;
               this.lerpY = y;
               this.lerpZ = z;
               this.boatYaw = (double)yaw;
               this.lerpXRot = (double)pitch;
               this.lerpSteps = 10;
           }
        
           /**
            * Gets the horizontal facing direction of this Entity, adjusted to take specially-treated entity types into
            * account.
            */
           public EnumFacing getAdjustedHorizontalFacing()
           {
               return this.getHorizontalFacing().rotateY();
           }
        
           /**
            * Called to update the entity's position/logic.
            */
           public void onUpdate()
           {
               this.previousStatus = this.status;
               this.status = this.getBoatStatus();
        
               if (this.status != EntitySleigh.Status.UNDER_WATER && this.status != EntitySleigh.Status.UNDER_FLOWING_WATER)
               {
                   this.outOfControlTicks = 0.0F;
               }
               else
               {
                   ++this.outOfControlTicks;
               }
        
               if (!this.worldObj.isRemote && this.outOfControlTicks >= 60.0F)
               {
                   this.removePassengers();
               }
        
               if (this.getTimeSinceHit() > 0)
               {
                   this.setTimeSinceHit(this.getTimeSinceHit() - 1);
               }
        
               if (this.getDamageTaken() > 0.0F)
               {
                   this.setDamageTaken(this.getDamageTaken() - 1.0F);
               }
        
               this.prevPosX = this.posX;
               this.prevPosY = this.posY;
               this.prevPosZ = this.posZ;
               super.onUpdate();
               this.tickLerp();
        
               if (this.canPassengerSteer())
               {
                   if (this.getPassengers().size() == 0 || !(this.getPassengers().get(0) instanceof EntityPlayer))
                   {
                       this.setPaddleState(false, false);
                   }
        
                   this.updateMotion();
        
                   if (this.worldObj.isRemote)
                   {
                       this.controlBoat();
                       this.worldObj.sendPacketToServer(new CPacketSteerBoat(this.getPaddleState(0), this.getPaddleState(1)));
                   }
        
                   this.moveEntity(this.motionX, this.motionY, this.motionZ);
               }
               else
               {
                   this.motionX = 0.0D;
                   this.motionY = 0.0D;
                   this.motionZ = 0.0D;
               }
        
               for (int i = 0; i <= 1; ++i)
               {
                   if (this.getPaddleState(i))
                   {
                       this.paddlePositions* = (float)((double)this.paddlePositions* + 0.01D);
                   }
                   else
                   {
                       this.paddlePositions* = 0.0F;
                   }
               }
        
               this.doBlockCollisions();
               List <entity>list = this.worldObj.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(0.20000000298023224D, -0.009999999776482582D, 0.20000000298023224D), EntitySelectors.<entity>getTeamCollisionPredicate(this));
        
               if (!list.isEmpty())
               {
                   boolean flag = !this.worldObj.isRemote && !(this.getControllingPassenger() instanceof EntityPlayer);
        
                   for (int j = 0; j < list.size(); ++j)
                   {
                       Entity entity = (Entity)list.get(j);
        
                       if (!entity.isPassenger(this))
                       {
                           if (flag && this.getPassengers().size() < 2 && !entity.isRiding() && entity.width < this.width && entity instanceof EntityLivingBase && !(entity instanceof EntityWaterMob) && !(entity instanceof EntityPlayer))
                           {
                               entity.startRiding(this);
                           }
                           else
                           {
                               this.applyEntityCollision(entity);
                           }
                       }
                   }
               }
           }
        
           private void tickLerp()
           {
               if (this.lerpSteps > 0 && !this.canPassengerSteer())
               {
                   double d0 = this.posX + (this.boatPitch - this.posX) / (double)this.lerpSteps;
                   double d1 = this.posY + (this.lerpY - this.posY) / (double)this.lerpSteps;
                   double d2 = this.posZ + (this.lerpZ - this.posZ) / (double)this.lerpSteps;
                   double d3 = MathHelper.wrapDegrees(this.boatYaw - (double)this.rotationYaw);
                   this.rotationYaw = (float)((double)this.rotationYaw + d3 / (double)this.lerpSteps);
                   this.rotationPitch = (float)((double)this.rotationPitch + (this.lerpXRot - (double)this.rotationPitch) / (double)this.lerpSteps);
                   –this.lerpSteps;
                   this.setPosition(d0, d1, d2);
                   this.setRotation(this.rotationYaw, this.rotationPitch);
               }
           }
        
           public void setPaddleState(boolean p_184445_1_, boolean p_184445_2_)
           {
               this.dataManager.set(DATA_ID_PADDLE[0], Boolean.valueOf(p_184445_1_));
               this.dataManager.set(DATA_ID_PADDLE[1], Boolean.valueOf(p_184445_2_));
           }
        
           @SideOnly(Side.CLIENT)
           public float getRowingTime(int p_184448_1_, float limbSwing)
           {
               return this.getPaddleState(p_184448_1_) ? (float)MathHelper.denormalizeClamp((double)this.paddlePositions[p_184448_1_] - 0.01D, (double)this.paddlePositions[p_184448_1_], (double)limbSwing) : 0.0F;
           }
        
           /**
            * Determines whether the boat is in water, gliding on land, or in air
            */
           private EntitySleigh.Status getBoatStatus()
           {
               EntitySleigh.Status entityboat$status = this.getUnderwaterStatus();
        
               if (entityboat$status != null)
               {
                   this.waterLevel = this.getEntityBoundingBox().maxY;
                   return entityboat$status;
               }
               else if (this.checkInWater())
               {
                   return EntitySleigh.Status.IN_WATER;
               }
               else
               {
                   float f = this.getBoatGlide();
        
                   if (f > 0.0F)
                   {
                       this.boatGlide = f;
                       return EntitySleigh.Status.ON_LAND;
                   }
                   else
                   {
                       return EntitySleigh.Status.IN_AIR;
                   }
               }
           }
        
           public float getWaterLevelAbove()
           {
               AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
               int i = MathHelper.floor_double(axisalignedbb.minX);
               int j = MathHelper.ceiling_double_int(axisalignedbb.maxX);
               int k = MathHelper.floor_double(axisalignedbb.maxY);
               int l = MathHelper.ceiling_double_int(axisalignedbb.maxY - this.lastYd);
               int i1 = MathHelper.floor_double(axisalignedbb.minZ);
               int j1 = MathHelper.ceiling_double_int(axisalignedbb.maxZ);
               BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
        
               try
               {
                   label78:
        
                   for (int k1 = k; k1 < l; ++k1)
                   {
                       float f = 0.0F;
                       int l1 = i;
        
                       while (true)
                       {
                           if (l1 >= j)
                           {
                               if (f < 1.0F)
                               {
                                   float f2 = (float)blockpos$pooledmutableblockpos.getY() + f;
                                   return f2;
                               }
        
                               break;
                           }
        
                           for (int i2 = i1; i2 < j1; ++i2)
                           {
                               blockpos$pooledmutableblockpos.set(l1, k1, i2);
                               IBlockState iblockstate = this.worldObj.getBlockState(blockpos$pooledmutableblockpos);
        
                               if (iblockstate.getMaterial() == Material.WATER)
                               {
                                   f = Math.max(f, getBlockLiquidHeight(iblockstate, this.worldObj, blockpos$pooledmutableblockpos));
                               }
        
                               if (f >= 1.0F)
                               {
                                   continue label78;
                               }
                           }
        
                           ++l1;
                       }
                   }
        
                   float f1 = (float)(l + 1);
                   return f1;
               }
               finally
               {
                   blockpos$pooledmutableblockpos.release();
               }
           }
        
           /**
            * Decides how much the boat should be gliding on the land (based on any slippery blocks)
            */
           public float getBoatGlide()
           {
               AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
               AxisAlignedBB axisalignedbb1 = new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY - 0.001D, axisalignedbb.minZ, axisalignedbb.maxX, axisalignedbb.minY, axisalignedbb.maxZ);
               int i = MathHelper.floor_double(axisalignedbb1.minX) - 1;
               int j = MathHelper.ceiling_double_int(axisalignedbb1.maxX) + 1;
               int k = MathHelper.floor_double(axisalignedbb1.minY) - 1;
               int l = MathHelper.ceiling_double_int(axisalignedbb1.maxY) + 1;
               int i1 = MathHelper.floor_double(axisalignedbb1.minZ) - 1;
               int j1 = MathHelper.ceiling_double_int(axisalignedbb1.maxZ) + 1;
               List <axisalignedbb>list = Lists.<axisalignedbb>newArrayList();
               float f = 0.0F;
               int k1 = 0;
               BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
        
               try
               {
                   for (int l1 = i; l1 < j; ++l1)
                   {
                       for (int i2 = i1; i2 < j1; ++i2)
                       {
                           int j2 = (l1 != i && l1 != j - 1 ? 0 : 1) + (i2 != i1 && i2 != j1 - 1 ? 0 : 1);
        
                           if (j2 != 2)
                           {
                               for (int k2 = k; k2 < l; ++k2)
                               {
                                   if (j2 <= 0 || k2 != k && k2 != l - 1)
                                   {
                                       blockpos$pooledmutableblockpos.set(l1, k2, i2);
                                       IBlockState iblockstate = this.worldObj.getBlockState(blockpos$pooledmutableblockpos);
                                       iblockstate.addCollisionBoxToList(this.worldObj, blockpos$pooledmutableblockpos, axisalignedbb1, list, this);
        
                                       if (!list.isEmpty())
                                       {
                                           f += iblockstate.getBlock().slipperiness;
                                           ++k1;
                                       }
        
                                       list.clear();
                                   }
                               }
                           }
                       }
                   }
               }
               finally
               {
                   blockpos$pooledmutableblockpos.release();
               }
        
               return f / (float)k1;
           }
        
           private boolean checkInWater()
           {
               AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
               int i = MathHelper.floor_double(axisalignedbb.minX);
               int j = MathHelper.ceiling_double_int(axisalignedbb.maxX);
               int k = MathHelper.floor_double(axisalignedbb.minY);
               int l = MathHelper.ceiling_double_int(axisalignedbb.minY + 0.001D);
               int i1 = MathHelper.floor_double(axisalignedbb.minZ);
               int j1 = MathHelper.ceiling_double_int(axisalignedbb.maxZ);
               boolean flag = false;
               this.waterLevel = Double.MIN_VALUE;
               BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
        
               try
               {
                   for (int k1 = i; k1 < j; ++k1)
                   {
                       for (int l1 = k; l1 < l; ++l1)
                       {
                           for (int i2 = i1; i2 < j1; ++i2)
                           {
                               blockpos$pooledmutableblockpos.set(k1, l1, i2);
                               IBlockState iblockstate = this.worldObj.getBlockState(blockpos$pooledmutableblockpos);
        
                               if (iblockstate.getMaterial() == Material.WATER)
                               {
                                   float f = getLiquidHeight(iblockstate, this.worldObj, blockpos$pooledmutableblockpos);
                                   this.waterLevel = Math.max((double)f, this.waterLevel);
                                   flag |= axisalignedbb.minY < (double)f;
                               }
                           }
                       }
                   }
               }
               finally
               {
                   blockpos$pooledmutableblockpos.release();
               }
        
               return flag;
           }
        
           /**
            * Decides whether the boat is currently underwater.
            */
           @Nullable
           private EntitySleigh.Status getUnderwaterStatus()
           {
               AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
               double d0 = axisalignedbb.maxY + 0.001D;
               int i = MathHelper.floor_double(axisalignedbb.minX);
               int j = MathHelper.ceiling_double_int(axisalignedbb.maxX);
               int k = MathHelper.floor_double(axisalignedbb.maxY);
               int l = MathHelper.ceiling_double_int(d0);
               int i1 = MathHelper.floor_double(axisalignedbb.minZ);
               int j1 = MathHelper.ceiling_double_int(axisalignedbb.maxZ);
               boolean flag = false;
               BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
        
               try
               {
                   for (int k1 = i; k1 < j; ++k1)
                   {
                       for (int l1 = k; l1 < l; ++l1)
                       {
                           for (int i2 = i1; i2 < j1; ++i2)
                           {
                               blockpos$pooledmutableblockpos.set(k1, l1, i2);
                               IBlockState iblockstate = this.worldObj.getBlockState(blockpos$pooledmutableblockpos);
        
                               if (iblockstate.getMaterial() == Material.WATER && d0 < (double)getLiquidHeight(iblockstate, this.worldObj, blockpos$pooledmutableblockpos))
                               {
                                   if (((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() != 0)
                                   {
                                       EntitySleigh.Status entityboat$status = EntitySleigh.Status.UNDER_FLOWING_WATER;
                                       return entityboat$status;
                                   }
        
                                   flag = true;
                               }
                           }
                       }
                   }
               }
               finally
               {
                   blockpos$pooledmutableblockpos.release();
               }
        
               return flag ? EntitySleigh.Status.UNDER_WATER : null;
           }
        
           public static float getBlockLiquidHeight(IBlockState p_184456_0_, IBlockAccess p_184456_1_, BlockPos p_184456_2_)
           {
               int i = ((Integer)p_184456_0_.getValue(BlockLiquid.LEVEL)).intValue();
               return (i & 7) == 0 && p_184456_1_.getBlockState(p_184456_2_.up()).getMaterial() == Material.WATER ? 1.0F : 1.0F - BlockLiquid.getLiquidHeightPercent(i);
           }
        
           public static float getLiquidHeight(IBlockState p_184452_0_, IBlockAccess p_184452_1_, BlockPos p_184452_2_)
           {
               return (float)p_184452_2_.getY() + getBlockLiquidHeight(p_184452_0_, p_184452_1_, p_184452_2_);
           }
        
           /**
            * Update the boat's speed, based on momentum.
            */
           private void updateMotion()
           {
               double d0 = -0.03999999910593033D;
               double d1 = d0;
               double d2 = 0.0D;
               this.momentum = 0.05F;
        
               if (this.previousStatus == EntitySleigh.Status.IN_AIR && this.status != EntitySleigh.Status.IN_AIR && this.status != EntitySleigh.Status.ON_LAND)
               {
                   this.waterLevel = this.getEntityBoundingBox().minY + (double)this.height;
                   this.setPosition(this.posX, (double)(this.getWaterLevelAbove() - this.height) + 0.101D, this.posZ);
                   this.motionY = 0.0D;
                   this.lastYd = 0.0D;
                   this.status = EntitySleigh.Status.IN_WATER;
               }
               else
               {
                   if (this.status == EntitySleigh.Status.IN_WATER)
                   {
                       d2 = (this.waterLevel - this.getEntityBoundingBox().minY) / (double)this.height;
                       this.momentum = 0.9F;
                   }
                   else if (this.status == EntitySleigh.Status.UNDER_FLOWING_WATER)
                   {
                       d1 = -7.0E-4D;
                       this.momentum = 0.9F;
                   }
                   else if (this.status == EntitySleigh.Status.UNDER_WATER)
                   {
                       d2 = 0.009999999776482582D;
                       this.momentum = 0.45F;
                   }
                   else if (this.status == EntitySleigh.Status.IN_AIR)
                   {
                       this.momentum = 0.9F;
                   }
                   else if (this.status == EntitySleigh.Status.ON_LAND)
                   {
                       this.momentum = this.boatGlide;
        
                       if (this.getControllingPassenger() instanceof EntityPlayer)
                       {
                           this.boatGlide /= 2.0F;
                       }
                   }
        
                   this.motionX *= (double)this.momentum;
                   this.motionZ *= (double)this.momentum;
                   this.deltaRotation *= this.momentum;
                   this.motionY += d1;
        
                   if (d2 > 0.0D)
                   {
                       double d3 = 0.65D;
                       this.motionY += d2 * (-d0 / 0.65D);
                       double d4 = 0.75D;
                       this.motionY *= 0.75D;
                   }
               }
           }
        
           private void controlBoat()
           {
               if (this.isBeingRidden())
               {
                   float f = 0.0F;
        
                   if (this.leftInputDown)
                   {
                       this.deltaRotation += -1.0F;
                   }
        
                   if (this.rightInputDown)
                   {
                       ++this.deltaRotation;
                   }
        
                   if (this.rightInputDown != this.leftInputDown && !this.forwardInputDown && !this.backInputDown)
                   {
                       f += 0.005F;
                   }
        
                   this.rotationYaw += this.deltaRotation;
        
                   if (this.forwardInputDown)
                   {
                       f += 0.04F;
                   }
        
                   if (this.backInputDown)
                   {
                       f -= 0.005F;
                   }
        
                   this.motionX += (double)(MathHelper.sin(-this.rotationYaw * 0.017453292F) * f);
                   this.motionZ += (double)(MathHelper.cos(this.rotationYaw * 0.017453292F) * f);
                   this.setPaddleState(this.rightInputDown || this.forwardInputDown, this.leftInputDown || this.forwardInputDown);
               }
           }
        
           @Override
           public void updatePassenger(Entity passenger)
           {
               if (this.isPassenger(passenger))
               {
                   float f = 0.0F;
                   float f1 = (float)((this.isDead ? 0.009999999776482582D : this.getMountedYOffset()) + passenger.getYOffset() + 1.15);
                   float f2 = 0.0F;
        
                   if (this.getPassengers().size() == 1)
                   {
                       int i = this.getPassengers().indexOf(passenger);
        
                       if (i == 0)
                       {
                           f = -1.5F;
                           f2 = -0.05F;
        
                       }
                       else
                       {
                           f = -1.5F;
                       }
        
                       if (passenger instanceof EntityAnimal)
                       {
                           f = (float)((double)f + 0.2D);
                       }
                   }
        
                   if (this.getPassengers().size() == 2)
                   {
                       int i = this.getPassengers().indexOf(passenger);
        
                       if (i == 0)
                       {
                           f = -1.5F;
                           f2 = -1.25F;
                       }
                       else
                       {
                           f = -1.5F;
                           f2 = -1.25F;
                       }
        
                       if (passenger instanceof EntityAnimal)
                       {
                           f = (float)((double)f + 0.2D);
                       }
                   }
        
                   Vec3d vec3d = (new Vec3d((double)f, 0.0D, (double)f2)).rotateYaw(-this.rotationYaw * 0.017453292F - ((float)Math.PI / 2F));
                   passenger.setPosition(this.posX + vec3d.xCoord, this.posY + (double)f1 - 0.5, this.posZ + vec3d.zCoord);
        
                   passenger.rotationYaw += this.deltaRotation;
                   passenger.setRotationYawHead(passenger.getRotationYawHead() + this.deltaRotation);
                   this.applyYawToEntity(passenger);
        
                   if (passenger instanceof EntityAnimal && this.getPassengers().size() > 1)
                   {
                       int j = passenger.getEntityId() % 2 == 0 ? 90 : 270;
                       passenger.setRenderYawOffset(((EntityAnimal)passenger).renderYawOffset + (float)j);
                       passenger.setRotationYawHead(passenger.getRotationYawHead() + (float)j);
                   }
               }
           }
        
           /**
            * Applies this boat's yaw to the given entity. Used to update the orientation of its passenger.
            */
           protected void applyYawToEntity(Entity entityToUpdate)
           {
               entityToUpdate.setRenderYawOffset(this.rotationYaw);
               float f = MathHelper.wrapDegrees(entityToUpdate.rotationYaw - this.rotationYaw);
               float f1 = MathHelper.clamp_float(f, -105.0F, 105.0F);
               entityToUpdate.prevRotationYaw += f1 - f;
               entityToUpdate.rotationYaw += f1 - f;
               entityToUpdate.setRotationYawHead(entityToUpdate.rotationYaw);
           }
        
           /**
            * Applies this entity's orientation (pitch/yaw) to another entity. Used to update passenger orientation.
            */
           @SideOnly(Side.CLIENT)
           public void applyOrientationToEntity(Entity entityToUpdate)
           {
               this.applyYawToEntity(entityToUpdate);
           }
        
           /**
            * (abstract) Protected helper method to write subclass entity data to NBT.
            */
           protected void writeEntityToNBT(NBTTagCompound compound)
           {
               compound.setString("Type", this.getBoatType().getName());
           }
        
           /**
            * (abstract) Protected helper method to read subclass entity data from NBT.
            */
           protected void readEntityFromNBT(NBTTagCompound compound)
           {
               if (compound.hasKey("Type", 8))
               {
                   this.setBoatType(EntitySleigh.Type.getTypeFromString(compound.getString("Type")));
               }
           }
        
           public boolean processInitialInteract(EntityPlayer player, @Nullable ItemStack stack, EnumHand hand)
           {
               if (!this.worldObj.isRemote && !player.isSneaking() && this.outOfControlTicks < 60.0F)
               {
                   player.startRiding(this);
               }
        
               return true;
           }
        
           protected void updateFallState(double y, boolean onGroundIn, IBlockState state, BlockPos pos)
           {
               this.lastYd = this.motionY;
        
               if (!this.isRiding())
               {
                   if (onGroundIn)
                   {
                       if (this.fallDistance > 3.0F)
                       {
                           if (this.status != EntitySleigh.Status.ON_LAND)
                           {
                               this.fallDistance = 0.0F;
                               return;
                           }
        
                           this.fall(this.fallDistance, 1.0F);
        
                           if (!this.worldObj.isRemote && !this.isDead)
                           {
                               this.setDead();
        
                               if (this.worldObj.getGameRules().getBoolean("doEntityDrops"))
                               {
                                   for (int i = 0; i < 3; ++i)
                                   {
                                       this.entityDropItem(new ItemStack(Item.getItemFromBlock(Blocks.PLANKS), 1, this.getBoatType().getMetadata()), 0.0F);
                                   }
        
                                   for (int j = 0; j < 2; ++j)
                                   {
                                       this.dropItemWithOffset(Items.STICK, 1, 0.0F);
                                   }
                               }
                           }
                       }
        
                       this.fallDistance = 0.0F;
                   }
                   else if (this.worldObj.getBlockState((new BlockPos(this)).down()).getMaterial() != Material.WATER && y < 0.0D)
                   {
                       this.fallDistance = (float)((double)this.fallDistance - y);
                   }
               }
           }
        
           public boolean getPaddleState(int p_184457_1_)
           {
               return ((Boolean)this.dataManager.get(DATA_ID_PADDLE[p_184457_1_])).booleanValue() && this.getControllingPassenger() != null;
           }
        
           /**
            * Sets the damage taken from the last hit.
            */
           public void setDamageTaken(float damageTaken)
           {
               this.dataManager.set(DAMAGE_TAKEN, Float.valueOf(damageTaken));
           }
        
           /**
            * Gets the damage taken from the last hit.
            */
           public float getDamageTaken()
           {
               return ((Float)this.dataManager.get(DAMAGE_TAKEN)).floatValue();
           }
        
           /**
            * Sets the time to count down from since the last time entity was hit.
            */
           public void setTimeSinceHit(int timeSinceHit)
           {
               this.dataManager.set(TIME_SINCE_HIT, Integer.valueOf(timeSinceHit));
           }
        
           /**
            * Gets the time since the last hit.
            */
           public int getTimeSinceHit()
           {
               return ((Integer)this.dataManager.get(TIME_SINCE_HIT)).intValue();
           }
        
           /**
            * Sets the forward direction of the entity.
            */
           public void setForwardDirection(int forwardDirection)
           {
               this.dataManager.set(FORWARD_DIRECTION, Integer.valueOf(forwardDirection));
           }
        
           /**
            * Gets the forward direction of the entity.
            */
           public int getForwardDirection()
           {
               return ((Integer)this.dataManager.get(FORWARD_DIRECTION)).intValue();
           }
        
           public void setBoatType(EntitySleigh.Type boatType)
           {
               this.dataManager.set(BOAT_TYPE, Integer.valueOf(boatType.ordinal()));
           }
        
           public EntitySleigh.Type getBoatType()
           {
               return EntitySleigh.Type.byId(((Integer)this.dataManager.get(BOAT_TYPE)).intValue());
           }
        
           protected boolean canFitPassenger(Entity passenger)
           {
               return this.getPassengers().size() < 2;
           }
        
           /**
            * For vehicles, the first passenger is generally considered the controller and "drives" the vehicle. For example,
            * Pigs, Horses, and Boats are generally "steered" by the controlling passenger.
            */
           @Nullable
           public Entity getControllingPassenger()
           {
               List <entity>list = this.getPassengers();
               return list.isEmpty() ? null : (Entity)list.get(0);
           }
        
           @SideOnly(Side.CLIENT)
           public void updateInputs(boolean p_184442_1_, boolean p_184442_2_, boolean p_184442_3_, boolean p_184442_4_)
           {
               this.leftInputDown = p_184442_1_;
               this.rightInputDown = p_184442_2_;
               this.forwardInputDown = p_184442_3_;
               this.backInputDown = p_184442_4_;
           }
        
           public static enum Status
           {
               IN_WATER,
               UNDER_WATER,
               UNDER_FLOWING_WATER,
               ON_LAND,
               IN_AIR;
           }
        
           public static enum Type
           {
               OAK(BlockPlanks.EnumType.OAK.getMetadata(), "oak"),
               SPRUCE(BlockPlanks.EnumType.SPRUCE.getMetadata(), "spruce"),
               BIRCH(BlockPlanks.EnumType.BIRCH.getMetadata(), "birch"),
               JUNGLE(BlockPlanks.EnumType.JUNGLE.getMetadata(), "jungle"),
               ACACIA(BlockPlanks.EnumType.ACACIA.getMetadata(), "acacia"),
               DARK_OAK(BlockPlanks.EnumType.DARK_OAK.getMetadata(), "dark_oak");
        
               private final String name;
               private final int metadata;
        
               private Type(int metadataIn, String nameIn)
               {
                   this.name = nameIn;
                   this.metadata = metadataIn;
               }
        
               public String getName()
               {
                   return this.name;
               }
        
               public int getMetadata()
               {
                   return this.metadata;
               }
        
               public String toString()
               {
                   return this.name;
               }
        
               /**
                * Get a boat type by it's enum ordinal
                */
               public static EntitySleigh.Type byId(int id)
               {
                   if (id < 0 || id >= values().length)
                   {
                       id = 0;
                   }
        
                   return values()[id];
               }
        
               public static EntitySleigh.Type getTypeFromString(String nameIn)
               {
                   for (int i = 0; i < values().length; ++i)
                   {
                       if (values()*.getName().equals(nameIn))
                       {
                           return values()*;
                       }
                   }
        
                   return values()[0];
               }
           }
        }
        ```(Comme vous pouvez le voir, il y a des choses en rapport avec les bateaux qui ne servent à rien, mais je les enlèverai plus tard).
        
        Si vous avez une idée, je suis preneur.
        
        Merci d'avance
        
        PS : J'ai placé ce problème à la fin de ce post au lieu de créer un autre sujet. Certes, j'ai mis ce sujet en résolu, mais il n'a pas encore été placé comme résolu. Ai-je eu raison de mettre ce problème ici ou aurais-je dû créer un autre sujet ?</entity></axisalignedbb></axisalignedbb></entity></entity></boolean></integer></integer></float></float></integer></integer></integer></integer>
        1 réponse Dernière réponse Répondre Citer 0
        • LeBossMax2L Hors-ligne
          LeBossMax2
          dernière édition par

          Si le bateau ne bouge pas, c’est surement que les variable “forwardInputDown”, “leftInputDown” , … sont toujours à false (coté serveur) donc regarde si la fonction “updateInputs” est bien appelée. Si elle est bien appelée, il faut surement envoyer les info au serveur je ne sait pas si il y as une fonction pour faire ça mais sinon, il faut surement passer par un packet. (je ne m’y connais pas trop en entité donc c’est peut-être pas ça le problème mais c’est ce qui me parait le plus probable)

          1 réponse Dernière réponse Répondre Citer 0
          • AxaurusA Hors-ligne
            Axaurus
            dernière édition par

            Salut
            Désolé pour le temps de la réponse, j’essayait d’ajouter un inventaire au traîneau, qui veut pas s’ouvrir.

            Bref. J’avais vu un packet dans la classe de l’entité, je suis allé à l’intérieur et j’ai vu qu’il servait aux mouvements. Je m’étais dit que ça pouvait l’utiliser. On dirait bien que non. Je vais en faire un autre et je reviens.

            Comme dit ci-dessus, j’ai essayer d’ajouter un inventaire (donc un gui, un container et un inventaire) à mon traîneau, mais il veut pas s’ouvrir. J’y ai passé toute l’après-midi à lire le tuto, le comprendre et tout. J’ai également dû “bidouiller” quelques trucs pour l’adapter à mon traîneau vu que le tuto à été créer pour un block.

            Voici les classes :
            Ce qui sert à ouvrir le gui dans la classe de l’entité :

                   else if (!this.worldObj.isRemote && player.isSneaking() && this.outOfControlTicks < 60.0F)
                   {
                    System.out.println("must open GUI");
                       player.openGui(ThisisChristmas.instance, 0, this.worldObj, (int)this.posX, (int)this.posY, (int)this.posZ);
                   }
            

            Mon GuiHandler

            package This_is_Christmas;
            
            import This_is_Christmas.Entity.EntitySleigh;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.world.World;
            import net.minecraftforge.fml.common.network.IGuiHandler;
            
            public class GuiHandlerChristmas implements IGuiHandler {
            
            @Override
            public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
            {
            if(ID == 0)
            {
            System.out.println("must call container");
            EntitySleigh sleigh = new EntitySleigh(world);
            InventorySleigh invSleigh = new InventorySleigh(world);
            return new ContainerSleigh(player.inventory, invSleigh, sleigh, player);
            }
            return null;
            }
            
            @Override
            public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
            {
            if(ID == 0)
            {
            System.out.println("must call GUI");
            EntitySleigh sleigh = new EntitySleigh(world);
            InventorySleigh invSleigh = new InventorySleigh(world);
            return new GuiSleigh(player.inventory, invSleigh, sleigh, player);
            }
            return null;
            }
            }
            

            Mon GUI :

            package This_is_Christmas;
            
            import org.lwjgl.opengl.GL11;
            
            import This_is_Christmas.Entity.EntitySleigh;
            import net.minecraft.client.gui.inventory.GuiContainer;
            import net.minecraft.client.resources.I18n;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.entity.player.InventoryPlayer;
            import net.minecraft.inventory.IInventory;
            import net.minecraft.util.ResourceLocation;
            
            public class GuiSleigh extends GuiContainer{
            
            private static final ResourceLocation texture = new ResourceLocation(ThisisChristmas.MODID + ":" + "textures/gui/inventorySleigh");
            private IInventory playerInv;
            private EntitySleigh theSleigh;
            private InventorySleigh sleighInventory;
            
            public GuiSleigh(InventoryPlayer inventory, InventorySleigh invSleigh, EntitySleigh sleigh, EntityPlayer player)
            {
            super(new ContainerSleigh(inventory, invSleigh, sleigh, player));
            System.out.println("GUI has been call");
            this.theSleigh = sleigh;
            this.playerInv = inventory;
            this.sleighInventory = invSleigh;
            this.allowUserInput = false;
            this.xSize = 176;
            this.ySize = 222;
            System.out.println("GUI has been initialize");
            }
            
            @Override
            protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
            {
            System.out.println("drawGuiContainerBackgroundLayer has been call");
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.getTextureManager().bindTexture(texture);
            int k = (this.width - this.xSize) / 2;
            int l = (this.height - this.ySize) / 2;
            this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
            System.out.println("GUI has been draw");
            }
            
            protected void drawGuiContainerForegroundLayer(int x, int y)
            {
            String invSleighName = this.sleighInventory.hasCustomName() ? this.sleighInventory.getName() : I18n.format(this.sleighInventory.getName());
            this.fontRendererObj.drawStringWithShadow(invSleighName, (this.xSize - this.fontRendererObj.getStringWidth(invSleighName)) / 2, 6, 0);
            String invPlayerName = this.playerInv.hasCustomName() ? this.playerInv.getName() : I18n.format(this.playerInv.getName());
            this.fontRendererObj.drawStringWithShadow(invPlayerName, (this.xSize - this.fontRendererObj.getStringWidth(invPlayerName)) / 2, this.ySize - 96, 0);
            }
            
            }
            
            

            Mon Container :

            package This_is_Christmas;
            
            import This_is_Christmas.Entity.EntitySleigh;
            import net.minecraft.entity.passive.EntityHorse;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.entity.player.InventoryPlayer;
            import net.minecraft.inventory.Container;
            import net.minecraft.inventory.IInventory;
            import net.minecraft.inventory.Slot;
            import net.minecraft.item.ItemStack;
            
            public class ContainerSleigh extends Container{
            
            private InventorySleigh sleighInventory;
            private EntitySleigh theSleigh;
            
            public ContainerSleigh(IInventory playerInventory, final InventorySleigh sleighInventoryIn, final EntitySleigh sleigh, EntityPlayer player)
            {
            System.out.println("Container has been call");
            sleighInventory = sleighInventoryIn;
            theSleigh = sleigh;
            
            sleighInventoryIn.openInventory(player);
            for(int i=0; i < 3; i++)
            {
            for(int j = 0; j < 9; j++)
            {
            this.addSlotToContainer(new Slot(sleighInventoryIn, j + i * 9, 8 + j * 18, 18 + i * 18));
            }
            }
            
            this.bindPlayerInventory(player.inventory);
            }
            
            @Override
            public boolean canInteractWith(EntityPlayer playerIn)
            {
                   return this.sleighInventory.isUseableByPlayer(playerIn) && this.theSleigh.isEntityAlive() && this.theSleigh.getDistanceToEntity(playerIn) < 8.0F;
            }
            
            private void bindPlayerInventory(InventoryPlayer inventory)
            {
            int i;
            for(i = 0; i < 3; i++)
            {
            for(int j = 0; j < 9; j++)
            {
            this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 86 + i * 18));
            }
            }
            
            for(i = 0; i < 9; i++)
            {
            this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 144));
            }
            }
            
            public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
               {
                   ItemStack itemstack = null;
                   Slot slot = (Slot)this.inventorySlots.get(index);
            
                   if (slot != null && slot.getHasStack())
                   {
                       ItemStack itemstack1 = slot.getStack();
                       itemstack = itemstack1.copy();
            
                       if (index < this.sleighInventory.getSizeInventory())
                       {
                           if (!this.mergeItemStack(itemstack1, this.sleighInventory.getSizeInventory(), this.inventorySlots.size(), true))
                           {
                               return null;
                           }
                       }
                       else if (this.getSlot(1).isItemValid(itemstack1) && !this.getSlot(1).getHasStack())
                       {
                           if (!this.mergeItemStack(itemstack1, 1, 2, false))
                           {
                               return null;
                           }
                       }
                       else if (this.getSlot(0).isItemValid(itemstack1))
                       {
                           if (!this.mergeItemStack(itemstack1, 0, 1, false))
                           {
                               return null;
                           }
                       }
                       else if (this.sleighInventory.getSizeInventory() <= 2 || !this.mergeItemStack(itemstack1, 2, this.sleighInventory.getSizeInventory(), false))
                       {
                           return null;
                       }
            
                       if (itemstack1.stackSize == 0)
                       {
                           slot.putStack((ItemStack)null);
                       }
                       else
                       {
                           slot.onSlotChanged();
                       }
                   }
            
                   return itemstack;
               }
            }
            
            

            Et mon Inventaire :

            package This_is_Christmas;
            
            import net.minecraft.entity.Entity;
            import net.minecraft.entity.player.EntityPlayer;
            import net.minecraft.inventory.IInventory;
            import net.minecraft.item.ItemStack;
            import net.minecraft.nbt.NBTTagCompound;
            import net.minecraft.util.text.ITextComponent;
            import net.minecraft.world.World;
            
            public class InventorySleigh extends Entity implements IInventory{
            
            public InventorySleigh(World worldIn)
            {
            super(worldIn);
            System.out.println("Inventory has been call");
            }
            
            private ItemStack[] contents = new ItemStack[54];
            private String customName;
            
            @Override
            public String getName()
            {
            return this.hasCustomName() ? this.customName : "entity.sleigh";
            }
            
            @Override
            public boolean hasCustomName() {
            // TODO Auto-generated method stub
            return false;
            }
            
            @Override
            public ITextComponent getDisplayName() {
            // TODO Auto-generated method stub
            return null;
            }
            
            @Override
            public int getSizeInventory()
            {
            return this.contents.length;
            }
            
            @Override
            public ItemStack getStackInSlot(int slotIndex)
            {
            return this.contents[slotIndex];
            }
            
            @Override
            public ItemStack decrStackSize(int slotIndex, int count)
            {
            if(this.contents[slotIndex] != null)
            {
            ItemStack itemStack;
            
            if(this.contents[slotIndex].stackSize <= count)
            {
            itemStack = this.contents[slotIndex];
            this.contents[slotIndex] = null;
            this.markDirty();
            return itemStack;
            }
            else
            {
            itemStack = this.contents[slotIndex].splitStack(count);
            
            if(this.contents[slotIndex].stackSize == 0)
            {
            this.contents[slotIndex] = null;
            }
            
            this.markDirty();
            return itemStack;
            }
            }
            else
            {
            return null;
            }
            }
            
            @Override
            public ItemStack removeStackFromSlot(int slotIndex)
            {
            if(this.contents[slotIndex] != null)
            {
            ItemStack itemStack = this.contents[slotIndex];
            this.contents[slotIndex] = null;
            return itemStack;
            }
            return null;
            }
            
            @Override
            public void setInventorySlotContents(int slotIndex, ItemStack stack)
            {
            this.contents[slotIndex] = stack;
            
            if(stack != null && stack.stackSize > this.getInventoryStackLimit())
            {
            stack.stackSize = this.getInventoryStackLimit();
            }
            
            this.markDirty();
            }
            
            @Override
            public int getInventoryStackLimit()
            {
            return 64;
            }
            
            @Override
            public void markDirty() {
            // TODO Auto-generated method stub
            
            }
            
            @Override
            public boolean isUseableByPlayer(EntityPlayer player)
            {
            if(player.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D)
            {
            return true;
            }
            else
            {
            return false;
            }
            }
            
            @Override
            public void openInventory(EntityPlayer player)
            {
            
            }
            
            @Override
            public void closeInventory(EntityPlayer player)
            {
            
            }
            
            @Override
            public boolean isItemValidForSlot(int index, ItemStack stack)
            {
            return true;
            }
            
            @Override
            public int getField(int id) {
            // TODO Auto-generated method stub
            return 0;
            }
            
            @Override
            public void setField(int id, int value) {
            // TODO Auto-generated method stub
            
            }
            
            @Override
            public int getFieldCount() {
            // TODO Auto-generated method stub
            return 0;
            }
            
            @Override
            public void clear() {
            // TODO Auto-generated method stub
            
            }
            
            public void setCustomName(String customName)
            {
            this.customName = customName;
            }
            
            @Override
            protected void entityInit() {
            // TODO Auto-generated method stub
            
            }
            
            @Override
            protected void readEntityFromNBT(NBTTagCompound compound) {
            // TODO Auto-generated method stub
            
            }
            
            @Override
            protected void writeEntityToNBT(NBTTagCompound compound) {
            // TODO Auto-generated method stub
            
            }
            
            }
            
            

            Je sais pas pourquoi mais j’ai l’impression qu’il y a des erreurs dans l’inventaire. Mais c’est pas là le problème. Comme vous voyez, dans chaque classe j’ai mis des sytem.out.println pour voir si c’est appelé ou pas. Voilà ce que j’obtient :

            [17:42:26] [Server thread/INFO] [STDOUT]: [This_is_Christmas.Entity.EntitySleigh:processInitialInteract:851]: must open GUI
            [17:42:26] [Server thread/INFO] [STDOUT]: [This_is_Christmas.GuiHandlerChristmas:getServerGuiElement:15]: must call container
            [17:42:26] [Server thread/INFO] [STDOUT]: [This_is_Christmas.InventorySleigh:<init>:16]: Inventory has been call
            [17:42:26] [Server thread/INFO] [STDOUT]: [This_is_Christmas.ContainerSleigh:<init>:19]: Container has been call
            [17:42:26] [Client thread/INFO] [STDOUT]: [This_is_Christmas.GuiHandlerChristmas:getClientGuiElement:28]: must call GUI
            [17:42:26] [Client thread/INFO] [STDOUT]: [This_is_Christmas.InventorySleigh:<init>:16]: Inventory has been call
            [17:42:26] [Client thread/INFO] [STDOUT]: [This_is_Christmas.ContainerSleigh:<init>:19]: Container has been call
            [17:42:26] [Client thread/INFO] [STDOUT]: [This_is_Christmas.GuiSleigh:<init>:23]: GUI has been call
            [17:42:26] [Client thread/INFO] [STDOUT]: [This_is_Christmas.GuiSleigh:<init>:30]: GUI has been initialize
            

            On peut voir que tout est appelé à l’exception d’une fonction : la fonction drawGuiContainerBackgroundLayer de la classe Gui. Je sais pas pourquoi ça ne marche pas, pourtant le gui est bien initialisé.

            Si vous avez une idée, n’hsitez pas 😉
            C’est peut-être le fait que j’ai bidouillé quelques trucs pour l’adapter à une entité qui fait foirer quelque chose

            Merci d’avance

            EDIT : Pour le mouvement du traîneau, ce n’est pas un packet en fait, parce qu’il a des paramètres en rapport avec les palles. Pour être sûr, j’ai ouvert un src 1.8, et il n’y a pas de packet.</init></init></init></init></init></init>

            1 réponse Dernière réponse Répondre Citer 0
            • robin4002R Hors-ligne
              robin4002 Moddeurs confirmés Rédacteurs Administrateurs
              dernière édition par

              Ton gui se referme car la condition suivante :

                    return this.sleighInventory.isUseableByPlayer(playerIn) && this.theSleigh.isEntityAlive() && this.theSleigh.getDistanceToEntity(playerIn) < 8.0F;
              

              n’est pas satisfaite (canInteractWith du container).

              Car ici :

              EntitySleigh sleigh = new EntitySleigh(world);
              InventorySleigh invSleigh = new InventorySleigh(world);
              return new GuiSleigh(player.inventory, invSleigh, sleigh, player);
              

              Tu créés une nouvelle instance au lieu de get l’entité existante.
              Utilises Entity entity = world.getEntityById(x) pour get l’entité, et lors du openGui utilise ça :

                        player.openGui(ThisisChristmas.instance, 0, this.worldObj, this.getEntityId(), 0, 0);
              

              x, y et z n’ont pas forcement besoin d’être des coordonnées, et c’est seulement utile dans le cas d’un bloc.
              Pour une entité faire passer l’id de l’entité suffit.

              Et pour ton inventaire, au lieu de créer une classe à part (qui te fait encore une instance de plus que tu gère déjà mal) fusionne-le dans la classe de l’entité. Ça sera beaucoup plus simple pour gérer l’instance et pour l’enregistrement des items dans le nbt de l’entité (d’ailleurs on fait exactement la même chose avec les tile entity, l’inventaire est dans la classe même et non dans une classe à part).

              1 réponse Dernière réponse Répondre Citer 0
              • AxaurusA Hors-ligne
                Axaurus
                dernière édition par

                Salut
                J’ai tout fait et ça marche bien, à part les slots qui étaient décalés. Je pensais que ça serait chaud de les déplacer, mais non : une fois qu’on a compris le calcul, c’est simple. Là, tout est bien positionné. Voilà le résultat :

                Il me reste plus que le problème que je ne peux pas bouger avec. A mon avis, la solution au problème doit être la même que mon problème de Renne que je ne peux pas contrôler non plus.

                Merci d’avance

                1 réponse Dernière réponse Répondre Citer 0
                • AxaurusA Hors-ligne
                  Axaurus
                  dernière édition par

                  Salut
                  Ce n’est pas la même solution que mon problème de renne, le renne étant extend de EntityAnimal. Mais je pense avoir trouvé. J’ai essayé de voir où était appelé ma classe entity, elle est appelé dans l’itemSleigh (en gros, c’est l’item pour le faire spawn). J’ai comparé à l’entityBoat, elle est appelé à trois endroits : dans l’item (comme pour moin traîneau, il sert a le faire spawn), dans la sous-classe BehaviorDispenseBoat de la classe Bootstrap et dans la classe NetHandlerPlayClient. Pour la sous-classe BehaviorDispenseBoat, si je comprend bien le commentaire (le voici : Dispense the specified stack, play the dispense sound and spawn particles.), ça sert pour le dispenser. Dans la classe NetHandlerPlayClient, je pense que c’est des packets vu que ça concerne le réseau. En tout cas, si c’est ça, tu avais raison LeBossMax2. Mais je suis pas sûr, voici la classe (je met juste ce qui est utile, demandez moi si vous voulez la classe en entière, elle est dans le package net/minecraft/client/network) :

                  package net.minecraft.client.network;
                  […]
                  @SideOnly(Side.CLIENT)
                  public class NetHandlerPlayClient implements INetHandlerPlayClient
                  {
                  […]
                     private WorldClient clientWorldController;
                  […]
                  /**
                      * Spawns an instance of the objecttype indicated by the packet and sets its position and momentum
                      */
                     public void handleSpawnObject(SPacketSpawnObject packetIn)
                     {
                         PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
                         double d0 = packetIn.getX();
                         double d1 = packetIn.getY();
                         double d2 = packetIn.getZ();
                         Entity entity = null;
                  […]
                        else if (packetIn.getType() == 1)
                         {
                             entity = new EntityBoat(this.clientWorldController, d0, d1, d2);
                         }
                  […]
                        if (entity != null)
                         {
                             EntityTracker.updateServerPosition(entity, d0, d1, d2);
                             entity.rotationPitch = (float)(packetIn.getPitch() * 360) / 256.0F;
                             entity.rotationYaw = (float)(packetIn.getYaw() * 360) / 256.0F;
                             Entity[] aentity = entity.getParts();
                  
                             if (aentity != null)
                             {
                                 int i = packetIn.getEntityID() - entity.getEntityId();
                  
                                 for (int j = 0; j < aentity.length; ++j)
                                 {
                                     aentity[j].setEntityId(aentity[j].getEntityId() + i);
                                 }
                             }
                  
                             entity.setEntityId(packetIn.getEntityID());
                             entity.setUniqueId(packetIn.getUniqueId());
                             this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entity);
                  
                             if (packetIn.getData() > 0)
                             {
                                 if (packetIn.getType() == 60 || packetIn.getType() == 91)
                                 {
                                     Entity entity2 = this.clientWorldController.getEntityByID(packetIn.getData() - 1);
                  
                                     if (entity2 instanceof EntityLivingBase && entity instanceof EntityArrow)
                                     {
                                         ((EntityArrow)entity).shootingEntity = entity2;
                                     }
                                 }
                  
                                 entity.setVelocity((double)packetIn.getSpeedX() / 8000.0D, (double)packetIn.getSpeedY() / 8000.0D, (double)packetIn.getSpeedZ() / 8000.0D);
                             }
                         }
                     }
                  […]
                  }
                  
                  

                  Merci d’avance

                  1 réponse Dernière réponse Répondre Citer 0
                  • AxaurusA Hors-ligne
                    Axaurus
                    dernière édition par

                    Salut
                    J’ai enfin réussi. J’ai mis :

                    Entity player = this.getControllingPassenger();
                    EntityTracker.updateServerPosition(this, this.posX, this.posY, this.posZ);
                    this.rotationPitch = (float)((MathHelper.floor_float(player.rotationPitch * 256.0F / 360.0F)) * 360) / 256.0F;
                    this.rotationYaw = (float)((MathHelper.floor_float(player.rotationYaw * 256.0F / 360.0F)) * 360) / 256.0F;
                    Entity[] aentity = this.getParts();
                    
                    if(aentity != null)
                    {
                    int i = player.getEntityId() - this.getEntityId();
                    
                    for(int j=0; j < aentity.length; ++j)
                    {
                    aentity[j].setEntityId(aentity[j].getEntityId() + i);
                    }
                    }
                    
                    this.setVelocity((double)((int)(MathHelper.clamp_double(player.motionX, -3.9D, 3.9D) * 8000.0D)) / 500.0D, (double)((int)(MathHelper.clamp_double(player.motionY, -3.9D, 3.9D) * 8000.0D)) / 500.0D, (double)((int)(MathHelper.clamp_double(player.motionZ, -3.9D, 3.9D) * 8000.0D)) / 500.0D);
                    ``` dans la fonction controlBoat. Je me suis inspiré de la fonction que j'ai donné dans le post précédent.
                    
                    Par contre, j'ai un autre problème et une question.
                    Mon autre problème concerne la hitbox. Je l'ai modifié et ça met fait ça :
                    [![](http://image.noelshack.com/minis/2016/43/1477837960-2016-10-30-15-06-51.png)](http://www.noelshack.com/2016-43-1477837960-2016-10-30-15-06-51.png)
                    (j'ai mis la hitbox en rouge pour bien la voir)
                    Comme vous voyez, elle est trop grande. J'ai essayé de la réduire, mais le problème c'est que ça la réduit des 4 côtés. Je pense qu'il y a une fonction pour repositionner la hitbox mais je ne la trouve pas. Ce que je pensais faire, c'est placer le traîneau centre de la hitbox pour ensuite la réduire.
                    
                    Et ma question, c'est que je vais faire d'autres modifs assez dur selon moi (pouvoir accroché des rennes aux traîneau et ne pouvoir avancer seulement si il y a des rennes). J'ai une petite idée mais si je n'y arrive pas, je demande ici ou je créer un nouveau sujet ?
                    1 réponse Dernière réponse Répondre Citer 0
                    • robin4002R Hors-ligne
                      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                      dernière édition par

                      En effet ton rendu n’est pas centré par rapport à la boite de collision, il faut adapter le code du rendu avec un petit glTranslate.
                      (et du-coup il faudra aussi adapter tes valeurs pour la position de l’entité qui monte le traineau).

                      Pour les rennes, il serait mieux de créer une nouvelle discussion.

                      1 réponse Dernière réponse Répondre Citer 0
                      • AxaurusA Hors-ligne
                        Axaurus
                        dernière édition par

                        Je n’arrive pas à bien positionner le rendu par rapport à la hitbox. Je sais pas trop comment expliquer, je met des images (ça me fait pareil que quand j’ai voulu positionner le joueur)
                        Quand je ne touche à rien :    
                        Quand je décale de 1 sur l’axe Z :

                        Je pense que je vais modifier le model, ça sera sans doute plus rapide. Mais j’ai juste une question : je ne vois pas de différence entre ces deux fonctions :

                              GL11.glTranslated(x, y, z);
                               GL11.glTranslatef(x, y, z);
                        

                        Pourquoi avoir mis deux fonctions qui font la même chose ?

                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002R Hors-ligne
                          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                          dernière édition par

                          Le premier prend un argument des doubles, l’autre des float.
                          Donc l’une permet plus de précision que l’autre mais est plus lourde.

                          1 réponse Dernière réponse Répondre Citer 0
                          • AxaurusA Hors-ligne
                            Axaurus
                            dernière édition par

                            Salut
                            Merci de ces précisions 😉
                            J’ai modifié le model. C’est bien positionner maintenant

                            Merci à tous

                            1 réponse Dernière réponse Répondre Citer 0
                            • 1 / 1
                            • Premier message
                              Dernier message
                            Design by Woryk
                            ContactMentions Légales

                            MINECRAFT FORGE FRANCE © 2024

                            Powered by NodeBB