mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-25 14:34:33 +00:00
port to forestry 4.2
This commit is contained in:
1 parent
dbc5c1a564
commit
f969f63b66
3697 files changed
+78372
No files matched your search
@@ -0,0 +1,298 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.binniecore;
|
||||
|
||||
import binnie.extrabees.gui.punnett.ExtraBeeGUITexture;
|
||||
import binnie.craftgui.resource.minecraft.PaddedTexture;
|
||||
import binnie.craftgui.resource.minecraft.CraftGUITexture;
|
||||
import binnie.craftgui.resource.StyleSheet;
|
||||
import binnie.genetics.machine.Analyser;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import java.util.List;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import binnie.craftgui.events.EventHandler;
|
||||
import binnie.craftgui.events.EventValueChanged;
|
||||
import binnie.craftgui.core.geometry.TextJustification;
|
||||
import binnie.craftgui.core.geometry.IArea;
|
||||
import binnie.craftgui.minecraft.InventoryType;
|
||||
import binnie.craftgui.minecraft.control.ControlSlot;
|
||||
import binnie.craftgui.minecraft.control.ControlImage;
|
||||
import binnie.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.extrabees.core.ExtraBeeTexture;
|
||||
import binnie.craftgui.core.geometry.IPoint;
|
||||
import binnie.craftgui.minecraft.control.ControlPlayerInventory;
|
||||
import binnie.craftgui.core.CraftGUI;
|
||||
import net.minecraft.init.Items;
|
||||
import binnie.Binnie;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.AbstractMod;
|
||||
import java.util.HashMap;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import java.util.Map;
|
||||
import binnie.craftgui.controls.ControlText;
|
||||
import binnie.genetics.gui.ControlChromosome;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
import java.util.Random;
|
||||
import binnie.craftgui.minecraft.Window;
|
||||
|
||||
public class WindowFieldKit extends Window
|
||||
{
|
||||
private float glassOffsetX;
|
||||
private float glassOffsetY;
|
||||
private float glassVX;
|
||||
private float glassVY;
|
||||
private Random glassRand;
|
||||
private Control GlassControl;
|
||||
private ControlChromosome chromo;
|
||||
private ControlText text;
|
||||
private float analyseProgress;
|
||||
private boolean isAnalysing;
|
||||
private Map<IChromosomeType, String> info;
|
||||
private ItemStack prev;
|
||||
|
||||
public WindowFieldKit(final EntityPlayer player, final IInventory inventory, final Side side) {
|
||||
super(280.0f, 230.0f, player, inventory, side);
|
||||
this.glassOffsetX = 0.0f;
|
||||
this.glassOffsetY = 0.0f;
|
||||
this.glassVX = 0.0f;
|
||||
this.glassVY = 0.0f;
|
||||
this.glassRand = new Random();
|
||||
this.analyseProgress = 1.0f;
|
||||
this.isAnalysing = false;
|
||||
this.info = new HashMap<IChromosomeType, String>();
|
||||
this.prev = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractMod getMod() {
|
||||
return BinnieCore.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Field Kit";
|
||||
}
|
||||
|
||||
private void setupValidators() {
|
||||
this.getWindowInventory().setValidator(0, new SlotValidator(null) {
|
||||
@Override
|
||||
public boolean isValid(final ItemStack object) {
|
||||
return AlleleManager.alleleRegistry.isIndividual(object) || Binnie.Genetics.getConversion(object) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Individual";
|
||||
}
|
||||
});
|
||||
this.getWindowInventory().setValidator(1, new SlotValidator(null) {
|
||||
@Override
|
||||
public boolean isValid(final ItemStack object) {
|
||||
return object.getItem() == Items.paper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Paper";
|
||||
}
|
||||
});
|
||||
this.getWindowInventory().disableAutoDispense(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseClient() {
|
||||
this.setTitle("Field Kit");
|
||||
CraftGUI.Render.stylesheet(new StyleSheetPunnett());
|
||||
this.getWindowInventory().createSlot(0);
|
||||
this.getWindowInventory().createSlot(1);
|
||||
this.setupValidators();
|
||||
new ControlPlayerInventory(this);
|
||||
final 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")).setColour(2236962);
|
||||
(this.text = new ControlText(this, new IArea(0.0f, 120.0f, this.w(), 24.0f), "", TextJustification.MiddleCenter)).setColour(2236962);
|
||||
this.chromo = new ControlChromosome(this, 150.0f, 24.0f);
|
||||
this.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventValueChanged event) {
|
||||
final IChromosomeType type = (IChromosomeType) event.getValue();
|
||||
if (type != null && WindowFieldKit.this.info.containsKey(type)) {
|
||||
final String t = WindowFieldKit.this.info.get(type);
|
||||
WindowFieldKit.this.text.setValue(t);
|
||||
}
|
||||
else {
|
||||
WindowFieldKit.this.text.setValue("");
|
||||
}
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.DirectChild, this.chromo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseServer() {
|
||||
final ItemStack kit = this.getPlayer().getHeldItem();
|
||||
final int sheets = 64 - kit.getItemDamage();
|
||||
if (sheets != 0) {
|
||||
this.getWindowInventory().setInventorySlotContents(1, new ItemStack(Items.paper, sheets));
|
||||
}
|
||||
this.setupValidators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
super.onUpdateClient();
|
||||
if (this.isAnalysing) {
|
||||
this.analyseProgress += 0.01f;
|
||||
if (this.analyseProgress >= 1.0f) {
|
||||
this.isAnalysing = false;
|
||||
this.analyseProgress = 1.0f;
|
||||
final ItemStack stack = this.getWindowInventory().getStackInSlot(0);
|
||||
if (stack != null) {
|
||||
this.sendClientAction("analyse", new NBTTagCompound());
|
||||
}
|
||||
this.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 void refreshSpecies() {
|
||||
final ItemStack item = this.getWindowInventory().getStackInSlot(0);
|
||||
if (item == null || !AlleleManager.alleleRegistry.isIndividual(item)) {
|
||||
return;
|
||||
}
|
||||
final IIndividual ind = AlleleManager.alleleRegistry.getIndividual(item);
|
||||
if (ind == null) {
|
||||
return;
|
||||
}
|
||||
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(item);
|
||||
this.chromo.setRoot(root);
|
||||
final Random rand = new Random();
|
||||
this.info.clear();
|
||||
for (final IChromosomeType type : root.getKaryotype()) {
|
||||
if (!Binnie.Genetics.isInvalidChromosome(type)) {
|
||||
final IAllele allele = ind.getGenome().getActiveAllele(type);
|
||||
final List<String> infos = new ArrayList<String>();
|
||||
int i = 0;
|
||||
for (String pref = root.getUID() + ".fieldkit." + type.getName().toLowerCase() + "."; Binnie.Language.canLocalise(pref + i); ++i) {
|
||||
infos.add(Binnie.Language.localise(pref + i));
|
||||
}
|
||||
String text = Binnie.Genetics.getSystem(root).getAlleleName(type, allele);
|
||||
if (!infos.isEmpty()) {
|
||||
text = infos.get(rand.nextInt(infos.size()));
|
||||
}
|
||||
this.info.put(type, text);
|
||||
this.chromo.setRoot(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowInventoryChanged() {
|
||||
super.onWindowInventoryChanged();
|
||||
if (this.isServer()) {
|
||||
final ItemStack kit = this.getPlayer().getHeldItem();
|
||||
final int sheets = 64 - kit.getItemDamage();
|
||||
final int size = (this.getWindowInventory().getStackInSlot(1) == null) ? 0 : this.getWindowInventory().getStackInSlot(1).stackSize;
|
||||
if (sheets != size) {
|
||||
kit.setItemDamage(64 - size);
|
||||
}
|
||||
((EntityPlayerMP) this.getPlayer()).updateHeldItem();
|
||||
}
|
||||
if (this.isClient()) {
|
||||
final ItemStack item = this.getWindowInventory().getStackInSlot(0);
|
||||
this.prev = item;
|
||||
this.text.setValue("");
|
||||
if (item != null && !Analyser.isAnalysed(item)) {
|
||||
if (this.getWindowInventory().getStackInSlot(1) == null) {
|
||||
this.text.setValue("No Paper!");
|
||||
this.isAnalysing = false;
|
||||
this.analyseProgress = 1.0f;
|
||||
}
|
||||
else {
|
||||
this.startAnalysing();
|
||||
this.chromo.setRoot(null);
|
||||
if (this.damageKit()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item != null) {
|
||||
this.isAnalysing = false;
|
||||
this.analyseProgress = 1.0f;
|
||||
this.refreshSpecies();
|
||||
if (this.damageKit()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showHelpButton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
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";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveGuiNBT(final Side side, final EntityPlayer player, final String name, final NBTTagCompound action) {
|
||||
super.recieveGuiNBT(side, player, name, action);
|
||||
if (side == Side.SERVER && name.equals("analyse")) {
|
||||
this.getWindowInventory().setInventorySlotContents(0, Analyser.analyse(this.getWindowInventory().getStackInSlot(0)));
|
||||
this.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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.binniecore;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import binnie.craftgui.events.EventMouse;
|
||||
import binnie.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import binnie.craftgui.events.EventHandler;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import binnie.craftgui.events.EventValueChanged;
|
||||
import binnie.craftgui.controls.listbox.ControlTextOption;
|
||||
import binnie.genetics.gui.ControlGenesisOption;
|
||||
import binnie.craftgui.minecraft.MinecraftGUI;
|
||||
import binnie.craftgui.core.geometry.IArea;
|
||||
import binnie.Binnie;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import binnie.craftgui.minecraft.control.ControlTabIcon;
|
||||
import binnie.craftgui.controls.tab.ControlTab;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import binnie.craftgui.controls.tab.ControlTabBar;
|
||||
import binnie.craftgui.core.geometry.Position;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.minecraft.control.ControlPlayerInventory;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.AbstractMod;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import binnie.craftgui.window.Panel;
|
||||
import binnie.core.genetics.Gene;
|
||||
import binnie.craftgui.controls.listbox.ControlListBox;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import binnie.craftgui.minecraft.Window;
|
||||
|
||||
public class WindowGenesis extends Window
|
||||
{
|
||||
private ISpeciesRoot root;
|
||||
private IAllele[] template;
|
||||
private ControlListBox<Gene> geneList;
|
||||
private ControlListBox<Gene> geneOptions;
|
||||
private Panel panelPickup;
|
||||
|
||||
public WindowGenesis(final EntityPlayer player, final IInventory inventory, final Side side) {
|
||||
super(342.0f, 228.0f, player, inventory, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractMod getMod() {
|
||||
return BinnieCore.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Genesis";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseClient() {
|
||||
new ControlPlayerInventory(this);
|
||||
this.setTitle("Genesis");
|
||||
final ControlTabBar<BreedingSystem> tabSystems = new ControlTabBar<BreedingSystem>(this, 8.0f, 28.0f, 23.0f, 100.0f, Position.Left) {
|
||||
@Override
|
||||
public ControlTab<BreedingSystem> createTab(final float x, final float y, final float w, final float h, final BreedingSystem value) {
|
||||
return new ControlTabIcon<BreedingSystem>(this, x, y, w, h, value) {
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
final int type = this.value.getDefaultType();
|
||||
final IIndividual ind = this.value.getDefaultIndividual();
|
||||
return this.value.getSpeciesRoot().getMemberStack(ind, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutlineColour() {
|
||||
return this.value.getColour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOutline() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
tabSystems.setValues(Binnie.Genetics.getActiveSystems());
|
||||
this.root = Binnie.Genetics.getActiveSystems().iterator().next().getSpeciesRoot();
|
||||
this.template = this.root.getDefaultTemplate();
|
||||
final IArea one = new IArea(32.0f, 28.0f, 170.0f, 100.0f);
|
||||
final IArea two = new IArea(214.0f, 28.0f, 100.0f, 100.0f);
|
||||
new Panel(this, one.outset(1), MinecraftGUI.PanelType.Black);
|
||||
new Panel(this, two.outset(1), MinecraftGUI.PanelType.Black);
|
||||
this.geneList = new ControlListBox<Gene>(this, one.x(), one.y(), one.w(), one.h(), 10.0f) {
|
||||
@Override
|
||||
public IWidget createOption(final Gene value, final int y) {
|
||||
return new ControlGenesisOption(this.getContent(), value, y);
|
||||
}
|
||||
};
|
||||
this.geneOptions = new ControlListBox<Gene>(this, two.x(), two.y(), two.w(), two.h(), 10.0f) {
|
||||
@Override
|
||||
public IWidget createOption(final Gene value, final int y) {
|
||||
return new ControlTextOption<Gene>(this.getContent(), value, y);
|
||||
}
|
||||
};
|
||||
tabSystems.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventValueChanged event) {
|
||||
WindowGenesis.this.root = ((BreedingSystem) event.getValue()).getSpeciesRoot();
|
||||
WindowGenesis.this.template = WindowGenesis.this.root.getDefaultTemplate();
|
||||
WindowGenesis.this.refreshTemplate(null);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, tabSystems));
|
||||
this.geneList.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventValueChanged event) {
|
||||
final Map<IChromosomeType, List<IAllele>> map = Binnie.Genetics.getChromosomeMap(WindowGenesis.this.root);
|
||||
final List<Gene> opts = new ArrayList<Gene>();
|
||||
final IChromosomeType chromo = ((Gene) event.value) != null ? ((Gene) event.value).getChromosome() : null;
|
||||
if (chromo != null)// fix NPE
|
||||
for (final IAllele allele : map.get(chromo)) {
|
||||
opts.add(new Gene(allele, chromo, WindowGenesis.this.root));
|
||||
}
|
||||
WindowGenesis.this.geneOptions.setOptions(opts);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this.geneList));
|
||||
this.geneOptions.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventValueChanged event) {
|
||||
if (event.value == null) {
|
||||
return;
|
||||
}
|
||||
final IChromosomeType chromo = ((Gene) event.value).getChromosome();
|
||||
WindowGenesis.this.template[chromo.ordinal()] = ((Gene) event.value).getAllele();
|
||||
if (chromo == ((Gene) event.value).getSpeciesRoot().getKaryotypeKey()) {
|
||||
WindowGenesis.this.template = ((Gene) event.value).getSpeciesRoot().getTemplate(((Gene) event.value).getAllele().getUID());
|
||||
}
|
||||
WindowGenesis.this.refreshTemplate(chromo);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this.geneOptions));
|
||||
this.panelPickup = new Panel(this, 16.0f, 140.0f, 60.0f, 42.0f, MinecraftGUI.PanelType.Black);
|
||||
this.refreshTemplate(null);
|
||||
}
|
||||
|
||||
private void refreshTemplate(final IChromosomeType selection) {
|
||||
final List<Gene> genes = new ArrayList<Gene>();
|
||||
final IChromosomeType[] arr$;
|
||||
final IChromosomeType[] chromos = arr$ = Binnie.Genetics.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]);
|
||||
for (final IChromosomeType type : arr$) {
|
||||
final IAllele allele = this.template[type.ordinal()];
|
||||
if (allele == null) {
|
||||
throw new NullPointerException("Allele missing for Chromosome " + type.getName());
|
||||
}
|
||||
genes.add(new Gene(allele, type, this.root));
|
||||
}
|
||||
final Map<IChromosomeType, List<IAllele>> map = Binnie.Genetics.getChromosomeMap(this.root);
|
||||
this.geneList.setOptions(genes);
|
||||
if (selection != null) {
|
||||
this.geneList.setValue(new Gene(this.template[selection.ordinal()], selection, this.root));
|
||||
}
|
||||
else {
|
||||
this.geneOptions.setOptions(new ArrayList<Gene>());
|
||||
}
|
||||
this.refreshPickup();
|
||||
}
|
||||
|
||||
private void refreshPickup() {
|
||||
this.panelPickup.deleteAllChildren();
|
||||
int i = 0;
|
||||
for (final int type : Binnie.Genetics.getSystem(this.root).getActiveTypes()) {
|
||||
final IIndividual ind = this.root.templateAsIndividual(this.template);
|
||||
ind.analyze();
|
||||
final ItemStack stack = this.root.getMemberStack(ind, type);
|
||||
final ControlItemDisplay display = new ControlItemDisplay(this.panelPickup, 4 + i % 3 * 18, 4 + i / 3 * 18);
|
||||
display.setItemStack(stack);
|
||||
display.setTooltip();
|
||||
display.addEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventMouse.Down event) {
|
||||
final NBTTagCompound nbt = new NBTTagCompound();
|
||||
stack.writeToNBT(nbt);
|
||||
Window.get(event.getOrigin()).sendClientAction("genesis", nbt);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, display));
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveGuiNBT(final Side side, final EntityPlayer player, final String name, final NBTTagCompound action) {
|
||||
super.recieveGuiNBT(side, player, name, action);
|
||||
if (side == Side.SERVER && name.equals("genesis")) {
|
||||
final ItemStack stack = ItemStack.loadItemStackFromNBT(action);
|
||||
final InventoryPlayer playerInv = player.inventory;
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
if (playerInv.getItemStack() == null) {
|
||||
playerInv.setItemStack(stack);
|
||||
}
|
||||
else if (playerInv.getItemStack().isItemEqual(stack) && ItemStack.areItemStackTagsEqual(playerInv.getItemStack(), stack)) {
|
||||
final int fit = stack.getMaxStackSize() - (stack.stackSize + playerInv.getItemStack().stackSize);
|
||||
if (fit >= 0) {
|
||||
final ItemStack itemStack;
|
||||
final ItemStack rec = itemStack = stack;
|
||||
itemStack.stackSize += playerInv.getItemStack().stackSize;
|
||||
playerInv.setItemStack(rec);
|
||||
}
|
||||
}
|
||||
player.openContainer.detectAndSendChanges();
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).updateHeldItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user