diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2023-01-09 17:50:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 17:50:36 +0100 |
commit | 867280556692363d6ec183ac9838ab3c7769cf1c (patch) | |
tree | a60568770f7491a175d21c76a34809747c4a19f8 /src/main/java/kubatech/tileentity/gregtech/multiblock | |
parent | 9bdc955dd4d5f8c2b51dfcc44277bfb7a5b4c96e (diff) | |
download | GT5-Unofficial-867280556692363d6ec183ac9838ab3c7769cf1c.tar.gz GT5-Unofficial-867280556692363d6ec183ac9838ab3c7769cf1c.tar.bz2 GT5-Unofficial-867280556692363d6ec183ac9838ab3c7769cf1c.zip |
Fix voltage variable in comb chance calculation in Mega Apiary + some tweaks (#43)
* Always use full potential power
* Fix voltage variable (t) in comb chance calculation
* Fix already existing apiaries
Diffstat (limited to 'src/main/java/kubatech/tileentity/gregtech/multiblock')
-rw-r--r-- | src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java | 89 |
1 files changed, 72 insertions, 17 deletions
diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java index 2840c3b466..79d1338a06 100644 --- a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java +++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_MegaIndustrialApiary.java @@ -100,6 +100,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary private static final String STRUCTURE_PIECE_MAIN = "main"; private static final String STRUCTURE_PIECE_MAIN_SURVIVAL = "mainsurvival"; private static final int CONFIGURATION_WINDOW_ID = 999; + private static final int MEGA_APIARY_STORAGE_VERSION = 1; private static final String[][] struct = transpose(new String[][] { // spotless:off {" "," "," "," HHH "," HHAAAHH "," HAPLPAH "," HAPAAAPAH "," HALAAALAH "," HAPAAAPAH "," HAPLPAH "," HHAAAHH "," HHH "," "," "," "}, @@ -204,6 +205,8 @@ public class GT_MetaTileEntity_MegaIndustrialApiary private final HashSet<String> flowersCache = new HashSet<>(); private final HashSet<String> flowersCheck = new HashSet<>(); private boolean flowersError = false; + private boolean needsTVarUpdate = false; + private int megaApiaryStorageVersion = 0; private void flowerCheck(final World world, final int x, final int y, final int z) { if (!flowersCheck.isEmpty() && !world.isAirBlock(x, y, z)) @@ -303,6 +306,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary aNBT.setInteger("mStorageSize", mStorage.size()); for (int i = 0; i < mStorage.size(); i++) aNBT.setTag("mStorage." + i, mStorage.get(i).toNBTTagCompound()); + aNBT.setInteger("MEGA_APIARY_STORAGE_VERSION", MEGA_APIARY_STORAGE_VERSION); } @Override @@ -313,6 +317,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary mSecondaryMode = aNBT.getInteger("mSecondaryMode"); for (int i = 0, isize = aNBT.getInteger("mStorageSize"); i < isize; i++) mStorage.add(new BeeSimulator(aNBT.getCompoundTag("mStorage." + i))); + megaApiaryStorageVersion = aNBT.getInteger("MEGA_APIARY_STORAGE_VERSION"); flowersCache.clear(); mStorage.forEach(s -> flowersCache.add(s.flowerType)); flowersCache.remove(""); @@ -363,10 +368,14 @@ public class GT_MetaTileEntity_MegaIndustrialApiary } private void updateMaxSlots() { + int mOld = mMaxSlots; long v = GTHelper.getMaxInputEU(this); if (v < GT_Values.V[6]) mMaxSlots = 0; else if (mSecondaryMode == 0) mMaxSlots = (int) (v / GT_Values.V[6]); else mMaxSlots = 1; + if (mOld != 0 && mOld != mMaxSlots) { + needsTVarUpdate = true; + } } private CustomTileEntityPacket packet = null; @@ -406,15 +415,17 @@ public class GT_MetaTileEntity_MegaIndustrialApiary if (mPrimaryMode < 2) { if (mPrimaryMode == 0 && mStorage.size() < mMaxSlots) { World w = getBaseMetaTileEntity().getWorld(); + float t = (float) GTHelper.getVoltageTierD(this); ArrayList<ItemStack> inputs = getStoredInputs(); for (ItemStack input : inputs) { if (beeRoot.getType(input) == EnumBeeType.QUEEN) { - BeeSimulator bs = new BeeSimulator(input, w); + BeeSimulator bs = new BeeSimulator(input, w, t); if (bs.isValid) { mStorage.add(bs); isCacheDirty = true; } } + if (mStorage.size() >= mMaxSlots) break; } updateSlots(); } else if (mPrimaryMode == 1 && mStorage.size() > 0) { @@ -432,8 +443,23 @@ public class GT_MetaTileEntity_MegaIndustrialApiary } else if (mPrimaryMode == 2) { if (mMaxSlots > 0 && !mStorage.isEmpty()) { if (mSecondaryMode == 0) { + if (megaApiaryStorageVersion != MEGA_APIARY_STORAGE_VERSION) { + megaApiaryStorageVersion = MEGA_APIARY_STORAGE_VERSION; + World w = getBaseMetaTileEntity().getWorld(); + float t = (float) GTHelper.getVoltageTierD(this); + mStorage.forEach(s -> s.generate(w, t)); + } + + if (mStorage.size() > mMaxSlots) return false; + if (flowersError) return false; + if (needsTVarUpdate) { + float t = (float) GTHelper.getVoltageTierD(this); + needsTVarUpdate = false; + mStorage.forEach(s -> s.updateTVar(t)); + } + int maxConsume = Math.min(mStorage.size(), mMaxSlots) * 40; int toConsume = maxConsume; ArrayList<ItemStack> inputs = getStoredInputs(); @@ -457,7 +483,7 @@ public class GT_MetaTileEntity_MegaIndustrialApiary stacks.addAll(beeSimulator.getDrops(64_00d * boosted)); } - this.mEUt = -((int) GT_Values.V[6] * mStorage.size()); + this.mEUt = -(int) ((double) GT_Values.V[6] * (double) mMaxSlots * 0.99d); this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; this.mMaxProgresstime = 100; @@ -899,9 +925,17 @@ public class GT_MetaTileEntity_MegaIndustrialApiary float maxBeeCycles; String flowerType; - public BeeSimulator(ItemStack queenStack, World world) { + public BeeSimulator(ItemStack queenStack, World world, float t) { isValid = false; this.queenStack = queenStack.copy(); + generate(world, t); + isValid = true; + queenStack.stackSize--; + } + + public void generate(World world, float t) { + drops.clear(); + specialDrops.clear(); if (beeRoot.getType(this.queenStack) != EnumBeeType.QUEEN) return; IBee queen = beeRoot.getMember(this.queenStack); IBeekeepingMode mode = beeRoot.getBeekeepingMode(world); @@ -911,29 +945,23 @@ public class GT_MetaTileEntity_MegaIndustrialApiary 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(); drops = new ArrayList<>(); specialDrops = new ArrayList<>(); beeSpeed = genome.getSpeed() * beeModifier.getProductionModifier(null, 1.f); genome.getPrimary() .getProductChances() - .forEach((key, value) -> drops.add(new BeeDrop(key, value, beeSpeed))); + .forEach((key, value) -> drops.add(new BeeDrop(key, value, beeSpeed, t))); genome.getSecondary() .getProductChances() - .forEach((key, value) -> drops.add(new BeeDrop(key, value / 2.f, beeSpeed))); - primary.getSpecialtyChances().forEach((key, value) -> specialDrops.add(new BeeDrop(key, value, beeSpeed))); - - isValid = true; - queenStack.stackSize--; + .forEach((key, value) -> drops.add(new BeeDrop(key, value / 2.f, beeSpeed, t))); + primary.getSpecialtyChances() + .forEach((key, value) -> specialDrops.add(new BeeDrop(key, value, beeSpeed, t))); } public BeeSimulator(NBTTagCompound tag) { queenStack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("queenStack")); isValid = tag.getBoolean("isValid"); - // isBreadingMode = tag.getBoolean("isBreadingMode"); - // isInfinite = tag.getBoolean("isInfinite"); drops = new ArrayList<>(); specialDrops = new ArrayList<>(); for (int i = 0, isize = tag.getInteger("dropssize"); i < isize; i++) @@ -954,8 +982,6 @@ public class GT_MetaTileEntity_MegaIndustrialApiary NBTTagCompound tag = new NBTTagCompound(); tag.setTag("queenStack", queenStack.writeToNBT(new NBTTagCompound())); tag.setBoolean("isValid", isValid); - // tag.setBoolean("isBreadingMode", isBreadingMode); - // tag.setBoolean("isInfinite", isInfinite); tag.setInteger("dropssize", drops.size()); for (int i = 0; i < drops.size(); i++) tag.setTag("drops" + i, drops.get(i).toNBTTagCompound()); @@ -992,15 +1018,38 @@ public class GT_MetaTileEntity_MegaIndustrialApiary return beeRoot.getMemberStack(princess, EnumBeeType.PRINCESS.ordinal()); } + public void updateTVar(float t) { + drops.forEach(d -> d.updateTVar(t)); + specialDrops.forEach(d -> d.updateTVar(t)); + } + private static class BeeDrop { ItemStack stack; double amount; GT_Utility.ItemId id; - public BeeDrop(ItemStack stack, float chance, float beeSpeed) { + float chance; + float beeSpeed; + float t; + + public BeeDrop(ItemStack stack, float chance, float beeSpeed, float t) { this.stack = stack; - this.amount = Bee.getFinalChance(chance, beeSpeed, 2.f, 8.f); + this.chance = chance; + this.beeSpeed = beeSpeed; + this.t = t; id = GT_Utility.ItemId.createNoCopy(stack); + evaluate(); + } + + public void updateTVar(float t) { + if (this.t != t) { + this.t = t; + evaluate(); + } + } + + public void evaluate() { + this.amount = Bee.getFinalChance(chance, beeSpeed, 2.f, t); } public double getAmount(double speedModifier) { @@ -1015,6 +1064,9 @@ public class GT_MetaTileEntity_MegaIndustrialApiary public BeeDrop(NBTTagCompound tag) { stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("stack")); + chance = tag.getFloat("chance"); + beeSpeed = tag.getFloat("beeSpeed"); + t = tag.getFloat("t"); amount = tag.getDouble("amount"); id = GT_Utility.ItemId.createNoCopy(stack); } @@ -1022,6 +1074,9 @@ public class GT_MetaTileEntity_MegaIndustrialApiary public NBTTagCompound toNBTTagCompound() { NBTTagCompound tag = new NBTTagCompound(); tag.setTag("stack", stack.writeToNBT(new NBTTagCompound())); + tag.setFloat("chance", chance); + tag.setFloat("beeSpeed", beeSpeed); + tag.setFloat("t", t); tag.setDouble("amount", amount); return tag; } |