aboutsummaryrefslogtreecommitdiff
path: root/src/Java/binnie/extrabees/apiary/machine/AlvearyFrame.java
blob: a910e101f9ddfc4a80838e1b17d9d28577c6315a (plain)
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
package binnie.extrabees.apiary.machine;

import binnie.Binnie;
import binnie.core.genetics.ManagerGenetics;
import binnie.core.machines.IMachine;
import binnie.core.machines.Machine;
import binnie.core.machines.inventory.ComponentInventorySlots;
import binnie.core.machines.inventory.InventorySlot;
import binnie.core.machines.inventory.SlotValidator;
import binnie.craftgui.minecraft.IMachineInformation;
import binnie.extrabees.apiary.ComponentBeeModifier;
import binnie.extrabees.apiary.ComponentExtraBeeGUI;
import binnie.extrabees.apiary.TileExtraBeeAlveary;
import binnie.extrabees.core.ExtraBeeGUID;
import binnie.extrabees.core.ExtraBeeTexture;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeListener;
import forestry.api.apiculture.IBeeModifier;
import forestry.api.apiculture.IBeeRoot;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.api.apiculture.IHiveFrame;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class AlvearyFrame
{
  public static int slotFrame = 0;
  
  public static class PackageAlvearyFrame
    extends AlvearyMachine.AlvearyPackage
    implements IMachineInformation
  {
    public PackageAlvearyFrame()
    {
      super(ExtraBeeTexture.AlvearyFrame.getTexture(), false);
    }
    
    public void createMachine(Machine machine)
    {
      new ComponentExtraBeeGUI(machine, ExtraBeeGUID.AlvearyFrame);
      
      ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
      
      inventory.addSlot(AlvearyFrame.slotFrame, "frame");
      inventory.getSlot(AlvearyFrame.slotFrame).setValidator(new AlvearyFrame.SlotValidatorFrame());
      
      new AlvearyFrame.ComponentFrameModifier(machine);
    }
  }
  
  public static class SlotValidatorFrame
    extends SlotValidator
  {
    public SlotValidatorFrame()
    {
      super();
    }
    
    public boolean isValid(ItemStack itemStack)
    {
      return (itemStack != null) && ((itemStack.getItem() instanceof IHiveFrame));
    }
    
    public String getTooltip()
    {
      return "Hive Frames";
    }
  }
  
  public static class ComponentFrameModifier
    extends ComponentBeeModifier
    implements IBeeModifier, IBeeListener
  {
    public ComponentFrameModifier(Machine machine)
    {
      super();
    }
    
    public void wearOutEquipment(int amount)
    {
      if (getHiveFrame() == null) {
        return;
      }
      World world = getMachine().getTileEntity().getWorldObj();
      int wear = Math.round(amount * 5 * Binnie.Genetics.getBeeRoot().getBeekeepingMode(world).getWearModifier());
      getInventory().setInventorySlotContents(AlvearyFrame.slotFrame, getHiveFrame().frameUsed((IBeeHousing)((TileExtraBeeAlveary)getMachine().getTileEntity()).getCentralTE(), getInventory().getStackInSlot(AlvearyFrame.slotFrame), null, wear));
    }
    
    public IHiveFrame getHiveFrame()
    {
      if (getInventory().getStackInSlot(AlvearyFrame.slotFrame) != null) {
        return (IHiveFrame)getInventory().getStackInSlot(AlvearyFrame.slotFrame).getItem();
      }
      return null;
    }
    
    public float getTerritoryModifier(IBeeGenome genome, float currentModifier)
    {
      return getHiveFrame() == null ? 1.0F : getHiveFrame().getTerritoryModifier(genome, currentModifier);
    }
    
    public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier)
    {
      return getHiveFrame() == null ? 1.0F : getHiveFrame().getMutationModifier(genome, mate, currentModifier);
    }
    
    public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier)
    {
      return getHiveFrame() == null ? 1.0F : getHiveFrame().getLifespanModifier(genome, mate, currentModifier);
    }
    
    public float getProductionModifier(IBeeGenome genome, float currentModifier)
    {
      return getHiveFrame() == null ? 1.0F : getHiveFrame().getProductionModifier(genome, currentModifier);
    }
    
    public float getFloweringModifier(IBeeGenome genome, float currentModifier)
    {
      return getHiveFrame() == null ? 1.0F : getHiveFrame().getFloweringModifier(genome, currentModifier);
    }
  }
}