Приват модовых дверей

Версия Minecraft
1.7.10
210
1
19
Сделал несколько дверей, люков, калиток, наследуя их от ванильных. И никак не могу избавиться от одного противного бага. Если установить плагин MachineGuardReloaded и прописать мои двери в запреты, то двери не открываются(и не закрываются) только если кликать их по нижнему. Если кликать по верхнему блоку - он пишет, что нет прав, но визуально переключение происходит. Совместо с рассинхронизацией клиента и сервера: если дверь закрыта была, то она выглядит открытой, пройти не получается (сервер не даёт), а если была открыта и игрок мог пройти, то теперь выглядит закрытой и пройти опять-таки не получается - теперь уже не даёт клиент. С ванильными дверями такой петрушки нет.
Я уже грехом подумал, что верхний и нижний блоки вообще разные, залез в код, но там это один и тот же блок. Написал собственный плагин привата моих дверей, люков и калиток. Люки и калитки нормально работают, а с дверями та же байда, что и в случае с плагином MachineGuardReloaded. Пробовал гуглить - вроде грешат на сам мод - дескать, (в моём случае - мною) криво сделано.
Вот видео:

Вот код моей двери (не бейте по ушам, это было три года назад, я тогда тупо скопировал код ванильной двери и немного подровнял топором):
Java:
package ru.lao.rha.blocks.mechanics;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;

