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
|
package binnie.craftgui.binniecore;
import binnie.Binnie;
import binnie.core.AbstractMod;
import binnie.core.BinnieCore;
import binnie.core.genetics.BreedingSystem;
import binnie.core.genetics.ManagerGenetics;
import binnie.core.language.ManagerLanguage;
import binnie.core.machines.inventory.SlotValidator;
import binnie.core.machines.inventory.ValidatorIcon;
import binnie.craftgui.controls.ControlText;
import binnie.craftgui.controls.core.Control;
import binnie.craftgui.core.CraftGUI;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.geometry.TextJustification;
import binnie.craftgui.core.renderer.Renderer;
import binnie.craftgui.events.EventHandler.Origin;
import binnie.craftgui.events.EventValueChanged;
import binnie.craftgui.events.EventValueChanged.Handler;
import binnie.craftgui.minecraft.InventoryType;
import binnie.craftgui.minecraft.Window;
import binnie.craftgui.minecraft.WindowInventory;
import binnie.craftgui.minecraft.control.ControlImage;
import binnie.craftgui.minecraft.control.ControlPlayerInventory;
import binnie.craftgui.minecraft.control.ControlSlot;
import binnie.craftgui.resource.StyleSheet;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.resource.minecraft.PaddedTexture;
import binnie.craftgui.resource.minecraft.StandardTexture;
import binnie.extrabees.core.ExtraBeeTexture;
import binnie.extrabees.gui.punnett.ExtraBeeGUITexture;
import binnie.genetics.gui.ControlChromosome;
import binnie.genetics.machine.Analyser;
import cpw.mods.fml.relauncher.Side;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleRegistry;
import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ISpeciesRoot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class WindowFieldKit
extends Window
{
public WindowFieldKit(EntityPlayer player, IInventory inventory, Side side)
{
super(280.0F, 230.0F, player, inventory, side);
}
protected AbstractMod getMod()
{
return BinnieCore.instance;
}
protected String getName()
{
return "Field Kit";
}
private void setupValidators()
{
getWindowInventory().setValidator(0, new SlotValidator(null)
{
public boolean isValid(ItemStack object)
{
return (AlleleManager.alleleRegistry.isIndividual(object)) || (Binnie.Genetics.getConversion(object) != null);
}
public String getTooltip()
{
return "Individual";
}
});
getWindowInventory().setValidator(1, new SlotValidator(null)
{
public boolean isValid(ItemStack object)
{
return object.getItem() == Items.paper;
}
public String getTooltip()
{
return "Paper";
}
});
getWindowInventory().disableAutoDispense(1);
}
public void initialiseClient()
{
setTitle("Field Kit");
CraftGUI.Render.stylesheet(new StyleSheetPunnett());
getWindowInventory().createSlot(0);
getWindowInventory().createSlot(1);
setupValidators();
new ControlPlayerInventory(this);
IPoint handGlass = new IPoint(16.0F, 32.0F);
this.GlassControl = new ControlImage(this, handGlass.x(), handGlass.y(), new StandardTexture(0, 160, 96, 96, ExtraBeeTexture.GUIPunnett));
new ControlSlot(this, handGlass.x() + 54.0F, handGlass.y() + 26.0F).assign(InventoryType.Window, 0);
new ControlSlot(this, 208.0F, 8.0F).assign(InventoryType.Window, 1);
this.text = new ControlText(this, new IPoint(232.0F, 13.0F), "Paper");
this.text.setColour(2236962);
this.text = new ControlText(this, new IArea(0.0F, 120.0F, w(), 24.0F), "", TextJustification.MiddleCenter);
this.text.setColour(2236962);
this.chromo = new ControlChromosome(this, 150.0F, 24.0F);
addEventHandler(new EventValueChanged.Handler()
{
public void onEvent(EventValueChanged event)
{
IChromosomeType type = (IChromosomeType)event.getValue();
if ((type != null) && (WindowFieldKit.this.info.containsKey(type)))
{
String t = (String)WindowFieldKit.this.info.get(type);
WindowFieldKit.this.text.setValue(t);
}
else
{
WindowFieldKit.this.text.setValue("");
}
}
}.setOrigin(EventHandler.Origin.DirectChild, this.chromo));
}
public void initialiseServer()
{
ItemStack kit = getPlayer().getHeldItem();
int sheets = 64 - kit.getItemDamage();
if (sheets != 0) {
getWindowInventory().setInventorySlotContents(1, new ItemStack(Items.paper, sheets));
}
setupValidators();
}
private float glassOffsetX = 0.0F;
private float glassOffsetY = 0.0F;
private float glassVX = 0.0F;
private float glassVY = 0.0F;
private Random glassRand = new Random();
private Control GlassControl;
private ControlChromosome chromo;
private ControlText text;
private float analyseProgress = 1.0F;
private boolean isAnalysing = false;
public void onUpdateClient()
{
super.onUpdateClient();
if (this.isAnalysing)
{
this.analyseProgress += 0.01F;
if (this.analyseProgress >= 1.0F)
{
this.isAnalysing = false;
this.analyseProgress = 1.0F;
ItemStack stack = getWindowInventory().getStackInSlot(0);
if (stack != null) {
sendClientAction("analyse", new NBTTagCompound());
}
refreshSpecies();
}
}
this.glassVX += this.glassRand.nextFloat() - 0.5F - this.glassOffsetX * 0.2F;
this.glassVY += this.glassRand.nextFloat() - 0.5F - this.glassOffsetY * 0.2F;
this.glassOffsetX += this.glassVX;
this.glassOffsetX *= (1.0F - this.analyseProgress);
this.glassOffsetY += this.glassVY;
this.glassOffsetY *= (1.0F - this.analyseProgress);
this.GlassControl.setOffset(new IPoint(this.glassOffsetX, this.glassOffsetY));
}
private Map<IChromosomeType, String> info = new HashMap();
private void refreshSpecies()
{
ItemStack item = getWindowInventory().getStackInSlot(0);
if ((item == null) || (!AlleleManager.alleleRegistry.isIndividual(item))) {
return;
}
IIndividual ind = AlleleManager.alleleRegistry.getIndividual(item);
if (ind == null) {
return;
}
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(item);
this.chromo.setRoot(root);
Random rand = new Random();
this.info.clear();
for (IChromosomeType type : root.getKaryotype()) {
if (!Binnie.Genetics.isInvalidChromosome(type))
{
IAllele allele = ind.getGenome().getActiveAllele(type);
List<String> infos = new ArrayList();
int i = 0;
String pref = root.getUID() + ".fieldkit." + type.getName().toLowerCase() + ".";
while (Binnie.Language.canLocalise(pref + i))
{
infos.add(Binnie.Language.localise(pref + i));
i++;
}
String text = Binnie.Genetics.getSystem(root).getAlleleName(type, allele);
if (!infos.isEmpty()) {
text = (String)infos.get(rand.nextInt(infos.size()));
}
this.info.put(type, text);
this.chromo.setRoot(root);
}
}
}
private ItemStack prev = null;
public void onWindowInventoryChanged()
{
super.onWindowInventoryChanged();
if (isServer())
{
ItemStack kit = getPlayer().getHeldItem();
int sheets = 64 - kit.getItemDamage();
int size = getWindowInventory().getStackInSlot(1) == null ? 0 : getWindowInventory().getStackInSlot(1).stackSize;
if (sheets != size) {
kit.setItemDamage(64 - size);
}
((EntityPlayerMP)getPlayer()).updateHeldItem();
}
if (isClient())
{
ItemStack item = getWindowInventory().getStackInSlot(0);
this.prev = item;
this.text.setValue("");
if ((item != null) && (!Analyser.isAnalysed(item)))
{
if (getWindowInventory().getStackInSlot(1) == null)
{
this.text.setValue("No Paper!");
this.isAnalysing = false;
this.analyseProgress = 1.0F;
}
else
{
startAnalysing();
this.chromo.setRoot(null);
if (!damageKit()) {}
}
}
else if (item != null)
{
this.isAnalysing = false;
this.analyseProgress = 1.0F;
refreshSpecies();
if (!damageKit()) {}
}
else
{
this.isAnalysing = false;
this.analyseProgress = 1.0F;
this.chromo.setRoot(null);
}
}
}
private boolean damageKit()
{
return false;
}
private void startAnalysing()
{
this.glassVX = 0.0F;
this.glassVY = 0.0F;
this.glassOffsetX = 0.0F;
this.glassOffsetY = 0.0F;
this.isAnalysing = true;
this.analyseProgress = 0.0F;
}
public boolean showHelpButton()
{
return true;
}
public String showInfoButton()
{
return "The Field Kit analyses bees, trees, flowers and butterflies. All that is required is a piece of paper to jot notes";
}
public void recieveGuiNBT(Side side, EntityPlayer player, String name, NBTTagCompound action)
{
super.recieveGuiNBT(side, player, name, action);
if ((side == Side.SERVER) && (name.equals("analyse")))
{
getWindowInventory().setInventorySlotContents(0, Analyser.analyse(getWindowInventory().getStackInSlot(0)));
getWindowInventory().decrStackSize(1, 1);
}
}
static class StyleSheetPunnett
extends StyleSheet
{
public StyleSheetPunnett()
{
this.textures.put(CraftGUITexture.Window, new PaddedTexture(0, 0, 160, 160, 0, ExtraBeeTexture.GUIPunnett, 32, 32, 32, 32));
this.textures.put(CraftGUITexture.Slot, new StandardTexture(160, 0, 18, 18, 0, ExtraBeeTexture.GUIPunnett));
this.textures.put(ExtraBeeGUITexture.Chromosome, new StandardTexture(160, 36, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
this.textures.put(ExtraBeeGUITexture.Chromosome2, new StandardTexture(160, 52, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
this.textures.put(CraftGUITexture.HelpButton, new StandardTexture(178, 0, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
this.textures.put(CraftGUITexture.InfoButton, new StandardTexture(178, 16, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
}
}
}
|