Не работает метод OnBlockDestroyed

Есть код который выполняет некоторые действий при  разрушении блока, но данный метод не работает.
Код:
package ua.crazy_dayv.new_craft.blocks;

import java.util.Random;

import ua.crazy_dayv.new_craft.ModInfo;
import ua.crazy_dayv.new_craft.items.Items;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class radiation_block extends Block 
{
    
    public radiation_block(String name)
    {
        super(Material.ground); 
        this.setBlockName(name);
        this.setHardness(15F);
        this.setResistance(10F);
        this.setHarvestLevel("pickaxe", 1);
        this.setLightLevel(150F);
        this.setBlockTextureName(ModInfo.MODID + ":radiation_block");
    }
    
    public void onBlockDestroyed(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    {
        if(par5EntityPlayer.getCurrentEquippedItem() != null)
        {
            if(par5EntityPlayer.getCurrentEquippedItem().getItem() != Items.coal_pickaxe)
            {
                par5EntityPlayer.addPotionEffect(new PotionEffect(9, 600, 1));
            } else {
                if (par5EntityPlayer.inventory.armorItemInSlot(3) != null && par5EntityPlayer.inventory.armorItemInSlot(2) != null && par5EntityPlayer.inventory.armorItemInSlot(1) != null && par5EntityPlayer.inventory.armorItemInSlot(0) != null && par5EntityPlayer.inventory.armorItemInSlot(3).getItem() == Items.coal_helmet && par5EntityPlayer.inventory.armorItemInSlot(2).getItem() == Items.coal_chest && par5EntityPlayer.inventory.armorItemInSlot(1).getItem() == Items.coal_leggings && par5EntityPlayer.inventory.armorItemInSlot(0).getItem() == Items.coal_boots) 
                {
                    par5EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(263)));
                }
            }
        } else {
            par5EntityPlayer.addPotionEffect(new PotionEffect(9, 600, 1));
        }
    }
    
    public boolean isOpaqueCube()
    {
        return false;
    }
    
    @Override
    public Item getItemDropped(int par1, Random par2Random, int par3)
    {
        return null;
    }
    
}
 

timaxa007

Модератор
5,831
409
672
smurfik997, и в каком месте у тебя находиться код, что-бы сработал твой метод onBlockDestroyed? В блоке есть метод "onBlockDestroyedByPlayer" и "onBlockDestroyedByExplosion", но нету "onBlockDestroyed".
 
timaxa007 написал(а):
smurfik997, и в каком месте у тебя находиться код, что-бы сработал метод onBlockDestroyed? В блоке есть метод "onBlockDestroyedByPlayer" и "onBlockDestroyedByExplosion".
Нет, а что в новых версиях нужен?
 

timaxa007

Модератор
5,831
409
672
В новых? Хм... Это зависит от того чего надо тебе от метода. Но скорее всего тебе подойдёт метод onBlockHarvested.
 
timaxa007 написал(а):
В новых? Хм... Это зависит от того чего надо тебе от метода. Но скорее всего тебе подойдёт метод onBlockHarvested.
Все я разобрался, теперь если ломаешь блок спец. киркой, то ничего не происходит, а если просто рукой или другим предметом, то выдается эффект тошноты. Но теперь не работает проверка на броню и если она есть, то не выдается уголь.
Код:
package ua.crazy_dayv.new_craft.blocks;

import java.util.Random;