import ru.lao.rha.Main;
import ru.lao.rha.lists.RHItems;

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.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class Block_Door extends Block
{
    @SideOnly(Side.CLIENT)
    private IIcon[] field_150017_a;
    @SideOnly(Side.CLIENT)
    private IIcon[] field_150016_b;
    private static final String __OBFID = "CL_00000230";
    private String texture, type;
    private boolean nonHandable;
    private Material mat;

    public Block_Door(Material material, String texture, String type, boolean nonHandable)
    {
        super(material);
        this.mat = material;
        float f = 0.5F;
        float f1 = 1.0F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
        this.texture = texture;
        this.type = type;
        this.nonHandable = nonHandable;
       // hardness section ---------------------------------
        float hard = 0, resist = 0; String tool = "axe"; int lvl = 0; SoundType sound = soundTypeStone;
        if(material == Material.wood){    hard = 2f;    resist = 5f;    tool = "axe";        lvl = 1;    sound = soundTypeWood;}
        if(material == Material.iron){    hard = 5f;    resist = 15f;    tool = "pickaxe";    lvl = 1;    sound = soundTypeMetal;}
        if(material == Material.grass){    hard = 0.5f;resist = 6f;    tool = "shovel";    lvl = 1;    sound = soundTypeGrass;}
        if(material == Material.ground){hard = 0.4f;resist = 3f;    tool = "shovel";    lvl = 1;    sound = soundTypeGravel;}
        if(material == Material.glass){    hard = 0.5f;resist = 3f;    tool = "pickaxe";    lvl = 1;    sound = soundTypeGlass;}
        if(material == Material.rock){    hard = 2f;    resist = 12f;    tool = "pickaxe";    lvl = 0;    sound = soundTypeStone;}
        if(material == Material.gourd){    hard = 1f;    resist = 8f;    tool = "axe";        lvl = 1;    sound = soundTypeWood;}
        this.setHardness(hard);
        this.setResistance(resist);
        this.setHarvestLevel(tool, lvl);
        this.setStepSound(sound);
        // hardness section ---------------------------------
    }
    
    // скорость распространения огня
    @Override
    public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face)
    {
        if(mat == Material.wood){return 5;} else {return 0;}
    }
    
    // горючесть?
    @Override
    public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face)
    {
        if(mat == Material.wood){return 5;} else {return 0;}
    }
    
    // возгораемость?
    @Override
    public boolean isFlammable(IBlockAccess w, int x, int y, int z, ForgeDirection face){
        return getFlammability(w, x, y, z, face) > 0;
    }

    // прозрачность красок
    @Override
    public int getRenderBlockPass()
    {
        return 1;
    }
    
    /**
     * Gets the block's texture. Args: side, meta
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        return this.field_150016_b[0];
    }

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(IBlockAccess block, int x, int y, int z, int side)
    {
        if (side != 1 && side != 0)
        {
            int i1 = this.func_150012_g(block, x, y, z);
            int j1 = i1 & 3;
            boolean flag = (i1 & 4) != 0;
            boolean flag1 = false;
            boolean flag2 = (i1 & 8) != 0;

            if (flag)
            {
                if (j1 == 0 && side == 2)
                {
                    flag1 = !flag1;
                }
                else if (j1 == 1 && side == 5)
                {
                    flag1 = !flag1;
                }
                else if (j1 == 2 && side == 3)
                {
                    flag1 = !flag1;
                }
                else if (j1 == 3 && side == 4)
                {
                    flag1 = !flag1;
                }
            }
            else
            {
                if (j1 == 0 && side == 5)
                {
                    flag1 = !flag1;
                }
                else if (j1 == 1 && side == 3)
                {
                    flag1 = !flag1;
                }
                else if (j1 == 2 && side == 4)
                {
                    flag1 = !flag1;
                }
                else if (j1 == 3 && side == 2)
                {
                    flag1 = !flag1;
                }

                if ((i1 & 16) != 0)
                {
                    flag1 = !flag1;
                }
            }

            return flag2 ? this.field_150017_a[flag1?1:0] : this.field_150016_b[flag1?1:0];
        }
        else
        {
            return this.field_150016_b[0];
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_150017_a = new IIcon[2];
        this.field_150016_b = new IIcon[2];
        
        if(this.type.equalsIgnoreCase("stone") || this.type.equalsIgnoreCase("sand") || this.type.equalsIgnoreCase("dirt") ||
                this.type.equalsIgnoreCase("stone_r") || this.type.equalsIgnoreCase("sand_r") || this.type.equalsIgnoreCase("dirt_r")){
            this.field_150017_a[0] = p_149651_1_.registerIcon(texture);
            this.field_150016_b[0] = p_149651_1_.registerIcon(texture);
        } else if(this.type.equalsIgnoreCase("cobble") || this.type.equalsIgnoreCase("cobble_r")){
            this.field_150017_a[0] = p_149651_1_.registerIcon("cobblestone");
            this.field_150016_b[0] = p_149651_1_.registerIcon("cobblestone");
        } else if(this.type.equalsIgnoreCase("smoothbrick") || this.type.equalsIgnoreCase("smoothbrick_r")){
            this.field_150017_a[0] = p_149651_1_.registerIcon("stonebrick");
            this.field_150016_b[0] = p_149651_1_.registerIcon("stonebrick");
        } else {
            this.field_150017_a[0] = p_149651_1_.registerIcon(Main.MODID + ":door_" + texture + "_upper");
            this.field_150016_b[0] = p_149651_1_.registerIcon(Main.MODID + ":door_" + texture + "_lower");
        }

        this.field_150017_a[1] = new IconFlipped(this.field_150017_a[0], true, false);
        this.field_150016_b[1] = new IconFlipped(this.field_150016_b[0], true, false);
    }

    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean getBlocksMovement(IBlockAccess block, int x, int y, int z)
    {
        int l = this.func_150012_g(block, x, y, z);
        return (l & 4) != 0;
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 7;
    }

    /**
     * Returns the bounding box of the wired rectangular prism to render.
     */
    @SideOnly(Side.CLIENT)
    public AxisAlignedBB getSelectedBoundingBoxFromPool(World w, int x, int y, int z)
    {
        this.setBlockBoundsBasedOnState(w, x, y, z);
        return super.getSelectedBoundingBoxFromPool(w, x, y, z);
    }

    /**
     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
     * cleared to be reused)
     */
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World w, int x, int y, int z)
    {
        this.setBlockBoundsBasedOnState(w, x, y, z);
        return super.getCollisionBoundingBoxFromPool(w, x, y, z);
    }

    /**
     * Updates the blocks bounds based on its current state. Args: world, x, y, z
     */
    public void setBlockBoundsBasedOnState(IBlockAccess block, int x, int y, int z)
    {
        this.func_150011_b(this.func_150012_g(block, x, y, z));
    }

    public int func_150013_e(IBlockAccess block, int x, int y, int z)
    {
        return this.func_150012_g(block, x, y, z) & 3;
    }

    public boolean func_150015_f(IBlockAccess block, int x, int y, int z)
    {
        return (this.func_150012_g(block, x, y, z) & 4) != 0;
    }

    private void func_150011_b(int p_150011_1_)
    {
        float f = 0.1875F;
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
        int j = p_150011_1_ & 3;
        boolean flag = (p_150011_1_ & 4) != 0;
        boolean flag1 = (p_150011_1_ & 16) != 0;

        if (j == 0)
        {
            if (flag)
            {
                if (!flag1)
                {
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
                }
                else
                {
                    this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
                }
            }
            else
            {
                this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
            }
        }
        else if (j == 1)
        {
            if (flag)
            {
                if (!flag1)
                {
                    this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                }
                else
                {
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
                }
            }
            else
            {
                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
            }
        }
        else if (j == 2)
        {
            if (flag)
            {
                if (!flag1)
                {
                    this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
                }
                else
                {
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
                }
            }
            else
            {
                this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
            }
        }
        else if (j == 3)
        {
            if (flag)
            {
                if (!flag1)
                {
                    this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
                }
                else
                {
                    this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                }
            }
            else
            {
                this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
            }
        }
    }

    /**
     * Called when a player hits the block. Args: world, x, y, z, player
     */
    public void onBlockClicked(World w, int x, int y, int z, EntityPlayer player) {}

    /**
     * Called upon block activation (right click on the block.)
     */
    public boolean onBlockActivated(World w, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {// TODO
        if (this.nonHandable)
        {
            return false; //Allow items to interact with the door
        }
        else
        {
            int i1 = this.func_150012_g(w, x, y, z);
            int j1 = i1 & 7;
            j1 ^= 4;

            if ((i1 & 8) == 0)
            {
                w.setBlockMetadataWithNotify(x, y, z, j1, 2);
                w.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
            }
            else
            {
                w.setBlockMetadataWithNotify(x, y - 1, z, j1, 2);
                w.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
            }

            w.playAuxSFXAtEntity(player, 1003, x, y, z, 0);
            return true;
        }
    }

    public void func_150014_a(World w, int x, int y, int z, boolean p_150014_5_)
    {
        int l = this.func_150012_g(w, x, y, z);
        boolean flag1 = (l & 4) != 0;

        if (flag1 != p_150014_5_)
        {
            int i1 = l & 7;
            i1 ^= 4;

            if ((l & 8) == 0)
            {
                w.setBlockMetadataWithNotify(x, y, z, i1, 2);
                w.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
            }
            else
            {
                w.setBlockMetadataWithNotify(x, y - 1, z, i1, 2);
                w.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
            }

            w.playAuxSFXAtEntity((EntityPlayer)null, 1003, x, y, z, 0);
        }
    }

    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor Block
     */
    public void onNeighborBlockChange(World w, int x, int y, int z, Block block)
    {
        int l = w.getBlockMetadata(x, y, z);

        if ((l & 8) == 0)
        {
            boolean flag = false;

            if (w.getBlock(x, y + 1, z) != this)
            {
                w.setBlockToAir(x, y, z);
                flag = true;
            }

            if (!World.doesBlockHaveSolidTopSurface(w, x, y - 1, z))
            {
                w.setBlockToAir(x, y, z);
                flag = true;

                if (w.getBlock(x, y + 1, z) == this)
                {
                    w.setBlockToAir(x, y + 1, z);
                }
            }

            if (flag)
            {
                if (!w.isRemote)
                {
                    this.dropBlockAsItem(w, x, y, z, l, 0);
                }
            }
            else
            {
                boolean flag1 = w.isBlockIndirectlyGettingPowered(x, y, z) || w.isBlockIndirectlyGettingPowered(x, y + 1, z);

                if ((flag1 || block.canProvidePower()) && block != this)
                {
                    this.func_150014_a(w, x, y, z, flag1);
                }
            }
        }
        else
        {
            if (w.getBlock(x, y - 1, z) != this)
            {
                w.setBlockToAir(x, y, z);
            }

            if (block != this)
            {
                this.onNeighborBlockChange(w, x, y - 1, z, block);
            }
        }
    }

    public Item getItemForType(String type){
        Item item = null;
        if(type.equalsIgnoreCase("acacia")) item = RHItems.acaciaDoor;
        if(type.equalsIgnoreCase("spruce")) item = RHItems.spruceDoor;
        if(type.equalsIgnoreCase("birch")) item = RHItems.birchDoor;
        if(type.equalsIgnoreCase("jungle")) item = RHItems.jungleDoor;
        if(type.equalsIgnoreCase("dark_oak")) item = RHItems.darkoakDoor;
        if(type.equalsIgnoreCase("iron")) item = RHItems.ironDoor;
        if(type.equalsIgnoreCase("gold")) item = RHItems.goldDoor;
        if(type.equalsIgnoreCase("bronze")) item = RHItems.bronzeDoor;
        if(type.equalsIgnoreCase("wyvern")) item = RHItems.wyvernDoor;
        if(type.equalsIgnoreCase("ogre")) item = RHItems.ogreDoor;
        if(type.equalsIgnoreCase("oro")) item = RHItems.oroDoor;
        if(type.equalsIgnoreCase("amaranth")) item = RHItems.amaranthDoor;
        if(type.equalsIgnoreCase("blackwood")) item = RHItems.blackwoodDoor;
        if(type.equalsIgnoreCase("cherry")) item = RHItems.cherryDoor;
        
        if(type.equalsIgnoreCase("dirt")) item = RHItems.dirtDoor;
        if(type.equalsIgnoreCase("stone")) item = RHItems.stoneDoor;
        if(type.equalsIgnoreCase("smoothbrick")) item = RHItems.smoothbrickDoor;
        if(type.equalsIgnoreCase("sand")) item = RHItems.sandDoor;
        if(type.equalsIgnoreCase("cobble")) item = RHItems.cobbleDoor;
        
        if(type.equalsIgnoreCase("acacia_r")) item = RHItems.acaciaRDoor;
        if(type.equalsIgnoreCase("spruce_r")) item = RHItems.spruceRDoor;
        if(type.equalsIgnoreCase("birch_r")) item = RHItems.birchRDoor;
        if(type.equalsIgnoreCase("jungle_r")) item = RHItems.jungleRDoor;
        if(type.equalsIgnoreCase("dark_oak_r")) item = RHItems.darkoakRDoor;
        if(type.equalsIgnoreCase("oak_r")) item = RHItems.oakRDoor;
        if(type.equalsIgnoreCase("gold_r")) item = RHItems.goldRDoor;
        if(type.equalsIgnoreCase("bronze_r")) item = RHItems.bronzeRDoor;
        if(type.equalsIgnoreCase("wyvern_r")) item = RHItems.wyvernRDoor;
        if(type.equalsIgnoreCase("ogre_r")) item = RHItems.ogreRDoor;
        if(type.equalsIgnoreCase("oro_r")) item = RHItems.oroRDoor;
        if(type.equalsIgnoreCase("amaranth_r")) item = RHItems.amaranthRDoor;
        if(type.equalsIgnoreCase("blackwood_r")) item = RHItems.blackwoodRDoor;
        if(type.equalsIgnoreCase("cherry_r")) item = RHItems.cherryRDoor;
        
        if(type.equalsIgnoreCase("dirt_r")) item = RHItems.dirtRDoor;
        if(type.equalsIgnoreCase("stone_r")) item = RHItems.stoneRDoor;
        if(type.equalsIgnoreCase("smoothbrick_r")) item = RHItems.smoothbrickRDoor;
        if(type.equalsIgnoreCase("sand_r")) item = RHItems.sandRDoor;
        if(type.equalsIgnoreCase("cobble_r")) item = RHItems.cobbleRDoor;
        return item;
    }
    
  
    @Override
    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        if((p_149650_1_ & 8) != 0) return null;
        
        return getItemForType(type);
    }

    /**
     * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world,
     * x, y, z, startVec, endVec
     */
    public MovingObjectPosition collisionRayTrace(World w, int x, int y, int z, Vec3 vec31, Vec3 vec32)
    {
        this.setBlockBoundsBasedOnState(w, x, y, z);
        return super.collisionRayTrace(w, x, y, z, vec31, vec32);
    }

    /**
     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
     */
    public boolean canPlaceBlockAt(World w, int x, int y, int z)
    {
        return y >= w.getHeight() - 1 ? false : World.doesBlockHaveSolidTopSurface(w, x, y - 1, z) && super.canPlaceBlockAt(w, x, y, z) && super.canPlaceBlockAt(w, x, y + 1, z);
    }

    /**
     * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
     * and stop pistons
     */
    public int getMobilityFlag()
    {
        return 1;
    }

    public int func_150012_g(IBlockAccess p_150012_1_, int p_150012_2_, int p_150012_3_, int p_150012_4_)
    {
        int l = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_, p_150012_4_);
        boolean flag = (l & 8) != 0;
        int i1;
        int j1;

        if (flag)
        {
            i1 = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_ - 1, p_150012_4_);
            j1 = l;
        }
        else
        {
            i1 = l;
            j1 = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_ + 1, p_150012_4_);
        }

        boolean flag1 = (j1 & 1) != 0;
        return i1 & 7 | (flag ? 8 : 0) | (flag1 ? 16 : 0);
    }

    /**
     * Gets an item for the block being called on. Args: world, x, y, z
     */
    @Override
    @SideOnly(Side.CLIENT)
    public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
    { //TODO
        
        
        return getItemForType(type);
        
        
        
        //return this.blockMaterial == Material.iron ? Items.iron_door : Items.wooden_door;
    }

    /**
     * Called when the block is attempted to be harvested
     */
    @Override
    public void onBlockHarvested(World w, int x, int y, int z, int p_149681_5_, EntityPlayer player)
    {
        if (player.capabilities.isCreativeMode && (p_149681_5_ & 8) != 0 && w.getBlock(x, y - 1, z) == this)
        {
            w.setBlockToAir(x, y - 1, z);
        }
    }
}
 
