Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Port flower mechanics from Industrial Apiary to Mega Apiary (#39)
Browse files Browse the repository at this point in the history
* BEES RENDERING

* FLOWER LINE

* Ha tfu

* Fix

* Remove machine spam

* Easier recipe

* Revert "Easier recipe"

This reverts commit ce50a35.

* Revert "Remove machine spam"

This reverts commit 5769a36.

* Revert GT_MetaTileEntity_MegaIndustrialApiary.java

* Port flower mechanics from Industrial Apiary

* spotlessApply (#41)

Co-authored-by: Jakub <53441451+kuba6000@users.noreply.github.com>
Co-authored-by: GitHub GTNH Actions <>

* Revert Flower Line

* Update structure

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
kuba6000 and github-actions[bot] authored Jan 2, 2023
1 parent d9e5195 commit 976ffdf
Showing 1 changed file with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import static kubatech.api.Variables.*;

import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import com.gtnewhorizons.modularui.api.ModularUITextures;
Expand Down Expand Up @@ -106,9 +108,9 @@ public class GT_MetaTileEntity_MegaIndustrialApiary
{" GGG "," GGG GGG "," G G "," G G "," G G "," G G ","G G","G G","G G"," G G "," G G "," G G "," G G "," GGG GGG "," GGG "},
{" AAA "," OLA ALO "," P P "," O O "," L L "," A A ","A A","A A","A A"," A A "," L L "," O O "," P P "," OLA ALO "," AAA "},
{" AAAAA "," NA AO "," P P "," N O "," A A ","A A","A III A","A III A","A III A","A A"," A A "," N N "," P P "," NA AN "," AAAAA "},
{" AAAAA "," NA AO "," P P "," N O "," A A ","A A","A JJJ A","A JKJ A","A JJJ A","A A"," A A "," N N "," P P "," NA AN "," AAAAA "},
{" AAA "," OLA ALO "," P P "," O O "," L L "," A A ","A KKK A","A KKK A","A KKK A"," A A "," L L "," O O "," P P "," OLA ALO "," AAA "},
{" G~G "," GGGBBBGGG "," GBB BBG "," GB BBG "," GB BG "," G G ","GB KKK BG","GB KJK BG","GB KKK BG"," G G "," GB BG "," GBB BBG "," GBB BBG "," GGGBBBGGG "," GGG "},
{" AAAAA "," NA FFF AO "," PFF FFP "," NF FFO "," AF FA ","A A","AF JJJ FA","AF JKJ FA","AF JJJ FA","A A"," AF FA "," NFF FFN "," PFF FFP "," NA FFF AN "," AAAAA "},
{" AAA "," OLAFFFALO "," PFFFFFFFFFP "," OFFFF FFFFO "," LFF FFL "," AFF FFFFF FA ","AFF FKKKFF FFA","AFF FFKKKFF FFA","AFF FFKKKF FFA"," AF FFFFF FA "," LFF FF FFL "," OFFFF FFFO "," PFFFFFFFFFP "," OLAFFFALO "," AAA "},
{" G~G "," GGGBBBGGG "," GBBFFFFFBBG "," GBFFF FFBBG "," GBF FBG "," GFF FFFFF FG ","GBF FKKKFF FBG","GBF FFKJKFF FBG","GBF FFKKKF FBG"," GF FFFFF FG "," GBF FF FBG "," GBBFF FBBG "," GBBFFFFFBBG "," GGGBBBGGG "," GGG "},
{" HHH "," HHBBBHH "," HHBBBBBBBHH "," HBBBWWWBBBH "," HBBWWWWWWWBBH "," HBBWBBBBBWWBH ","HBBWWBBBBBBWBBH","HBBWBBBBBBBWBBH","HBBWBBBBBBWWBBH"," HBWWBBBBBWWBH "," HBBWWWBBWWBBH "," HBBBWWWWBBH "," HHBBBBBBBHH "," HHBBBHH "," HHH "},
{" "," GGGGG "," GGGBBBBGG "," GBBBBBBBBBG "," GBBBBBBBBBG "," GBBBBBBBBBBBG "," GBBBBBBBBBBBG "," GBBBBBBBBBBBG "," GBBBBBBBBBBBG "," GBBBBBBBBBBBG "," GBBBBBBBBBG "," GBBBBBBBBBG "," GGBBBBBGG "," GGGGG "," "},
{" "," HHH "," HHBBBHH "," HBBBBBBBH "," HBBBBBBBBBH "," HBBBBBBBBBH "," HBBBBBBBBBBBH "," HBBBBBBBBBBBH "," HBBBBBBBBBBBH "," HBBBBBBBBBH "," HBBBBBBBBBH "," HBBBBBBBH "," HHBBBHH "," HHH "," "},
Expand All @@ -126,7 +128,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary
STRUCTURE_PIECE_MAIN_SURVIVAL,
Arrays.stream(struct)
.map(sa -> Arrays.stream(sa)
.map(s -> s.replaceAll("W", " "))
.map(s -> s.replaceAll("W", " ").replaceAll("F", " "))
.toArray(String[]::new))
.toArray(String[][]::new))
.addElement(
Expand Down Expand Up @@ -167,6 +169,26 @@ public class GT_MetaTileEntity_MegaIndustrialApiary
.addElement('O', ofBlock(PluginApiculture.blocks.alveary, BlockAlveary.Type.HEATER.ordinal()))
.addElement('P', ofBlock(PluginApiculture.blocks.alveary, BlockAlveary.Type.FAN.ordinal()))
.addElement('W', ofBlock(Blocks.water, 0))
.addElement('F', new IStructureElementNoPlacement<GT_MetaTileEntity_MegaIndustrialApiary>() {
@Override
public boolean check(
GT_MetaTileEntity_MegaIndustrialApiary mte, World world, int x, int y, int z) {
mte.flowerCheck(world, x, y, z);
return true;
}

@Override
public boolean spawnHint(
GT_MetaTileEntity_MegaIndustrialApiary mte,
World world,
int x,
int y,
int z,
ItemStack trigger) {
StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 2 - 1);
return true;
}
})
.build();

@SuppressWarnings("unused")
Expand All @@ -178,6 +200,16 @@ public GT_MetaTileEntity_MegaIndustrialApiary(String aName) {
super(aName);
}

private boolean isCacheDirty = true;
private final HashSet<String> flowersCache = new HashSet<>();
private final HashSet<String> flowersCheck = new HashSet<>();
private boolean flowersError = false;

private void flowerCheck(final World world, final int x, final int y, final int z) {
if (!flowersCheck.isEmpty() && !world.isAirBlock(x, y, z))
flowersCheck.removeIf(s -> FlowerManager.flowerRegistry.isAcceptedFlower(s, world, x, y, z));
}

@Override
public void construct(ItemStack stackSize, boolean hintsOnly) {
buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 7, 8, 0);
Expand All @@ -188,7 +220,8 @@ public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBu
int built = survivialBuildPiece(STRUCTURE_PIECE_MAIN_SURVIVAL, stackSize, 7, 8, 0, elementBudget, env, true);
if (built == -1) {
GT_Utility.sendChatToPlayer(
env.getActor(), EnumChatFormatting.GREEN + "Auto placing done ! Now go place the water yourself !");
env.getActor(),
EnumChatFormatting.GREEN + "Auto placing done ! Now go place the water and flowers yourself !");
return 0;
}
return built;
Expand Down Expand Up @@ -252,6 +285,7 @@ protected GT_Multiblock_Tooltip_Builder createTooltip() {
.addCasingInfo("Bronze Plated Bricks", 190)
.addOtherStructurePart("Borosilicate Glass", "Look at the hologram")
.addStructureInfo("The glass tier limits the Energy Input tier")
.addOtherStructurePart("Flowers", "On dirt/grass", 2)
.addInputBus("Any casing", 1)
.addOutputBus("Any casing", 1)
.addEnergyHatch("Any casing", 1)
Expand Down Expand Up @@ -279,6 +313,10 @@ public void loadNBTData(NBTTagCompound aNBT) {
mSecondaryMode = aNBT.getInteger("mSecondaryMode");
for (int i = 0, isize = aNBT.getInteger("mStorageSize"); i < isize; i++)
mStorage.add(new BeeSimulator(aNBT.getCompoundTag("mStorage." + i)));
flowersCache.clear();
mStorage.forEach(s -> flowersCache.add(s.flowerType));
flowersCache.remove("");
isCacheDirty = false;
}

@Override
Expand Down Expand Up @@ -372,14 +410,18 @@ public boolean checkRecipe(ItemStack aStack) {
for (ItemStack input : inputs) {
if (beeRoot.getType(input) == EnumBeeType.QUEEN) {
BeeSimulator bs = new BeeSimulator(input, w);
if (bs.isValid) mStorage.add(bs);
if (bs.isValid) {
mStorage.add(bs);
isCacheDirty = true;
}
}
}
updateSlots();
} else if (mPrimaryMode == 1 && mStorage.size() > 0) {
for (int i = 0, imax = Math.min(10, mStorage.size()); i < imax; i++) {
addOutput(mStorage.get(0).queenStack);
mStorage.remove(0);
isCacheDirty = true;
}
} else return false;
mMaxProgresstime = 10;
Expand All @@ -390,10 +432,7 @@ public boolean checkRecipe(ItemStack aStack) {
} else if (mPrimaryMode == 2) {
if (mMaxSlots > 0 && !mStorage.isEmpty()) {
if (mSecondaryMode == 0) {
this.mEUt = -((int) GT_Values.V[6] * mStorage.size());
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
this.mMaxProgresstime = 100;
if (flowersError) return false;

int maxConsume = Math.min(mStorage.size(), mMaxSlots) * 40;
int toConsume = maxConsume;
Expand All @@ -417,6 +456,11 @@ public boolean checkRecipe(ItemStack aStack) {
BeeSimulator beeSimulator = mStorage.get(i);
stacks.addAll(beeSimulator.getDrops(64_00d * boosted));
}

this.mEUt = -((int) GT_Values.V[6] * mStorage.size());
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
this.mMaxProgresstime = 100;
this.mOutputItems = stacks.toArray(new ItemStack[0]);
return true;
} else {
Expand Down Expand Up @@ -473,11 +517,19 @@ public String[] getInfoData() {
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
mGlassTier = 0;
mCasing = 0;
if (isCacheDirty) {
flowersCache.clear();
mStorage.forEach(s -> flowersCache.add(s.flowerType));
flowersCache.remove("");
isCacheDirty = false;
}
flowersCheck.addAll(flowersCache);
if (!checkPiece(STRUCTURE_PIECE_MAIN, 7, 8, 0)) return false;
if (this.mGlassTier < 10 && !this.mEnergyHatches.isEmpty())
for (GT_MetaTileEntity_Hatch_Energy hatchEnergy : this.mEnergyHatches)
if (this.mGlassTier < hatchEnergy.mTier) return false;
boolean valid = this.mMaintenanceHatches.size() == 1 && this.mEnergyHatches.size() >= 1 && this.mCasing >= 190;
flowersError = valid && !this.flowersCheck.isEmpty();
if (valid) updateMaxSlots();
return valid;
}
Expand Down Expand Up @@ -621,6 +673,7 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
}
BeeSimulator removed = mStorage.remove(ID);
addOutput(removed.queenStack);
isCacheDirty = true;
GT_Utility.sendChatToPlayer(player, "Queen ejected !");
})
.setBackground(() -> new IDrawable[] {
Expand Down Expand Up @@ -791,6 +844,7 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
.setSynced(false)
.widget(new TextWidget("Status: ").setDefaultColor(COLOR_TEXT_GRAY.get()))
.widget(new DynamicTextWidget(() -> {
if (flowersError) return new Text("No flowers !").color(Color.RED.dark(3));
if (getBaseMetaTileEntity().isActive()) return new Text("Working !").color(Color.GREEN.dark(3));
else if (getBaseMetaTileEntity().isAllowedToWork())
return new Text("Enabled").color(Color.GREEN.dark(3));
Expand Down Expand Up @@ -847,6 +901,7 @@ private static class BeeSimulator {
float beeSpeed;

float maxBeeCycles;
String flowerType;

public BeeSimulator(ItemStack queenStack, World world) {
isValid = false;
Expand All @@ -859,6 +914,7 @@ public BeeSimulator(ItemStack queenStack, World world) {
int h = queen.getMaxHealth();
maxBeeCycles = (float) h / (1.f / mod);
IBeeGenome genome = queen.getGenome();
this.flowerType = genome.getFlowerProvider().getFlowerType();
// isInfinite = queen.isNatural();
// if (!isInfinite && h < 4) return;
IAlleleBeeSpecies primary = genome.getPrimary();
Expand Down Expand Up @@ -890,6 +946,12 @@ public BeeSimulator(NBTTagCompound tag) {
specialDrops.add(new BeeDrop(tag.getCompoundTag("specialDrops" + i)));
beeSpeed = tag.getFloat("beeSpeed");
maxBeeCycles = tag.getFloat("maxBeeCycles");
if (tag.hasKey("flowerType")) flowerType = tag.getString("flowerType");
else {
IBee queen = beeRoot.getMember(this.queenStack);
IBeeGenome genome = queen.getGenome();
this.flowerType = genome.getFlowerProvider().getFlowerType();
}
}

public NBTTagCompound toNBTTagCompound() {
Expand All @@ -906,6 +968,7 @@ public NBTTagCompound toNBTTagCompound() {
tag.setTag("specialDrops" + i, specialDrops.get(i).toNBTTagCompound());
tag.setFloat("beeSpeed", beeSpeed);
tag.setFloat("maxBeeCycles", maxBeeCycles);
tag.setString("flowerType", flowerType);
return tag;
}

Expand Down

0 comments on commit 976ffdf

Please sign in to comment.