Использовал код из одной темы,впихнул вместо ванильных вещей , свои из мода,но оно не работает,выпадают только ванильные
И еще вопрос,как сделать проверку на заполненность инвентаря,что бы если инвентарь заполнень ничего не происходило и выдавало в чат что то типо "Инвентарь переполнен"
Код:
public class rndbox extends Item {
private ArrayList<DropsItem> list_drops = new ArrayList<DropsItem>();
public rndbox() {
super();
setCreativeTab(CreativeTabs.tabMisc);
this.setTextureName("testmod:rndbox");
addItemWithChance(25F, Items.stick);
addItemWithChance(25F, Items.beef);
addItemWithChance(25F, Main.coin1);
addItemWithChance(25F, Main.coin2);
}
@Override
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
if (!world.isRemote) {
float p = world.rand.nextFloat() * getChanceMax();
ItemStack item_drop = null;
if (list_drops != null)
for (int i = 0; i < list_drops.size(); ++i) {
if (list_drops.get(i) != null) {
if (list_drops.get(i).getChanceA() <= p && list_drops.get(i).getChanceB() > p) {
item_drop = list_drops.get(i).getItem().copy();
//System.out.println("onItemRightClick - " + p + ", " + item_drop);
break;
}
}
}
if (item_drop != null) {
player.inventory.addItemStackToInventory(item_drop);
--is.stackSize;
}
}
return is;
}
public void addItemWithChance(float chance, Object item) {
float a = 0F;
if (list_drops != null && list_drops.size() > 0) {
float b = -1F;
for (int i = 0; i < list_drops.size(); ++i) {
if (list_drops.get(i) != null) {
if (b < list_drops.get(i).getChanceB()) b = list_drops.get(i).getChanceB();
else continue;
} else continue;
}
if (b != -1F) a = b;
}
list_drops.add(new DropsItem(a, a + chance, item));
}
public float getChanceMax() {
float a = 0F;
if (list_drops != null && list_drops.size() > 0) {
float b = -1;
for (int i = 0; i < list_drops.size(); ++i) {
if (list_drops.get(i) != null) {
if (b < list_drops.get(i).getChanceB()) b = list_drops.get(i).getChanceB();
else continue;
} else continue;
}
if (b != -1) a = b;
}
return a;
}
private static class DropsItem {
private ItemStack item;
private float chanceA;
private float chanceB;
private DropsItem(float chanceA, float chanceB, Object item) {
if (item == null) return;
if (item != null) {
if (item instanceof Block) this.item = new ItemStack((Block)item);
else if (item instanceof Item) this.item = new ItemStack((Item)item);
else if (item instanceof ItemStack) this.item = (ItemStack)item;
//this.item = item;
}
this.chanceA = chanceA;
this.chanceB = chanceB;
}
public ItemStack getItem() {
return item;
}
public float getChanceA() {
return chanceA;
}
public float getChanceB() {
return chanceB;
}
}
}