1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package jp.plusplus.fbs.pottery.usable;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.registry.GameData;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
/**
* Created by plusplus_F on 2016/03/30.
*/
public class PotteryChange extends PotteryKeep {
private static Integer[] itemIds;
private Random rand=new Random();
@Override
public String getUnlocalizedName() {
return "pottery.fbs.pot.change";
}
@Override
public float getPriceScale(ItemStack pottery){
return 5.0f;
}
@Override
public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
if(itemStack!=null && !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index)){
if(itemIds==null){
Map<String,Integer> idMapping = Maps.newHashMap();
GameData.itemRegistry.serializeInto(idMapping);
itemIds=new Integer[idMapping.size()];
idMapping.values().toArray(itemIds);
}
for(int i=0;i<10;i++){
Item item=Item.getItemById(rand.nextInt(itemIds.length));
if(item==null) continue;
if(item instanceof ItemBlock){
Block b=((ItemBlock) item).field_150939_a;
Item d=b.getItemDropped(0, rand, 0);
if(d==null || d==Item.getItemById(0) || b.quantityDropped(0, 0, rand)==0){
continue;
}
}
ArrayList<ItemStack> list=new ArrayList<ItemStack>();
item.getSubItems(item, item.getCreativeTab(), list);
if(!list.isEmpty()){
ItemStack ret=list.get(rand.nextInt(list.size()));
ret.stackSize=Math.min(ret.getMaxStackSize(), itemStack.stackSize);
return ret;
}
}
}
return itemStack;
}
@Override
public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
return !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index);
}
}
|