diff options
| author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-07-27 04:39:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-27 09:39:06 +0700 |
| commit | b3c3b9c5d7d0f40404f702b849d46f348cd78a9c (patch) | |
| tree | 76fa9babd038565663f70f02395bbb3151e37a5a /src/main/java/gregtech/common | |
| parent | 8c2089b5e3d1591d4c3904494414ea26815079e8 (diff) | |
| download | GT5-Unofficial-b3c3b9c5d7d0f40404f702b849d46f348cd78a9c.tar.gz GT5-Unofficial-b3c3b9c5d7d0f40404f702b849d46f348cd78a9c.tar.bz2 GT5-Unofficial-b3c3b9c5d7d0f40404f702b849d46f348cd78a9c.zip | |
Move Industrial Apiary to gregtech (#1107)
* Industrial Apiary
* Make Forestry not required.
* Add support for gendustry upgrades and lower energy demand
* Add item validation to input slots and fix battery + special slots
* Automation upgrade support and bug fixes
* Better canWork check and flower detection
* GUI work
* Better detection of modifier update
* Add button to cancel process
* Add textures
* Tooltip changes
* Add convert crafting
* Make top and sides glow
* Bug fix
* New textures
* Add bee effects
* Make all tooltips translatable
* Implement GT Apiary Upgrades
* Prevent inserting too many upgrades
* Just require gendustry instead of checking it everywhere
* Add blacklist (bug fix) and use hashsets instead of arrays
* Cache beemember to do effects
* Make blacklist automatic
* Add acceleration upgrades for all tiers (LV -> UV)
* Lock the machine to maxspeed by default
* Correct required energy in info tooltip
* Use isUpgrade method instead of manually checking
* Lower amperage to 4
* Save locked speed to nbt
Diffstat (limited to 'src/main/java/gregtech/common')
4 files changed, 1386 insertions, 1 deletions
diff --git a/src/main/java/gregtech/common/gui/GT_Container_IndustrialApiary.java b/src/main/java/gregtech/common/gui/GT_Container_IndustrialApiary.java new file mode 100644 index 0000000000..45d455ff03 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_Container_IndustrialApiary.java @@ -0,0 +1,292 @@ +package gregtech.common.gui; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.ForestryAPI; +import forestry.api.core.IErrorState; +import gregtech.api.gui.GT_ContainerMetaTile_Machine; +import gregtech.api.gui.GT_Slot_Holo; +import gregtech.api.gui.GT_Slot_Output; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_ApiaryUpgrade; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_IndustrialApiary; +import net.bdew.gendustry.api.items.IApiaryUpgrade; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; + +import java.util.ArrayList; + +public class GT_Container_IndustrialApiary extends GT_ContainerMetaTile_Machine { + + GT_Slot_Holo slotItemTransferToggle; + GT_Slot_Holo slotSpeedToggle; + GT_Slot_Holo slotPollenToggle; + GT_Slot_Holo slotCancelProcess; + Slot slotBattery; + Slot slotSpecial; + + boolean mItemTransfer; + boolean mStuttering; + + int mSpeed = 0; // scale 0 - 8 + boolean mLockedSpeed = true; + boolean retrievePollen; + + ArrayList<String> mErrorStates = new ArrayList<>(50); + + public GT_Container_IndustrialApiary(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(aInventoryPlayer, aTileEntity); + } + + @Override + public void addSlots(InventoryPlayer aInventoryPlayer) { + addSlotToContainer(slotItemTransferToggle = new GT_Slot_Holo(mTileEntity, 0, 8, 63, false, true, 1)); + addSlotToContainer(slotSpeedToggle = new GT_Slot_Holo(mTileEntity, 0, 26, 63, false, true, 1)); + addSlotToContainer(slotPollenToggle = new GT_Slot_Holo(mTileEntity, 0, 8, 45, false, true, 1)); + addSlotToContainer(slotCancelProcess = new GT_Slot_Holo(mTileEntity, 0, 8, 27, false, true, 1)); + int tStartIndex = 5; + + addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 37, 22)); + addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 37, 42)); + + addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 62, 24)); + addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 80, 24)); + addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 62, 42)); + addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 80, 42)); + + for(int i = 107; i <= 143; i += 18) + for(int j = 6; j <= 42; j += 18) + addSlotToContainer(new GT_Slot_Output(this.mTileEntity, tStartIndex++, i, j)); + + addSlotToContainer(slotBattery = new Slot(mTileEntity, 1, 80, 63)); + addSlotToContainer(slotSpecial = new Slot(mTileEntity, 3, 125, 63)); + + } + + @Override + public ItemStack slotClick(int aSlotNumber, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (mTileEntity.getMetaTileEntity() == null) return null; + GT_MetaTileEntity_IndustrialApiary machine = getMachine(); + if (machine == null) return null; + switch (aSlotNumber) { + case 0: + machine.mItemTransfer = !machine.mItemTransfer; + return null; + case 1: + if(aMouseclick == 0) { + if(machine.mLockedSpeed) + return null; + if(aShifthold == 0) { + machine.mSpeed++; + if (machine.mSpeed > machine.getMaxSpeed()) machine.mSpeed = 0; + } + else if(aShifthold == 1) + { + machine.mSpeed--; + if (machine.mSpeed < 0) machine.mSpeed = machine.getMaxSpeed(); + } + } + else if(aMouseclick == 1) + { + machine.mLockedSpeed = !machine.mLockedSpeed; + if(machine.mLockedSpeed) + machine.mSpeed = machine.getMaxSpeed(); + } + return null; + case 2: + machine.retreviePollen = !machine.retreviePollen; + return null; + case 3: + machine.cancelProcess(); + detectAndSendChanges(); + return null; + } + + if(!(aSlotNumber >= getSlotStartIndex()+2 && aSlotNumber < getSlotStartIndex()+2+4)) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + if(aShifthold == 5) + return null; + if(aShifthold != 0) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + if(aMouseclick > 1) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + ItemStack s = aPlayer.inventory.getItemStack(); + if(s == null) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + Slot slot = getSlot(aSlotNumber); + ItemStack slotstack = slot.getStack(); + if(slotstack != null && !GT_Utility.areStacksEqual(slotstack, s)) + return null; // super would replace item + if(slotstack == null && !slot.isItemValid(s)) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + if(!(s.getItem() instanceof IApiaryUpgrade) && !GT_ApiaryUpgrade.isUpgrade(s)) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + int max = 1; + if (s.getItem() instanceof IApiaryUpgrade) + max = ((IApiaryUpgrade) s.getItem()).getMaxNumber(s); + else + max = GT_ApiaryUpgrade.getUpgrade(s).getMaxNumber(); + if(slotstack != null) + max = Math.max(0, max - slotstack.stackSize); + max = Math.min(max, s.stackSize); + if(max == 0) + return null; + if(aMouseclick == 1) + max = 1; + if(max == s.stackSize) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + ItemStack newstack = s.splitStack(s.stackSize - max); + ItemStack result = super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + aPlayer.inventory.setItemStack(newstack); + return result; + } + + @Override + public int getSlotStartIndex() { + return 4; + } + + @Override + public int getSlotCount() { + return 6+9+2; + } + + @Override + public int getShiftClickSlotCount() { + return 6; + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { + return; + } + + this.mSpeed = getMachine().mSpeed; + this.mItemTransfer = getMachine().mItemTransfer; + this.mStuttering = getMachine().mStuttering; + this.retrievePollen = getMachine().retreviePollen; + this.mLockedSpeed = getMachine().mLockedSpeed; + + for (Object crafter : this.crafters) { + ICrafting var1 = (ICrafting) crafter; + var1.sendProgressBarUpdate(this, 100, this.mSpeed); + var1.sendProgressBarUpdate(this, 101, this.mItemTransfer ? 1 : 0); + var1.sendProgressBarUpdate(this, 102, 0); + for(IErrorState s : getMachine().mErrorStates) + var1.sendProgressBarUpdate(this, 103, s.getID()); + var1.sendProgressBarUpdate(this, 104, this.mStuttering ? 1 : 0); + var1.sendProgressBarUpdate(this, 105, this.retrievePollen ? 1 : 0); + var1.sendProgressBarUpdate(this, 106, this.mLockedSpeed ? 1 : 0); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void updateProgressBar(int par1, int par2) { + super.updateProgressBar(par1, par2); + switch (par1) { + case 100: + this.mSpeed = par2; + break; + case 101: + this.mItemTransfer = par2 == 1; + break; + case 102: + this.mErrorStates.clear(); + break; + case 103: + this.mErrorStates.add(EnumChatFormatting.RED + StatCollector.translateToLocal("for." + ForestryAPI.errorStateRegistry.getErrorState((short) par2).getDescription())); + break; + case 104: + this.mStuttering = par2 == 1; + break; + case 105: + this.retrievePollen = par2 == 1; + break; + case 106: + this.mLockedSpeed = par2 == 1; + break; + } + } + + public GT_MetaTileEntity_IndustrialApiary getMachine() { + return (GT_MetaTileEntity_IndustrialApiary) mTileEntity.getMetaTileEntity(); + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer aPlayer, int aSlotIndex) { + Slot s = getSlot(aSlotIndex); + if(s == null) + return super.transferStackInSlot(aPlayer, aSlotIndex); + if(!(s.inventory instanceof InventoryPlayer)) + return super.transferStackInSlot(aPlayer, aSlotIndex); + ItemStack aStack = s.getStack(); + if(aStack == null) + return super.transferStackInSlot(aPlayer, aSlotIndex); + if(!(aStack.getItem() instanceof IApiaryUpgrade) && !GT_ApiaryUpgrade.isUpgrade(aStack)) + return super.transferStackInSlot(aPlayer, aSlotIndex); + for(int i = getSlotStartIndex()+2; i < getSlotStartIndex()+2+4; i++) { + Slot iSlot = getSlot(i); + ItemStack iStack = iSlot.getStack(); + if(iStack == null) + { + if(!iSlot.isItemValid(aStack)) + continue; + } + else + { + if(!GT_Utility.areStacksEqual(aStack, iStack)) + continue; + } + int max = 1; + if (aStack.getItem() instanceof IApiaryUpgrade) + max = ((IApiaryUpgrade) aStack.getItem()).getMaxNumber(aStack); + else + max = GT_ApiaryUpgrade.getUpgrade(aStack).getMaxNumber(); + if (iStack == null) { + max = Math.min(max, aStack.stackSize); + ItemStack newstack = aStack.splitStack(max); + iSlot.putStack(newstack); + } else { + max = Math.max(0, max - iStack.stackSize); + max = Math.min(max, aStack.stackSize); + iStack.stackSize += max; + aStack.stackSize -= max; + iSlot.onSlotChanged(); + } + if (aStack.stackSize == 0) + s.putStack(null); + else + s.onSlotChanged(); + break; + } + return null; + } + + private static class ApiarySlot extends Slot{ + + public ApiarySlot(IInventory p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) { + super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); + } + + @Override + public boolean isItemValid(ItemStack p_75214_1_) { + return this.inventory.isItemValidForSlot(this.getSlotIndex(), p_75214_1_); + } + + @Override + public void onSlotChanged() { + super.onSlotChanged(); + ((GT_MetaTileEntity_IndustrialApiary)((IGregTechTileEntity)this.inventory).getMetaTileEntity()).onInventoryUpdate(this.getSlotIndex()); + } + } +} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_IndustrialApiary.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_IndustrialApiary.java new file mode 100644 index 0000000000..f901a78599 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_GUIContainer_IndustrialApiary.java @@ -0,0 +1,152 @@ +package gregtech.common.gui; + +import forestry.api.apiculture.*; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; +import gregtech.api.gui.widgets.GT_GuiSlotTooltip; +import gregtech.api.gui.widgets.GT_GuiTooltip; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_TooltipDataCache; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_IndustrialApiary; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.StatCollector; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Arrays; + +public class GT_GUIContainer_IndustrialApiary extends GT_GUIContainerMetaTile_Machine { + + + private static final String + BATTERY_SLOT_TOOLTIP = "GT5U.machines.battery_slot.tooltip", + UNUSED_SLOT_TOOLTIP = "GT5U.machines.unused_slot.tooltip", + STALLED_STUTTERING_TOOLTIP = "GT5U.machines.stalled_stuttering.tooltip", + ITEM_TRANSFER_TOOLTIP = "GT5U.machines.item_transfer.tooltip", + POWER_SOURCE_POWER = "GT5U.machines.powersource.power", + RETRIEVE_POLLEN_TOOLTIP = "GT5U.machines.industrialapiary.pollen.tooltip", + CANCEL_PROCESS_TOOLTIP = "GT5U.machines.industrialapiary.cancel.tooltip", + SPEED_TOOLTIP = "GT5U.machines.industrialapiary.speed.tooltip", + SPEED_LOCKED_TOOLTIP = "GT5U.machines.industrialapiary.speedlocked.tooltip", + INFO_TOOLTIP = "GT5U.machines.industrialapiary.info.tooltip", + INFO_WITH_BEE_TOOLTIP = "GT5U.machines.industrialapiary.infoextended.tooltip" + ; + + + GT_GuiTooltip mErrorStatesTooltip; + GT_GuiTooltip mSpeedToggleTooltip; + GT_GuiTooltip mInfoTooltip; + + public GT_GUIContainer_IndustrialApiary(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(new GT_Container_IndustrialApiary(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/basicmachines/IndustrialApiary.png"); + } + + @Override + protected void setupTooltips() { + Rectangle tBeeProblemArea = new Rectangle(this.guiLeft + 100, this.guiTop + 63, 18, 18); + addToolTip(mErrorStatesTooltip = new GT_GuiTooltip(tBeeProblemArea, "") { + @Override + protected void onTick() { + boolean e = this.enabled; + super.onTick(); + this.enabled = e; + } + }); + addToolTip(mSpeedToggleTooltip = new GT_GuiSlotTooltip(getContainer().slotSpeedToggle, new GT_TooltipDataCache.TooltipData(null, null))); + mErrorStatesTooltip.enabled = false; + addToolTip(mInfoTooltip = new GT_GuiTooltip(new Rectangle(this.guiLeft + 163, guiTop + 5, 6, 17))); + + addToolTip(new GT_GuiSlotTooltip(getContainer().slotPollenToggle, mTooltipCache.getData(RETRIEVE_POLLEN_TOOLTIP))); + addToolTip(new GT_GuiSlotTooltip(getContainer().slotCancelProcess, mTooltipCache.getData(CANCEL_PROCESS_TOOLTIP))); + + + addToolTip(new GT_GuiSlotTooltip(getContainer().slotItemTransferToggle, mTooltipCache.getData(ITEM_TRANSFER_TOOLTIP))); + addToolTip(new GT_GuiSlotTooltip(getContainer().slotBattery, mTooltipCache.getData(BATTERY_SLOT_TOOLTIP, + powerTierName(getContainer().getMachine().mTier), + powerTierName((byte)(getContainer().getMachine().mTier + 1))))); + addToolTip(new GT_GuiSlotTooltip(getContainer().slotSpecial, mTooltipCache.getData(UNUSED_SLOT_TOOLTIP))); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float parTicks) { + mErrorStatesTooltip.enabled = !getContainer().mErrorStates.isEmpty(); + if(mErrorStatesTooltip.enabled){ mErrorStatesTooltip.setToolTipText(new GT_TooltipDataCache.TooltipData(getContainer().mErrorStates, getContainer().mErrorStates)); } + else if(getContainer().mStuttering) + { + mErrorStatesTooltip.enabled = true; + mErrorStatesTooltip.setToolTipText(mTooltipCache.getData(STALLED_STUTTERING_TOOLTIP, StatCollector.translateToLocal(POWER_SOURCE_POWER))); + } + int accelerated = (1 << getContainer().mSpeed); + int energyusage = 0; + if(accelerated == 2) + energyusage = 32; + else if(accelerated > 2) + energyusage = 32 * accelerated << (getContainer().mSpeed - 2); + mSpeedToggleTooltip.setToolTipText(mTooltipCache.getUncachedTooltipData(getContainer().mLockedSpeed ? SPEED_LOCKED_TOOLTIP : SPEED_TOOLTIP, accelerated, GT_Utility.formatNumbers(energyusage))); + ArrayList<String> s = new ArrayList<>(); + GT_MetaTileEntity_IndustrialApiary IA = getContainer().getMachine(); + + String energyreq = GT_Utility.formatNumbers((int)((float)GT_MetaTileEntity_IndustrialApiary.baseEUtUsage * IA.getEnergyModifier() * accelerated) + energyusage); + String Temp = StatCollector.translateToLocal(IA.getTemperature().getName()); + String Hum = StatCollector.translateToLocal(IA.getHumidity().getName()); + boolean moreinformationgiven = false; + if(IA.getUsedQueen() != null && BeeManager.beeRoot.isMember(IA.getUsedQueen(), EnumBeeType.QUEEN.ordinal())) { + IBee bee = BeeManager.beeRoot.getMember(IA.getUsedQueen()); + if (bee.isAnalyzed()) { + moreinformationgiven = true; + IBeeGenome genome = bee.getGenome(); + IBeeModifier mod = BeeManager.beeRoot.getBeekeepingMode(IA.getWorld()).getBeeModifier(); + float tmod = IA.getTerritoryModifier(null, 1f) * mod.getTerritoryModifier(null, 1f); + int[] t = Arrays.stream(genome.getTerritory()).map(i -> (int) ((float) i * tmod)).toArray(); + mInfoTooltip.setToolTipText(mTooltipCache.getUncachedTooltipData(INFO_WITH_BEE_TOOLTIP, energyreq, Temp, Hum, + Math.round(100f * IA.getProductionModifier(null, 1f) * genome.getSpeed() * mod.getProductionModifier(null, 1f)), + Math.round(IA.getFloweringModifier(null, 1f) * genome.getFlowering() * mod.getFloweringModifier(null, 1f)), + Math.round(IA.getLifespanModifier(null, null, 1f) * genome.getLifespan() * mod.getLifespanModifier(null, null, 1f)), + t[0], t[1], t[2])); + } + } + if(!moreinformationgiven) + mInfoTooltip.setToolTipText(mTooltipCache.getUncachedTooltipData(INFO_TOOLTIP, energyreq, Temp, Hum)); + + + super.drawScreen(mouseX, mouseY, parTicks); + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + this.fontRendererObj.drawString("Ind. Apiary", 8, 4, 4210752); + this.fontRendererObj.drawString("x", 30, 63, 4210752); + this.fontRendererObj.drawString((1 << getContainer().mSpeed) + "", 26, 72, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + super.drawGuiContainerBackgroundLayer(par1, par2, par3); + int x = (this.width - this.xSize) / 2; + int y = (this.height - this.ySize) / 2; + drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + if (this.mContainer != null) { + if (getContainer().mItemTransfer) + drawTexturedModalRect(x + 7, y + 62, 176, 18, 18, 18); + if(getContainer().retrievePollen) + drawTexturedModalRect(x + 7, y + 44, 194, 18, 18, 18); + if(getContainer().mMaxProgressTime > 0) { + double p = (double) getContainer().mProgressTime / getContainer().mMaxProgressTime; + drawTexturedModalRect(x+70, y+3, 176, 0, (int)(p*20), 18); + } + if(mErrorStatesTooltip.enabled) + drawTexturedModalRect(x+100, y+63, 176, 36, getContainer().mStuttering ? 18 : 9, 18); + } + } + + private GT_Container_IndustrialApiary getContainer(){ + return ((GT_Container_IndustrialApiary) this.mContainer); + } + + // taken from GT_GUIContainer_BasicMachine + private String powerTierName(byte machineTier) { + return GT_Values.TIER_COLORS[machineTier] + GT_Values.VN[machineTier]; + } + +} diff --git a/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_03.java b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_03.java index 1252fdb2f0..3e35ff6a21 100644 --- a/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_03.java +++ b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_03.java @@ -330,7 +330,26 @@ public class GT_MetaGenerated_Item_03 ItemList.GalliumArsenideCrystalSmallPart.set(addItem(tLastID = 191, "Small Gallium Arsenide Crystal", "For making boules", o)); ItemList.KevlarFiber.set(addItem(tLastID = 192, "Kevlar Fiber", "For make Kevlar Plates", o)); ItemList.WovenKevlar.set(addItem(tLastID = 193, "Woven Kevlar", "For make Kevlar Plates", o)); - ItemList.Spinneret.set(addItem(tLastID = 194, "Spinneret", "For make Kevlar Fiber", o)); + ItemList.Spinneret.set(addItem(tLastID = 194, "Spinneret", "For make Kevlar Fiber", o)); + + ItemList.IndustrialApiary_Upgrade_Acceleration_1.set(addItem(tLastID = 200, "Acceleration Upgrade x2", "Acceleration upgrade for Industrial Apiary/n Unlocks 2x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_2.set(addItem(tLastID = 201, "Acceleration Upgrade x4", "Acceleration upgrade for Industrial Apiary/n Unlocks 4x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_3.set(addItem(tLastID = 202, "Acceleration Upgrade x8", "Acceleration upgrade for Industrial Apiary/n Unlocks 8x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_4.set(addItem(tLastID = 203, "Acceleration Upgrade x16", "Acceleration upgrade for Industrial Apiary/n Unlocks 16x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_5.set(addItem(tLastID = 204, "Acceleration Upgrade x32", "Acceleration upgrade for Industrial Apiary/n Unlocks 32x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_6.set(addItem(tLastID = 205, "Acceleration Upgrade x64", "Acceleration upgrade for Industrial Apiary/n Unlocks 64x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_7.set(addItem(tLastID = 206, "Acceleration Upgrade x128", "Acceleration upgrade for Industrial Apiary/n Unlocks 128x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + ItemList.IndustrialApiary_Upgrade_Acceleration_8.set(addItem(tLastID = 207, "Acceleration Upgrade x256", "Acceleration upgrade for Industrial Apiary/n Unlocks 256x acceleration level/n Will also grant 8x production upgrade", OrePrefixes.apiaryUpgrade.name())); + + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_1.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_2.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_3.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_4.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_5.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_6.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_7.get(1L)); + OrePrefixes.apiaryUpgrade.add(ItemList.IndustrialApiary_Upgrade_Acceleration_8.get(1L)); + } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java new file mode 100644 index 0000000000..f442b6812c --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java @@ -0,0 +1,922 @@ +package gregtech.common.tileentities.machines.basic; + +import com.google.common.collect.ImmutableSet; +import com.mojang.authlib.GameProfile; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.apiculture.*; +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.core.*; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IEffectData; +import forestry.api.genetics.IIndividual; +import forestry.core.errors.EnumErrorCode; +import forestry.plugins.PluginApiculture; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_ApiaryUpgrade; +import gregtech.api.util.GT_Utility; +import gregtech.common.GT_Client; +import gregtech.common.gui.GT_Container_IndustrialApiary; +import gregtech.common.gui.GT_GUIContainer_IndustrialApiary; +import net.bdew.gendustry.api.ApiaryModifiers; +import net.bdew.gendustry.api.items.IApiaryUpgrade; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.*; + +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; + +public class GT_MetaTileEntity_IndustrialApiary extends GT_MetaTileEntity_BasicMachine implements IBeeHousing, IBeeHousingInventory, IErrorLogic, IBeeModifier, IBeeListener { + + public static final int baseEUtUsage = 37; + static final int queen = 5; + static final int drone = 6; + + + IBeeRoot beeRoot = (IBeeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); + + public int mSpeed = 0; + public boolean mLockedSpeed = true; + public boolean retreviePollen = false; + + private ItemStack usedQueen = null; + private IBee usedQueenBee = null; + private IEffectData[] effectData = new IEffectData[2]; + + public GT_MetaTileEntity_IndustrialApiary(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 4, new String[] { "BEES GOES BRRRR", EnumChatFormatting.GRAY + "Added by " + EnumChatFormatting.GOLD + "kuba6000" }, 6, 9, "IndustrialApiary.png", "", + TextureFactory.of( + TextureFactory.of(OVERLAY_SIDE_INDUSTRIAL_APIARY_ACTIVE), + TextureFactory.builder().addIcon(OVERLAY_SIDE_INDUSTRIAL_APIARY_ACTIVE_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_SIDE_INDUSTRIAL_APIARY), + TextureFactory.builder().addIcon(OVERLAY_SIDE_INDUSTRIAL_APIARY_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_FRONT_INDUSTRIAL_APIARY_ACTIVE), + TextureFactory.builder().addIcon(OVERLAY_FRONT_INDUSTRIAL_APIARY_ACTIVE_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_FRONT_INDUSTRIAL_APIARY), + TextureFactory.builder().addIcon(OVERLAY_FRONT_INDUSTRIAL_APIARY_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_TOP_INDUSTRIAL_APIARY_ACTIVE), + TextureFactory.builder().addIcon(OVERLAY_TOP_INDUSTRIAL_APIARY_ACTIVE_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_TOP_INDUSTRIAL_APIARY), + TextureFactory.builder().addIcon(OVERLAY_TOP_INDUSTRIAL_APIARY_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_BOTTOM_INDUSTRIAL_APIARY_ACTIVE), + TextureFactory.builder().addIcon(OVERLAY_BOTTOM_INDUSTRIAL_APIARY_ACTIVE_GLOW).glow().build()), + TextureFactory.of( + TextureFactory.of(OVERLAY_BOTTOM_INDUSTRIAL_APIARY), + TextureFactory.builder().addIcon(OVERLAY_BOTTOM_INDUSTRIAL_APIARY_GLOW).glow().build())); + } + + public GT_MetaTileEntity_IndustrialApiary(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 4, aDescription, aTextures, 6, 9, aGUIName, aNEIName); + } + + public GT_MetaTileEntity_IndustrialApiary(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 4, aDescription, aTextures, 6, 9, aGUIName, aNEIName); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_IndustrialApiary(this.mName, this.mTier, this.mDescriptionArray, this.mTextures, this.mGUIName, this.mNEIName); + } + + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_IndustrialApiary(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_IndustrialApiary(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mSpeed", mSpeed); + aNBT.setBoolean("mLockedSpeed", mLockedSpeed); + aNBT.setBoolean("retrievePolen", retreviePollen); + if(usedQueen != null) + aNBT.setTag("usedQueen", usedQueen.writeToNBT(new NBTTagCompound())); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mSpeed = aNBT.getInteger("mSpeed"); + mLockedSpeed = aNBT.getBoolean("mLockedSpeed"); + retreviePollen = aNBT.getBoolean("retrievePolen"); + if(aNBT.hasKey("usedQueen")) + usedQueen = ItemStack.loadItemStackFromNBT(aNBT.getCompoundTag("usedQueen")); + } + + @Override + public int checkRecipe() { + updateModifiers(); + if(canWork()) { + + ItemStack queen = getQueen(); + usedQueen = queen.copy(); + if(beeRoot.getType(queen) == EnumBeeType.QUEEN) + { + IBee bee = beeRoot.getMember(queen); + usedQueenBee = bee; + + // LIFE CYCLES + + float mod = this.getLifespanModifier(null, null, 1.f); + IBeekeepingMode mode = beeRoot.getBeekeepingMode(this.getWorld()); + IBeeModifier beemodifier = mode.getBeeModifier(); + mod *= beemodifier.getLifespanModifier(null, null, 1.f); + int h = bee.getHealth(); + mod = 1.f / mod; + float cycles = h/mod; + + + // PRODUCTS + + HashMap<GT_Utility.ItemId, ItemStack> pollen = new HashMap<>(); + + if(retreviePollen) { + int icycles = (int)cycles + (getWorld().rand.nextFloat() < (cycles - (float)((int)cycles)) ? 1 : 0); + for(int z = 0; z < icycles; z++) { + IIndividual p = bee.retrievePollen(this); + if(p != null) + { + ItemStack s = p.getGenome().getSpeciesRoot().getMemberStack(p, EnumGermlingType.POLLEN.ordinal()); + if(s != null) { + GT_Utility.ItemId id = GT_Utility.ItemId.createNoCopy(s); + pollen.computeIfAbsent(id, k -> { ItemStack ns = s.copy(); ns.stackSize = 0; return ns; }); + pollen.get(id).stackSize += s.stackSize; + } + } + } + } + + IBeeGenome genome = bee.getGenome(); + IAlleleBeeSpecies primary = genome.getPrimary(); + IAlleleBeeSpecies secondary = genome.getSecondary(); + + float speed = genome.getSpeed() * getProductionModifier(null, 1f) * beemodifier.getProductionModifier(null, 1.f); + + HashMap<GT_Utility.ItemId, Float> drops = new HashMap<>(); + HashMap<GT_Utility.ItemId, ItemStack> dropstacks = new HashMap<>(); + + for(Map.Entry<ItemStack, Float> entry : primary.getProductChances().entrySet()) { + GT_Utility.ItemId id = GT_Utility.ItemId.createNoCopy(entry.getKey()); + drops.merge(id, Math.min(1f, entry.getValue() * speed) * (float) entry.getKey().stackSize * cycles, Float::sum); + dropstacks.computeIfAbsent(id, k -> entry.getKey()); + } + for(Map.Entry<ItemStack, Float> entry : secondary.getProductChances().entrySet()) { + GT_Utility.ItemId id = GT_Utility.ItemId.createNoCopy(entry.getKey()); + drops.merge(id, Math.min(1f, (float) Math.round(entry.getValue() / 2.0F) * speed) * (float) entry.getKey().stackSize * cycles, Float::sum); + dropstacks.computeIfAbsent(id, k -> entry.getKey()); + } + if(primary.isJubilant(genome, this) && secondary.isJubilant(genome, this)) + for(Map.Entry<ItemStack, Float> entry : primary.getSpecialtyChances().entrySet()) { + GT_Utility.ItemId id = GT_Utility.ItemId.createNoCopy(entry.getKey()); + drops.merge(id, Math.min(1f, entry.getValue() * speed) * (float) entry.getKey().stackSize * cycles, Float::sum); + dropstacks.computeIfAbsent(id, k -> entry.getKey()); + } + + int i = 0; + for(Map.Entry<GT_Utility.ItemId, Float> entry : drops.entrySet()) + { + ItemStack s = dropstacks.get(entry.getKey()).copy(); + s.stackSize = entry.getValue().intValue() + (getWorld().rand.nextFloat() < (entry.getValue() - (float) entry.getValue().intValue()) ? 1 : 0); + if(s.stackSize > 0) + this.mOutputItems[i++] = s; + } + + IApiaristTracker breedingTracker = beeRoot.getBreedingTracker(getWorld(), getOwner()); + + if(!bee.canSpawn()) { + ItemStack convert = new ItemStack(PluginApiculture.items.beePrincessGE); + NBTTagCompound nbttagcompound = new NBTTagCompound(); + queen.writeToNBT(nbttagcompound); + convert.setTagCompound(nbttagcompound); + this.mOutputItems[7] = convert; + } + else { + IBee b = bee.spawnPrincess(this); + if(b != null){ + ItemStack princess = beeRoot.getMemberStack(b, EnumBeeType.PRINCESS.ordinal()); + breedingTracker.registerPrincess(b); + this.mOutputItems[7] = princess; + } + IBee[] d = bee.spawnDrones(this); + if(d != null && d.length > 0) { + ItemStack drone = beeRoot.getMemberStack(d[0], EnumBeeType.DRONE.ordinal()); + drone.stackSize = d.length; + breedingTracker.registerDrone(d[0]); + this.mOutputItems[8] = drone; + } + } + + setQueen(null); + + for(ItemStack s : pollen.values()) + if(i < 7) + this.mOutputItems[i++] = s; + else + break; + + + + + + // Overclock + + + this.mMaxProgresstime = (int)(cycles * 550.f); + int timemaxdivider = this.mMaxProgresstime / 100; + int useddivider = 1 << this.mSpeed; + int ac |