import ua.crazy_dayv.new_craft.ModInfo;
import ua.crazy_dayv.new_craft.items.Items;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class radiation_block extends Block 
{
    
    public radiation_block(String name)
    {
        super(Material.ground); 
        this.setBlockName(name);
        this.setLightLevel(150F);
        this.setBlockTextureName(ModInfo.MODID + ":radiation_block");
    }
    
    public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    {
        if(par5EntityPlayer.getCurrentEquippedItem() != null)
        {
            if(par5EntityPlayer.getCurrentEquippedItem().getItem() != Items.coal_pickaxe)
            {
                par5EntityPlayer.addPotionEffect(new PotionEffect(9, 600, 1));
            } else {
                if (par5EntityPlayer.inventory.armorItemInSlot(3) != null && par5EntityPlayer.inventory.armorItemInSlot(2) != null && par5EntityPlayer.inventory.armorItemInSlot(1) != null && par5EntityPlayer.inventory.armorItemInSlot(0) != null && par5EntityPlayer.inventory.armorItemInSlot(0).getItem() == Items.coal_helmet && par5EntityPlayer.inventory.armorItemInSlot(1).getItem() == Items.coal_chest && par5EntityPlayer.inventory.armorItemInSlot(2).getItem() == Items.coal_leggings && par5EntityPlayer.inventory.armorItemInSlot(3).getItem() == Items.coal_boots) 
                {
                    par5EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(263)));
                }
            }
        } else {
            par5EntityPlayer.addPotionEffect(new PotionEffect(9, 600, 1));
        }
    }
    
    public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    {
        onBlockDestroyedByPlayer(par1World, par4, par4, par4, par5EntityPlayer);
    }

    public boolean isOpaqueCube()
    {
        return false;
    }
    
    @Override
    public Item getItemDropped(int par1, Random par2Random, int par3)
    {
        return null;
    }
    
}
 

timaxa007

Модератор
5,831
409
672
smurfik997, ты даже не глядел в класс блока какие нужны аргументы, чтобы использовать нужный метод (а он там только один).
 
Я все исправил. ​
Теперь когда ломаешь блок спец. киркой, то ничего не происходит. Если ломаешь блок спец. киркой и при этом у тебя спец. броня, то с блока дропается уголь. Когда ломаешь блок рукой или другим предметом выдается эффект тошноты на 30 сек.
Вот готовый код.
Код:
package ua.crazy_dayv.new_craft.blocks;

import java.util.Random;

import ua.crazy_dayv.new_craft.ModInfo;
import ua.crazy_dayv.new_craft.items.Items;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class radiation_block extends Block 
{

    private Item dropItem = null;

    public radiation_block(String name)
    {
        super(Material.ground); 
        this.setBlockName(name);
        this.setLightLevel(150F);
        this.setBlockTextureName(ModInfo.MODID + ":radiation_block");
    }
    
    public void onBlockDestroyedByPlayer(World World, int x, int y, int z, EntityPlayer Player)
    {
        if(Player.getCurrentEquippedItem() != null)
        {
            if(Player.getCurrentEquippedItem().getItem() != Items.coal_pickaxe)
            {
                Player.addPotionEffect(new PotionEffect(9, 600, 1));
                dropItem = null;
            } else {
                if (Player.inventory.armorItemInSlot(0) != null && Player.inventory.armorItemInSlot(1) != null && Player.inventory.armorItemInSlot(2) != null && Player.inventory.armorItemInSlot(3) != null && Player.inventory.armorItemInSlot(3).getItem() == Items.coal_helmet && Player.inventory.armorItemInSlot(2).getItem() == Items.coal_chest && Player.inventory.armorItemInSlot(1).getItem() == Items.coal_leggings && Player.inventory.armorItemInSlot(0).getItem() == Items.coal_boots) 
                {
                    dropItem = Item.getItemById(263);
                } else {
                    dropItem = null;
                }
            }
        } else {
            Player.addPotionEffect(new PotionEffect(9, 600, 1));
            dropItem = null;
        }
    }
    
    public void onBlockClicked(World World, int x, int y, int z, EntityPlayer Player)
    {
        onBlockDestroyedByPlayer(World, x, y, z, Player);
    }

    public AxisAlignedBB getCollisionBoundingsu_boxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }
    
    @Override
    public Item getItemDropped(int par1, Random par2Random, int par3)
    {
        return dropItem;
    }

    
}


 

timaxa007

Модератор
5,831
409
672
Название метода то, но вот аргументы не те.
Код:
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int metadata) {

}
 
Сверху