7,099
324
1,510
if ((i1 & 8) == 0) { w.setBlockMetadataWithNotify(x, y, z, j1, 2); w.markBlockRangeForRenderUpdate(x, y, z, x, y, z); } else { w.setBlockMetadataWithNotify(x, y - 1, z, j1, 2); w.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z); }
Проблема явно здесь: при клике по верхнему блоку изменяется только нижний
 
210
1
19
Повтыкал в этот код минут пятнадцать, ничего не придумал, пошёл снова тестировать. Есть в плагине приватов команда /mgid, она выводит метадату блока, на который смотришь. Попробовал вписать в конфиг все варианты - со всеми метадатами. Ничего не изменилось. Интересно, что нижний блок имеет несколько метадат, зависит число от "открыто"/"закрыто" и от того, куда повернута дверь относительно сторон света. А верхний блок всегда имеет метадату 8. Никаких идей?

WrogQZq4QD.png
 
7,099
324
1,510
Так надо изменять мету верхнего тоже при открытии/закрытии
 
210
1
19
Попробовал поэкспериментировать с MalisisDoors. Вообще не реагирует, ни нижняя, ни верхняя секция. У него тоже верхняя секция всегда имеет мету 8, нижняя меняется. Как и у меня, сделано по образу и подобию ванильной.
uCs20ETeig.png




Скачал исходники MalisisDoors. оказывается, у него каждая дверь имеет в себе TileEntity. И статус двери переключается через него.

Update: Я перепутал конфиги от соседних серверов. Работает блокирование дверей MalisisDoors (с TileEntity), корректно на обе половины. Что, переделывать свои двери на манер их дверей теперь? С ванильным вариантом никто не поможет? :(
 
Последнее редактирование:
Сверху