Problème avec les portes



  • Salut à tous, donc je suis entrain de créer un mod qui ajoute une porte en obsidienne mais malheureusement je rencontre quelques difficultés.

    1. La porte a une résistance de 6000 mais explose quand même
    2. Lorsqu'on porte la partie du haut de la porte on obtient deux portes au lieu d'une seule

    BlockObsiDoor.java
    :::

    package qc.maxx.blocks;
    
    import java.util.Random;
    
    import qc.maxx.ores.EpicOres;
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockDoor;
    import net.minecraft.block.material.Material;
    import net.minecraft.client.renderer.IconFlipped;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.util.IIcon;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    public class BlockObsiDoor extends BlockDoor
    {
    public Item placerItem;
    public IIcon topDoorIcon;
    public IIcon[] flippedIcons = new IIcon[2];
    
    public BlockObsiDoor(Material mat)
    {
    super(mat);
    float f = 0.5F;
    float f1 = 1.0F;
    setLightOpacity(0);
    setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
    setBlockTextureName("EpicOres:door_obsidian");
    setHardness(50.0F);
    setStepSound(Block.soundTypeStone);
    setHarvestLevel("pickaxe", 3);
    setResistance(2000.0F);
    }
    
    public int getMobilityFlag()
       {
           return 2;
       }
    
    public IIcon getBlockTexture(IBlockAccess par1IBlockAccess, int par2,
    int par3, int par4, int par5) {
    if (par5 == 1 || par5 == 0) {
    return this.blockIcon;
    }
    int meta = func_150012_g(par1IBlockAccess, par2, par3, par4);
    boolean flag = (meta & 4) != 0;
    int halfMeta = meta & 3;
    boolean flipped = false;
    
    if (flag) {
    if (halfMeta == 0 && par5 == 2)
    flipped = !flipped;
    else if (halfMeta == 1 && par5 == 5)
    flipped = !flipped;
    else if (halfMeta == 2 && par5 == 3)
    flipped = !flipped;
    else if (halfMeta == 3 && par5 == 4)
    flipped = !flipped;
    } else {
    if (halfMeta == 0 && par5 == 5)
    flipped = !flipped;
    else if (halfMeta == 1 && par5 == 3)
    flipped = !flipped;
    else if (halfMeta == 2 && par5 == 4)
    flipped = !flipped;
    else if (halfMeta == 3 && par5 == 2)
    flipped = !flipped;
    if ((meta & 16) != 0)
    flipped = !flipped;
    }
    
    if (flipped)
    return flippedIcons[(meta & 8) != 0 ? 1 : 0];
    else
    return (meta & 8) != 0 ? this.topDoorIcon : this.blockIcon;
    }
    
    public IIcon getIcon(int par1, int par2) {
    return this.blockIcon;
    }
    
    public void registerIcons(IIconRegister iconRegister) {
    this.blockIcon = iconRegister.registerIcon(":EpicOres:door_obsidian_lower");
    this.topDoorIcon = iconRegister.registerIcon("EpicOres:door_obsidian_upper");
    this.flippedIcons[0] = new IconFlipped(blockIcon, true, false);
    this.flippedIcons[1] = new IconFlipped(topDoorIcon, true, false);
    }
    
    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
       {
           return EpicOres.ItemObsiDoor;
       }
    
    public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
       {
           return EpicOres.ItemObsiDoor;
       }
    }
    
    

    :::

    ItemObsiDoor.java
    :::

    package qc.maxx.items;
    
    import net.minecraft.block.Block;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemDoor;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.MathHelper;
    import net.minecraft.world.World;
    
    public class ItemObsiDoor extends Item {
    public Block doorBlock;
    
    public ItemObsiDoor(Block block) {
    super();
    this.doorBlock = block;
    setCreativeTab(CreativeTabs.tabRedstone);
    setTextureName("EpicOres:door_obsidian_icon");
    setMaxStackSize(1);
    }
    
    public boolean onItemUse(ItemStack par1ItemStack,
    EntityPlayer par2EntityPlayer, World par3World, int par4, int par5,
    int par6, int par7, float par8, float par9, float par10) {
    if (par7 != 1) {
    return false;
    } else {
    ++par5;
    Block block = this.doorBlock;
    
    if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7,
    par1ItemStack)
    && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6,
    par7, par1ItemStack)) {
    if (!block.canPlaceBlockAt(par3World, par4, par5, par6)) {
    return false;
    } else {
    int i1 = MathHelper
    .floor_double((double) ((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
    ItemDoor.placeDoorBlock(par3World, par4, par5, par6, i1,
    block);
    –par1ItemStack.stackSize;
    return true;
    }
    } else {
    return false;
    }
    }
    }
    
    public static void func_150924_a(World p_150924_0_, int p_150924_1_, int p_150924_2_, int p_150924_3_, int p_150924_4_, Block p_150924_5_)
       {
           byte var6 = 0;
           byte var7 = 0;
    
           if (p_150924_4_ == 0)
           {
               var7 = 1;
           }
    
           if (p_150924_4_ == 1)
           {
               var6 = -1;
           }
    
           if (p_150924_4_ == 2)
           {
               var7 = -1;
           }
    
           if (p_150924_4_ == 3)
           {
               var6 = 1;
           }
    
           int var8 = (p_150924_0_.getBlock(p_150924_1_ - var6, p_150924_2_, p_150924_3_ - var7).isNormalCube() ? 1 : 0) + (p_150924_0_.getBlock(p_150924_1_ - var6, p_150924_2_ + 1, p_150924_3_ - var7).isNormalCube() ? 1 : 0);
           int var9 = (p_150924_0_.getBlock(p_150924_1_ + var6, p_150924_2_, p_150924_3_ + var7).isNormalCube() ? 1 : 0) + (p_150924_0_.getBlock(p_150924_1_ + var6, p_150924_2_ + 1, p_150924_3_ + var7).isNormalCube() ? 1 : 0);
           boolean var10 = p_150924_0_.getBlock(p_150924_1_ - var6, p_150924_2_, p_150924_3_ - var7) == p_150924_5_ || p_150924_0_.getBlock(p_150924_1_ - var6, p_150924_2_ + 1, p_150924_3_ - var7) == p_150924_5_;
           boolean var11 = p_150924_0_.getBlock(p_150924_1_ + var6, p_150924_2_, p_150924_3_ + var7) == p_150924_5_ || p_150924_0_.getBlock(p_150924_1_ + var6, p_150924_2_ + 1, p_150924_3_ + var7) == p_150924_5_;
           boolean var12 = false;
    
           if (var10 && !var11)
           {
               var12 = true;
           }
           else if (var9 > var8)
           {
               var12 = true;
           }
    
           p_150924_0_.setBlock(p_150924_1_, p_150924_2_, p_150924_3_, p_150924_5_, p_150924_4_, 2);
           p_150924_0_.setBlock(p_150924_1_, p_150924_2_ + 1, p_150924_3_, p_150924_5_, 8 | (var12 ? 1 : 0), 2);
           p_150924_0_.notifyBlocksOfNeighborChange(p_150924_1_, p_150924_2_, p_150924_3_, p_150924_5_);
           p_150924_0_.notifyBlocksOfNeighborChange(p_150924_1_, p_150924_2_ + 1, p_150924_3_, p_150924_5_);
       }
    }
    

    :::

    Merci à tous ceux qui pourront m'aider 🙂


  • Administrateurs

    Problème 1 :
    Tu es sûr que c'est la porte qui explose et non le bloc en dessous ?
    Problème 2 :

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
       {
           return EpicOres.ItemObsiDoor;
       }
    

    ->

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
       {
           return (metadata & 8) != 0 ? null : EpicOres.ItemObsiDoor;
       }
    


  • @'robin4002':

    Problème 1 :
    Tu es sûr que c'est la porte qui explose et non le bloc en dessous ?
    Problème 2 :

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
       {
           return EpicOres.ItemObsiDoor;
       }
    

    ->

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
       {
           return (metadata & 8) != 0 ? null : EpicOres.ItemObsiDoor;
       }
    

    Merci à toi, je crois que tu as raison pour le problème 1. Je vais tester ce soir! 🙂
    EDIT: Problème 1 & 2 réglés 🙂 Merci.


  • Correcteurs

    Oublie pas ta balise résolu!