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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
package darkknight.jewelrycraft.worldGen;
import java.util.ArrayList;
import java.util.Random;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import darkknight.jewelrycraft.block.BlockList;
import darkknight.jewelrycraft.item.ItemList;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;
/**
* @author Sorin
*
*/
public class ChestGeneration {
static Item[] jewelry = new Item[] { ItemList.ring, ItemList.necklace, ItemList.bracelet, ItemList.earrings };
static Random random = new Random();
public static void preInit(FMLPreInitializationEvent e) {
{
ItemStack gloves = new ItemStack(ItemList.thiefGloves);
WeightedRandomChestContent wrcc = new WeightedRandomChestContent(gloves, 1, 1, 2);
addItemToDifferentPlaces(wrcc, true, true, false, false, true);
}
{
ItemStack guide = new ItemStack(ItemList.guide);
WeightedRandomChestContent wrcc = new WeightedRandomChestContent(guide, 1, 1, 7);
addItemToDifferentPlaces(wrcc, true, true, true, true, true, false, true, true);
}
{
ItemStack shadowIngot = new ItemStack(ItemList.shadowIngot);
addVillageBlacksmithLoot(new WeightedRandomChestContent(shadowIngot, 1, 4, 5));
}
for (int i = 0; i < 16 && i % 3 == 0; i++) {
{
ItemStack crystal = new ItemStack(BlockList.crystal, 1, i);
WeightedRandomChestContent wrcc = new WeightedRandomChestContent(crystal, 1, 3, 3);
addItemToDifferentPlaces(wrcc, true, true, true, true);
}
}
for (int i = 0; i < 4; i++) {
ItemStack special = new ItemStack(jewelry[i]);
int randValue = random.nextInt(4);
if (JewelrycraftUtil.metal.size() > 0) {
int rint = random.nextInt(JewelrycraftUtil.metal.size());
ItemStack metal = JewelrycraftUtil.metal.get(rint);
JewelryNBT.addMetal(special, metal);
}
if (JewelrycraftUtil.objects.size() > 0) {
ArrayList<ItemStack> modifiers = JewelrycraftUtil.addRandomModifiers(randValue);
JewelryNBT.addModifiers(special, modifiers);
}
if (JewelrycraftUtil.gem.size() > 0) {
int rint = random.nextInt(JewelrycraftUtil.gem.size());
ItemStack gem = JewelrycraftUtil.gem.get(rint);
JewelryNBT.addGem(special, gem);
}
WeightedRandomChestContent wrcc = new WeightedRandomChestContent(special, 1, 1, 1);
addItemToDifferentPlaces(wrcc, true, true, true, true);
}
}
/**
* The booleans determine in which places should the items be added. The order
* is like so:
* <p>
* <ul>
* <li>Dungeon
* <li>Stronhold
* <li>Pyramid
* <li>Mineshaft
* <li>Village Blacksmith
* <li>Dispenser
* <li>Bonus Chest
* <li>Stronghold Library
* </ul>
* <p>
*/
public static void addItemToDifferentPlaces(WeightedRandomChestContent item, Boolean... options) {
if (options.length > 0 && options[0])
addDungeonLoot(item);
if (options.length > 1 && options[1])
addStrongholdLoot(item);
if (options.length > 2 && options[2])
addPyramidLoot(item);
if (options.length > 3 && options[3])
addMineshaftLoot(item);
if (options.length > 4 && options[4])
addVillageBlacksmithLoot(item);
if (options.length > 5 && options[5])
addDispenserLoot(item);
if (options.length > 6 && options[6])
addBonusChestLoot(item);
if (options.length > 7 && options[7])
addStrongholdLibraryLoot(item);
}
public static void addDungeonLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, item);
}
public static void addStrongholdLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.STRONGHOLD_CORRIDOR, item);
ChestGenHooks.addItem(ChestGenHooks.STRONGHOLD_CROSSING, item);
}
public static void addPyramidLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.PYRAMID_DESERT_CHEST, item);
ChestGenHooks.addItem(ChestGenHooks.PYRAMID_JUNGLE_CHEST, item);
}
public static void addMineshaftLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.MINESHAFT_CORRIDOR, item);
}
public static void addVillageBlacksmithLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.VILLAGE_BLACKSMITH, item);
}
public static void addDispenserLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.PYRAMID_JUNGLE_DISPENSER, item);
}
public static void addBonusChestLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.BONUS_CHEST, item);
}
public static void addStrongholdLibraryLoot(WeightedRandomChestContent item) {
ChestGenHooks.addItem(ChestGenHooks.STRONGHOLD_LIBRARY, item);
}
}
|