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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
package gtPlusPlus.xmod.forestry.bees.alveary;
import java.util.*;
import forestry.api.apiculture.*;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.genetics.*;
import forestry.api.multiblock.IAlvearyComponent;
import forestry.apiculture.AlvearyBeeModifier;
import forestry.apiculture.network.packets.PacketActiveUpdate;
import forestry.apiculture.worldgen.*;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.wrappers.IInvSlot;
import forestry.core.inventory.wrappers.InventoryIterator;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.IActivatable;
import forestry.core.utils.ItemStackUtil;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.xmod.forestry.bees.alveary.gui.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class TileAlvearyFrameHousing
extends FR_TileAlveary
implements ISidedFrameWearingInventory, IActivatable, IAlvearyComponent.Active, IAlvearyComponent.BeeModifier, IAlvearyFrameHousing, IAlvearyComponent.BeeListener
{
private final InventoryFrameHousing inventory;
private final IBeeListener beeListener;
private final Stack<ItemStack> pendingSpawns = new Stack<>();
private boolean active;
public TileAlvearyFrameHousing()
{
super(FR_BlockAlveary.Type.FRAME);
this.inventory = new InventoryFrameHousing(this);
this.beeListener = new AlvearyFrameHousingBeeListener(this.inventory);
}
@Override
public IInventoryAdapter getInternalInventory()
{
return this.inventory;
}
@Override
public boolean allowsAutomation()
{
return true;
}
@Override
public void updateServer(final int tickCount)
{
if (this.getInternalInventory() == null) {
return;
}
if (this.inventory.getStackInSlot(0) != null)
{
if (this.getMultiblockLogic().getController().getBeekeepingLogic().canWork()){
this.setActive(true);
if ((tickCount % 1000) == 0) {
this.wearOutFrames(this, 1);
}
}
else {
Utils.LOG_INFO("Cannot work - Probably no queen alive.");
}
}
else
{
this.setActive(false);
}
if ((tickCount % 500) != 0) {
return;
}
}
@Override
public void updateClient(final int tickCount) {}
private ItemStack getPrincessStack()
{
final ItemStack princessStack = this.getMultiblockLogic().getController().getBeeInventory().getQueen();
if (BeeManager.beeRoot.isMated(princessStack)) {
return princessStack;
}
return null;
}
private int consumeInducerAndGetChance()
{
if (this.getInternalInventory() == null) {
return 0;
}
for (final Iterator<?> i$ = InventoryIterator.getIterable(this.getInternalInventory()).iterator(); i$.hasNext();)
{
final IInvSlot slot = (IInvSlot)i$.next();
final ItemStack stack = slot.getStackInSlot();
for (final Map.Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
if (ItemStackUtil.isIdenticalItem(entry.getKey(), stack))
{
slot.decreaseStackInSlot();
return entry.getValue().intValue();
}
}
}
final IInvSlot slot;
final ItemStack stack;
return 0;
}
private void trySpawnSwarm()
{
final ItemStack toSpawn = this.pendingSpawns.peek();
final HiveDescriptionSwarmer hiveDescription = new HiveDescriptionSwarmer(new ItemStack[] { toSpawn });
final Hive hive = new Hive(hiveDescription);
final int chunkX = ((this.xCoord + this.worldObj.rand.nextInt(80)) - 40) / 16;
final int chunkZ = ((this.zCoord + this.worldObj.rand.nextInt(80)) - 40) / 16;
if (HiveDecorator.genHive(this.worldObj, this.worldObj.rand, chunkX, chunkZ, hive)) {
this.pendingSpawns.pop();
}
}
@Override
protected void encodeDescriptionPacket(final NBTTagCompound packetData)
{
super.encodeDescriptionPacket(packetData);
packetData.setBoolean("Active", this.active);
}
@Override
protected void decodeDescriptionPacket(final NBTTagCompound packetData)
{
super.decodeDescriptionPacket(packetData);
this.setActive(packetData.getBoolean("Active"));
}
@Override
public int getIcon(final int side)
{
if ((side == 0) || (side == 1)) {
return 2;
}
if (this.active) {
return 6;
}
return 5;
}
@Override
public void readFromNBT(final NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
this.setActive(nbttagcompound.getBoolean("Active"));
final NBTTagList nbttaglist = nbttagcompound.getTagList("PendingSpawns", 10);
for (int i = 0; i < nbttaglist.tagCount(); i++)
{
final NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
this.pendingSpawns.add(ItemStack.loadItemStackFromNBT(nbttagcompound1));
}
}
@Override
public void writeToNBT(final NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
nbttagcompound.setBoolean("Active", this.active);
final NBTTagList nbttaglist = new NBTTagList();
final ItemStack[] offspring = this.pendingSpawns.toArray(new ItemStack[this.pendingSpawns.size()]);
for (int i = 0; i < offspring.length; i++) {
if (offspring[i] != null)
{
final NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
offspring[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbttagcompound.setTag("PendingSpawns", nbttaglist);
}
@Override
public boolean isActive()
{
return this.active;
}
@Override
public void setActive(final boolean active)
{
if (this.active == active) {
return;
}
this.active = active;
if (!this.worldObj.isRemote) {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), this.worldObj);
}
}
@Override
public Object getGui(final EntityPlayer player, final int data)
{
return new GUI_FrameHousing(this, player);
}
@Override
public Object getContainer(final EntityPlayer player, final int data)
{
return new CONTAINER_FrameHousing(this, player);
}
private final IBeeModifier beeModifier = new AlvearyBeeModifier();
//private final IBeeListener beeListener = new AlvearyBeeListener(this);
private final Iterable<IBeeListener> beeListenerList = this.getMultiblockLogic().getController().getBeeListeners();
@Override
public Collection<IBeeModifier> getBeeModifiers()
{
final List<IBeeModifier> beeModifiers = new ArrayList<>();
beeModifiers.add(this.beeModifier);
for (final IHiveFrame frame : this.getFrames(this.inventory)) {
beeModifiers.add(frame.getBeeModifier());
}
return beeModifiers;
}
public Collection<IHiveFrame> getFrames(final IInventory inventory)
{
final Collection<IHiveFrame> hiveFrames = new ArrayList<>(inventory.getSizeInventory());
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
final ItemStack stackInSlot = this.getStackInSlot(i);
if (stackInSlot != null)
{
final Item itemInSlot = stackInSlot.getItem();
if ((itemInSlot instanceof IHiveFrame)) {
hiveFrames.add((IHiveFrame)itemInSlot);
}
}
}
return hiveFrames;
}
@Override
public IBeeModifier getBeeModifier() {
final List<IBeeModifier> beeModifiers = new ArrayList<>();
//beeModifiers.add(this.beeModifier);
for (final IHiveFrame frame : this.getFrames(this.inventory)) {
beeModifiers.add(frame.getBeeModifier());
}
return beeModifiers.get(0);
}
private ItemStack getQueenStack()
{
final ItemStack queenStack = this.getMultiblockLogic().getController().getBeeInventory().getQueen();
return queenStack;
}
@Override
public void wearOutFrames(final IBeeHousing beeHousing, final int amount)
{
final IBeekeepingMode beekeepingMode = BeeManager.beeRoot.getBeekeepingMode(beeHousing.getWorld());
final int wear = Math.round(amount * beekeepingMode.getWearModifier());
for (int i = 0; i < this.inventory.getSizeInventory(); i++)
{
final ItemStack hiveFrameStack = this.getStackInSlot(i);
if (hiveFrameStack != null)
{
final Item hiveFrameItem = hiveFrameStack.getItem();
if ((hiveFrameItem instanceof IHiveFrame))
{
final IHiveFrame hiveFrame = (IHiveFrame)hiveFrameItem;
Utils.LOG_INFO("Wearing out frame by "+amount);
final ItemStack queenStack = this.getQueenStack();
final IBee queen = BeeManager.beeRoot.getMember(queenStack);
final ItemStack usedFrame = hiveFrame.frameUsed(beeHousing, hiveFrameStack, queen, wear);
//((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeListeners().
this.setInventorySlotContents(i, usedFrame);
}
}
}
}
@Override
public InventoryFrameHousing getAlvearyInventory() {
return this.inventory;
}
@Override
public IBeeListener getBeeListener() {
return this.beeListener;
}
static class AlvearyFrameHousingBeeListener
extends DefaultBeeListener
{
private final InventoryFrameHousing inventory;
public AlvearyFrameHousingBeeListener(final InventoryFrameHousing inventory)
{
this.inventory = inventory;
}
@Override
public boolean onPollenRetrieved(final IIndividual pollen)
{
/*if (!((Object) this.inventory).canStorePollen()) {
return false;
}*/
final ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(pollen.getClass());
final ItemStack pollenStack = speciesRoot.getMemberStack(pollen, EnumGermlingType.POLLEN.ordinal());
if (pollenStack != null)
{
// ((Object) this.inventory).storePollenStack(pollenStack);
return true;
}
return false;
}
}
}
|