• Bonjour tout le monde, je vous expose mon problème : J’ai créer un bouclier qui réduit les dégâts selon son matériau (fer, or, diamant …) et je voudrais 2 choses que je n’arrive pas à faire :

    1. Je voudrais que le bouclier ralentisse le joueur quand il à l’item à la main (ServerTickHandler ?)
    2. Je voudrais que le bouclier affiche un rendu spécial a la 1ère et à la 3ème personne (surtout la 3ème)
      Code du bouclier :
    package ast.mod.minecraftextension.item;
    
    import ast.mod.minecraftextension.core.CreativeTabsHandler;
    import net.minecraft.item.EnumAction;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    
    public class ItemShield extends Item {
    
    public ItemShield(int par1) {
    super(par1);
    this.canRepair = true;
    this.maxStackSize = 1;
    this.setCreativeTab(CreativeTabsHandler.all);
    this.setMaxDamage(500);
    }
    @Override
    public int getItemEnchantability() {
    return 24;
    }
    @Override
    public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2) {
    return true;
    }
    
    public boolean isFull3D() {
    return false;
    }
    public EnumAction getItemUseAction(ItemStack par1ItemStack) {
    return EnumAction.block;
    }
    }
    
    

    Code du ServerTickHandler :

    package ast.mod.minecraftextension.core;
    
    import java.util.EnumSet;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.potion.Potion;
    import net.minecraft.potion.PotionEffect;
    import cpw.mods.fml.common.ITickHandler;
    import cpw.mods.fml.common.TickType;
    
    public class ServerTickHandler implements ITickHandler {
    
    private void onPlayerTick(EntityPlayer player) {
    
    if (player.getCurrentItemOrArmor(0) != null) {
    ItemStack hand = player.getCurrentItemOrArmor(0);
    if (hand.itemID == ToolsHandler.swordUltimate.itemID) {
    player.addPotionEffect(new PotionEffect(Potion.damageBoost.id,
    200, 2));
    }
    if (hand.itemID == ToolsHandler.axeUltimate.itemID
    || hand.itemID == ToolsHandler.pickaxeUltimate.itemID
    || hand.itemID == ToolsHandler.shovelUltimate.itemID) {
    player.addPotionEffect(new PotionEffect(Potion.digSpeed.id,
    200, 2));
    }
    }
    if (player.getCurrentItemOrArmor(4) != null) {
    ItemStack helmet = player.getCurrentItemOrArmor(4);
    if (helmet.itemID == ArmorHandler.ultimateHelmet.itemID) {
    player.addPotionEffect(new PotionEffect(Potion.nightVision.id,
    200, 2));
    }
    }
    if (player.getCurrentItemOrArmor(3) != null) {
    ItemStack chest = player.getCurrentItemOrArmor(3);
    if (chest.itemID == ArmorHandler.ultimatePlate.itemID) {
    player.addPotionEffect(new PotionEffect(Potion.resistance.id,
    200, 2));
    }
    }
    if (player.getCurrentItemOrArmor(2) != null) {
    ItemStack legs = player.getCurrentItemOrArmor(2);
    if (legs.itemID == ArmorHandler.ultimatePants.itemID) {
    player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id,
    200, 2));
    }
    }
    if (player.getCurrentItemOrArmor(1) != null) {
    ItemStack boots = player.getCurrentItemOrArmor(1);
    if (boots.itemID == ArmorHandler.ultimateBoots.itemID) {
    player.addPotionEffect(new PotionEffect(Potion.jump.id, 200, 2));
    }
    }
    }
    
    @Override
    public void tickStart(EnumSet <ticktype>type, Object... tickData) {
    if (type.equals(EnumSet.of(TickType.PLAYER))) {
    onPlayerTick((EntityPlayer) tickData[0]);
    }
    }
    
    @Override
    public EnumSet <ticktype>ticks() {
    return EnumSet.of(TickType.PLAYER, TickType.SERVER);
    }
    
    @Override
    public void tickEnd(EnumSet <ticktype>type, Object… tickData) {
    
    }
    
    @Override
    public String getLabel() {
    return null;
    }
    }
    
    

    Code de l’EventHandler :

    package ast.mod.minecraftextension.event;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.event.ForgeSubscribe;
    import net.minecraftforge.event.entity.living.LivingHurtEvent;
    import ast.mod.minecraftextension.core.ItemHandler;
    
    public class EventHandler {
    @ForgeSubscribe
    public void onLivingHurt(LivingHurtEvent event) {
    if (event.entityLiving instanceof EntityPlayer) {
    if (event.entityLiving.getHeldItem() != null) {
    ItemStack hand = event.entityLiving.getHeldItem();
    if (hand.itemID == ItemHandler.leatherShield.itemID) {
    event.ammount = event.ammount - 2;
    hand.damageItem(1, event.entityLiving);
    }
    if (hand.itemID == ItemHandler.stoneShield.itemID) {
    event.ammount = event.ammount - 3;
    hand.damageItem(1, event.entityLiving);
    }
    if (hand.itemID == ItemHandler.ironShield.itemID) {
    event.ammount = event.ammount - 5;
    hand.damageItem(1, event.entityLiving);
    }
    if (hand.itemID == ItemHandler.goldShield.itemID) {
    event.ammount = event.ammount - 4;
    hand.damageItem(1, event.entityLiving);
    }
    if (hand.itemID == ItemHandler.diamondShield.itemID) {
    event.ammount = event.ammount - 6;
    hand.damageItem(1, event.entityLiving);
    }
    }
    }
    }
    }
    
    

    Merci d’avance :D</ticktype></ticktype></ticktype>

  • Moddeurs confirmés

    Pour le 2)
    http://www.minecraftforgefrance.fr/showthread.php?tid=130
    et pour le 1), je ne sais pas, regarde au niveau de l’effet slowness


  • Je vais regarder ça merci 😄