Alors suite à la réponse de @Julot10085 sur le sujet Item qui a un cooldown je me suis dis que je pourrais peut-être “enfin” mettre un cooldown sur le klaxon de mes véhicules (ça spam bien les oreilles sinon).
Donc toujours sur ma base “extends EntityHorse” j’ai essayé d’appliquer les bouts de codes en suivant les indications d’Eclipse pour l’adapter, je pense que je n’ai pas bien régler les TagCompound, en tout cas ça ne crash pas.
Là où avant quand je voulais ouvrir l’inventaire de la monture ça ne produisait que le son du klaxon (sans GUI), maintenant ça ouvre le GUI du cheval, donc j’aimerais votre avis svp.
Le fonctionnement souhaité serait de pouvoir klaxonner seulement toutes les X secondes.
:::
private Object stackTagCompound;
:::
:::
| public void onLivingUpdate() |
| { |
| { |
| if(this.hasTagCompound()) |
| { |
| if(((NBTTagCompound) this.stackTagCompound).getInteger("timer") > 0) |
| { |
| ((NBTTagCompound) this.stackTagCompound).setInteger("timer", (int) (((NBTTagCompound) this.stackTagCompound).getInteger("timer") + 1)); |
| } |
| if(((NBTTagCompound) this.stackTagCompound).getInteger("timer") >= (int) (6*20)) |
| { |
| ((NBTTagCompound) this.stackTagCompound).setInteger("timer", 0); |
| } |
| } |
| if(this.ticksExisted>=12000 && this.riddenByEntity == null) |
| { |
| this.setDead(); |
| } |
| else if (this.riddenByEntity == null) |
| { |
| motionX = motionY = motionZ = 0.0F; |
| } |
| else |
| { |
| super.onLivingUpdate(); |
| this.worldObj.theProfiler.startSection("looting"); |
| |
| if (!this.worldObj.isRemote && this.canPickUpLoot() && !this.dead && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")) |
| { |
:::
:::
| public void openGUI(EntityPlayer p_110199_1_, World world) |
| { |
| if (!this.worldObj.isRemote && (this.riddenByEntity == null || this.riddenByEntity == p_110199_1_) && this.isTame() && p_110199_1_.inventory.getCurrentItem() == null) |
| { |
| if(!this.hasTagCompound()) |
| { |
| this.setTagCompound(new NBTTagCompound()); |
| ((NBTTagCompound) this.stackTagCompound).setInteger("timer", 0); |
| } |
| if(((NBTTagCompound) this.stackTagCompound).getInteger("timer") == 0) |
| { |
| worldObj.playSoundAtEntity(this, "modpg:klaxon", 0.5F, 0.5F); |
| ((NBTTagCompound) this.stackTagCompound).setInteger("timer", 1); |
| } |
| else |
| { |
| if(world.isRemote) |
| p_110199_1_.addChatComponentMessage(new ChatComponentTranslation("Attends encore un peu si tu veux re-klaxonner.")); |
| } |
| } |
| } |
:::
:::
| private boolean hasTagCompound() |
| { |
| return false; |
| } |
| |
| private void setTagCompound(NBTTagCompound nbtTagCompound) |
| { |
| } |
:::
:::
| public void openGUI(EntityPlayer p_110199_1_) |
| { |
| if (!this.worldObj.isRemote && (this.riddenByEntity == null || this.riddenByEntity == p_110199_1_) && this.isTame() && p_110199_1_.inventory.getCurrentItem() == null) |
| { |
| worldObj.playSoundAtEntity(this, "modpg:sonnette", 0.5F, 0.5F); |
| } |
| } |
:::