Skip to content

Commit e4e672f

Browse files
committed
[Part2] Industrial Apiary more fix
1 parent 6ffc50d commit e4e672f

File tree

9 files changed

+141
-68
lines changed

9 files changed

+141
-68
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v1.4.3
2+
- Fix external automation inserting non-bee items into bee slots
3+
- Fix drone not returning to bee slot when Automation Upgrade is inserted while stopped
4+
- Fix upgrade changes not applied immediately when apiary is stopped
5+
- Fix bee tooltip not showing flower names for crop flowers
6+
- Fix BeekeepingLogic state (breeding progress, pending offspring) lost on world reload
7+
8+
* * *
9+
110
# v1.4.2
211
- Add Mixins to skip Forestry fluid registration and redirect to GregTech fluids.
312
- Align Industrial Apiary logic with Gendustry spec

dependencies.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ dependencies {
6060

6161
// Debug Forestry
6262
implementation rfg.deobf("curse.maven:forestry-59751:5903382") // Forestry 5.8.2.387
63-
implementation rfg.deobf("curse.maven:beebetteratbees-244516:2627215") // BeeBetterAtBees 2.0.3
64-
implementation rfg.deobf("curse.maven:jei-bees-248370:2490058") // JEIBees 0.9.0.5
63+
runtimeOnly rfg.deobf("curse.maven:jei-bees-248370:2490058") // JEIBees 0.9.0.5
6564

6665
// Debug Gendustry
6766
compileOnly rfg.deobf("curse.maven:bdlib-70496:2518031") // BdLib 1.14.3.12
6867
compileOnly rfg.deobf("curse.maven:gendustry-70492:2516215") // Gendustry 1.6.5.8
69-
compileOnly rfg.deobf("curse.maven:gendustry-jei-addon-301364:2609434") // Gendustry JEI Addon 1.0.2
7068
if (project.debug_all.toBoolean() || project.debug_gendustry.toBoolean()) {
7169
runtimeOnly rfg.deobf("curse.maven:bdlib-70496:2518031") // BdLib 1.14.3.12
7270
runtimeOnly rfg.deobf("curse.maven:gendustry-70492:2516215") // Gendustry 1.6.5.8

src/main/java/com/github/gtexpert/gtbm/integration/forestry/util/BeeProductHelper.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,34 @@
88
import forestry.api.apiculture.IBeeRoot;
99

1010
/**
11-
* Reusable product distribution logic for bee housings.
12-
* Handles automated bee re-insertion and output slot management.
11+
* Product distribution logic for bee housings backed by GT item handlers.
1312
*/
1413
public class BeeProductHelper {
1514

1615
/**
17-
* Add a bee product to the housing's inventory.
18-
* If automated, attempts to re-insert bees into queen/drone slots first.
16+
* Distributes a bee product into the housing's inventory.
1917
*
20-
* @param product the product to add
21-
* @param beeRoot the bee root (nullable, skips automation if null)
22-
* @param autoBreeding whether auto-breeding is enabled (princess auto-insertion)
23-
* @param isAutomated whether automation upgrade is active (drone auto-insertion)
24-
* @param beeInv the bee housing inventory (queen/drone access)
25-
* @param importItems the import item handler (for drone merging)
26-
* @param exportItems the export item handler (output slots)
27-
* @return true if the product was fully inserted
18+
* <p>
19+
* When the Automation Upgrade is active, bee members are re-inserted
20+
* into bee slots (princess → queen, drone → drone / merge).
21+
* Everything else goes to the export (output) slots.
2822
*/
2923
public static boolean addProduct(ItemStack product, IBeeRoot beeRoot,
30-
boolean autoBreeding, boolean isAutomated,
24+
boolean isAutomated,
3125
IBeeHousingInventory beeInv,
3226
IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems) {
3327
if (product.isEmpty()) return true;
3428

3529
ItemStack remaining = product.copy();
3630

37-
if (beeRoot != null && beeRoot.isMember(remaining)) {
38-
if (autoBreeding && (beeRoot.isMember(remaining, EnumBeeType.PRINCESS) ||
39-
beeRoot.isMember(remaining, EnumBeeType.QUEEN))) {
31+
if (isAutomated && beeRoot != null && beeRoot.isMember(remaining)) {
32+
if (beeRoot.isMember(remaining, EnumBeeType.PRINCESS)) {
4033
if (beeInv.getQueen().isEmpty()) {
4134
beeInv.setQueen(remaining);
4235
return true;
4336
}
4437
}
45-
if (isAutomated && beeRoot.isMember(remaining, EnumBeeType.DRONE)) {
38+
if (beeRoot.isMember(remaining, EnumBeeType.DRONE)) {
4639
if (beeInv.getDrone().isEmpty()) {
4740
beeInv.setDrone(remaining);
4841
return true;

src/main/java/com/github/gtexpert/gtbm/integration/gendustry/metatileentities/IndustrialApiaryLogic.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class IndustrialApiaryLogic extends RecipeLogicEnergy {
4040

4141
private IBeeRoot beeRoot;
4242
private IBeekeepingLogic beekeepingLogic;
43+
private NBTTagCompound pendingBeeLogicNBT;
4344
private boolean needsMovePrincess;
4445
/**
4546
* Set when {@link #beekeepingLogic} is first created on the server.
@@ -120,6 +121,10 @@ private void initBeekeepingLogic() {
120121
IBeeRoot root = getBeeRoot();
121122
if (root != null) {
122123
beekeepingLogic = root.createBeekeepingLogic(getApiary());
124+
if (pendingBeeLogicNBT != null) {
125+
beekeepingLogic.readFromNBT(pendingBeeLogicNBT);
126+
pendingBeeLogicNBT = null;
127+
}
123128
if (!metaTileEntity.getWorld().isRemote) {
124129
needsInitialSync = true;
125130
}
@@ -217,6 +222,8 @@ private void updateClient() {
217222
* draws energy, and syncs bee state to clients when needed.
218223
*/
219224
private void updateServer() {
225+
updateModifiers();
226+
220227
if (beekeepingLogic == null) {
221228
if (isActive) setActive(false);
222229
return;
@@ -225,8 +232,6 @@ private void updateServer() {
225232
MetaTileEntityIndustrialApiary apiary = getApiary();
226233
needsMovePrincess = false;
227234

228-
updateModifiers();
229-
230235
int euPerTick = getEUPerTick();
231236
boolean hasPower = getEnergyStored() >= euPerTick;
232237

@@ -254,6 +259,9 @@ private void updateServer() {
254259
if (needsMovePrincess && apiary.getQueen().isEmpty()) {
255260
movePrincessToQueenSlot();
256261
}
262+
if (apiary.getModifiers().isAutomated) {
263+
moveBeesFromOutput(apiary);
264+
}
257265

258266
// Sync AFTER canWork() so BeekeepingLogic.queenStack has genome data.
259267
// needsInitialSync covers chunk-reload where isActive == isWorking (both true)
@@ -378,6 +386,27 @@ public void movePrincessToQueenSlot() {
378386
}
379387
}
380388

389+
/**
390+
* Scans the output inventory for bee members and moves them into
391+
* the appropriate bee slots when the Automation Upgrade is active.
392+
*/
393+
private void moveBeesFromOutput(MetaTileEntityIndustrialApiary apiary) {
394+
IBeeRoot root = getBeeRoot();
395+
if (root == null) return;
396+
var output = getOutputInventory();
397+
for (int i = 0; i < output.getSlots(); i++) {
398+
ItemStack stack = output.getStackInSlot(i);
399+
if (stack.isEmpty() || !root.isMember(stack)) continue;
400+
if (root.isMember(stack, EnumBeeType.PRINCESS) && apiary.getQueen().isEmpty()) {
401+
apiary.setQueen(stack.copy());
402+
output.setStackInSlot(i, ItemStack.EMPTY);
403+
} else if (root.isMember(stack, EnumBeeType.DRONE) && apiary.getDrone().isEmpty()) {
404+
apiary.setDrone(stack.copy());
405+
output.setStackInSlot(i, ItemStack.EMPTY);
406+
}
407+
}
408+
}
409+
381410
// ---- Recipe overrides (unused — bee work replaces GT recipe system) ----
382411

383412
@Override
@@ -416,10 +445,8 @@ public NBTTagCompound serializeNBT() {
416445
public void deserializeNBT(@NotNull NBTTagCompound compound) {
417446
super.deserializeNBT(compound);
418447
if (compound.hasKey("BeekeepingLogic")) {
448+
pendingBeeLogicNBT = compound.getCompoundTag("BeekeepingLogic");
419449
initBeekeepingLogic();
420-
if (beekeepingLogic != null) {
421-
beekeepingLogic.readFromNBT(compound.getCompoundTag("BeekeepingLogic"));
422-
}
423450
}
424451
}
425452
}

src/main/java/com/github/gtexpert/gtbm/integration/gendustry/metatileentities/MetaTileEntityIndustrialApiary.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.gtexpert.gtbm.integration.gendustry.metatileentities;
22

3+
import java.io.IOException;
34
import java.util.Collections;
45
import java.util.function.Function;
56

@@ -10,6 +11,7 @@
1011
import net.minecraft.entity.player.EntityPlayer;
1112
import net.minecraft.item.ItemStack;
1213
import net.minecraft.nbt.NBTTagCompound;
14+
import net.minecraft.network.PacketBuffer;
1315
import net.minecraft.util.EnumFacing;
1416
import net.minecraft.util.NonNullList;
1517
import net.minecraft.util.ResourceLocation;
@@ -19,6 +21,8 @@
1921
import net.minecraft.world.biome.Biome;
2022
import net.minecraftforge.items.IItemHandlerModifiable;
2123

24+
import org.jetbrains.annotations.NotNull;
25+
2226
import com.mojang.authlib.GameProfile;
2327

2428
import gregtech.api.GTValues;
@@ -33,6 +37,7 @@
3337
import gregtech.client.renderer.ICubeRenderer;
3438

3539
import com.github.gtexpert.gtbm.api.gui.GTBMGuiTextures;
40+
import com.github.gtexpert.gtbm.api.util.ModLog;
3641
import com.github.gtexpert.gtbm.common.metatileentities.GTBMSimpleMachineMetaTileEntity;
3742
import com.github.gtexpert.gtbm.integration.forestry.util.BeeProductHelper;
3843
import com.github.gtexpert.gtbm.integration.gendustry.util.ApiaryModifierBridge;
@@ -44,6 +49,7 @@
4449
import forestry.api.genetics.IIndividual;
4550
import forestry.core.errors.ErrorLogic;
4651
import forestry.core.owner.OwnerHandler;
52+
import io.netty.buffer.Unpooled;
4753

4854
public class MetaTileEntityIndustrialApiary extends GTBMSimpleMachineMetaTileEntity
4955
implements IBeeHousing, IBeeHousingInventory {
@@ -84,7 +90,7 @@ public boolean onPollenRetrieved(IIndividual pollen) {
8490
};
8591
private final OwnerHandler ownerHandler = new OwnerHandler();
8692
private IItemHandlerModifiable upgradeInventory;
87-
private boolean autoBreeding = false;
93+
private boolean autoBreeding;
8894
private byte[] pendingBeeLogicData;
8995

9096
public MetaTileEntityIndustrialApiary(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap,
@@ -111,7 +117,7 @@ protected IItemHandlerModifiable createImportItemHandler() {
111117
return new NotifiableItemStackHandler(this, 2, this, false) {
112118

113119
@Override
114-
public boolean isItemValid(int slot, @org.jetbrains.annotations.NotNull ItemStack stack) {
120+
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
115121
IBeeRoot beeRoot = getLogic().getBeeRoot();
116122
if (beeRoot == null) return true;
117123
if (slot == 0) {
@@ -122,6 +128,13 @@ public boolean isItemValid(int slot, @org.jetbrains.annotations.NotNull ItemStac
122128
}
123129
return false;
124130
}
131+
132+
@Override
133+
@NotNull
134+
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
135+
if (!isItemValid(slot, stack)) return stack;
136+
return super.insertItem(slot, stack, simulate);
137+
}
125138
};
126139
}
127140

@@ -140,7 +153,7 @@ protected void initializeInventory() {
140153
this.upgradeInventory = new NotifiableItemStackHandler(this, getUpgradeSlotCount(), this, false) {
141154

142155
@Override
143-
public boolean isItemValid(int slot, @org.jetbrains.annotations.NotNull ItemStack stack) {
156+
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
144157
if (stack.isEmpty() || !(stack.getItem() instanceof IApiaryUpgrade)) return false;
145158
return getMaxAdditionalUpgrades(stack) >= stack.getCount();
146159
}
@@ -187,9 +200,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {
187200
}
188201
}
189202
data.setTag("UpgradeInventory", upgradeTag);
190-
191203
ownerHandler.writeToNBT(data);
192-
193204
data.setBoolean("AutoBreeding", autoBreeding);
194205
return data;
195206
}
@@ -206,7 +217,6 @@ public void readFromNBT(NBTTagCompound data) {
206217
}
207218
}
208219
}
209-
// Migrate legacy "Owner" tag to Forestry's "owner" format
210220
if (data.hasKey("Owner") && !data.hasKey("owner")) {
211221
NBTTagCompound legacyTag = data.getCompoundTag("Owner");
212222
NBTTagCompound converted = new NBTTagCompound();
@@ -395,10 +405,10 @@ public void setDrone(ItemStack stack) {
395405
@Override
396406
public boolean addProduct(ItemStack product, boolean all) {
397407
return BeeProductHelper.addProduct(product, getLogic().getBeeRoot(),
398-
autoBreeding, modifiers.isAutomated, this, importItems, exportItems);
408+
modifiers.isAutomated, this, importItems, exportItems);
399409
}
400410

401-
// ---- Bee FX sync ----
411+
// ---- Bee logic sync ----
402412

403413
public void syncBeeLogicToClient() {
404414
IBeekeepingLogic logic = getBeekeepingLogic();
@@ -408,7 +418,7 @@ public void syncBeeLogicToClient() {
408418
}
409419

410420
@Override
411-
public void writeInitialSyncData(@org.jetbrains.annotations.NotNull net.minecraft.network.PacketBuffer buf) {
421+
public void writeInitialSyncData(@NotNull PacketBuffer buf) {
412422
super.writeInitialSyncData(buf);
413423
IBeekeepingLogic logic = getBeekeepingLogic();
414424
if (logic != null) {
@@ -420,55 +430,48 @@ public void writeInitialSyncData(@org.jetbrains.annotations.NotNull net.minecraf
420430
}
421431

422432
@Override
423-
public void receiveInitialSyncData(@org.jetbrains.annotations.NotNull net.minecraft.network.PacketBuffer buf) {
433+
public void receiveInitialSyncData(@NotNull PacketBuffer buf) {
424434
super.receiveInitialSyncData(buf);
425435
if (buf.readBoolean()) {
426436
readBeeLogicData(buf);
427437
}
428438
}
429439

430440
@Override
431-
public void receiveCustomData(int dataId,
432-
@org.jetbrains.annotations.NotNull net.minecraft.network.PacketBuffer buf) {
441+
public void receiveCustomData(int dataId, @NotNull PacketBuffer buf) {
433442
super.receiveCustomData(dataId, buf);
434443
if (dataId == BEE_LOGIC_SYNC_ID) {
435444
readBeeLogicData(buf);
436445
}
437446
}
438447

439-
private void readBeeLogicData(net.minecraft.network.PacketBuffer buf) {
448+
private void readBeeLogicData(PacketBuffer buf) {
440449
getLogic().initBeekeepingLogicClient();
441450
IBeekeepingLogic logic = getBeekeepingLogic();
442451
try {
443452
if (logic != null) {
444453
logic.readData(buf);
445454
pendingBeeLogicData = null;
446455
} else {
447-
// Buffer the data for later application when the logic becomes available
448456
byte[] data = new byte[buf.readableBytes()];
449457
buf.readBytes(data);
450458
pendingBeeLogicData = data;
451459
}
452-
} catch (java.io.IOException e) {
453-
com.github.gtexpert.gtbm.api.util.ModLog.logger.error("Failed to read bee logic sync data", e);
460+
} catch (IOException e) {
461+
ModLog.logger.error("Failed to read bee logic sync data", e);
454462
}
455463
}
456464

457-
/** Applies buffered bee logic data that arrived before the logic was initialized on the client. */
458465
public void applyPendingBeeLogicData() {
459-
if (pendingBeeLogicData != null) {
460-
IBeekeepingLogic logic = getBeekeepingLogic();
461-
if (logic != null) {
462-
try {
463-
logic.readData(new net.minecraft.network.PacketBuffer(
464-
io.netty.buffer.Unpooled.wrappedBuffer(pendingBeeLogicData)));
465-
} catch (java.io.IOException e) {
466-
com.github.gtexpert.gtbm.api.util.ModLog.logger.error(
467-
"Failed to apply pending bee logic data", e);
468-
}
469-
pendingBeeLogicData = null;
470-
}
466+
if (pendingBeeLogicData == null) return;
467+
IBeekeepingLogic logic = getBeekeepingLogic();
468+
if (logic == null) return;
469+
try {
470+
logic.readData(new PacketBuffer(Unpooled.wrappedBuffer(pendingBeeLogicData)));
471+
} catch (IOException e) {
472+
ModLog.logger.error("Failed to apply pending bee logic data", e);
471473
}
474+
pendingBeeLogicData = null;
472475
}
473476

474477
// ---- Accessors ----

src/main/java/com/github/gtexpert/gtbm/mixins/GTBMMixinLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class GTBMMixinLoader implements ILateMixinLoader {
2020

2121
public static final Map<String, Boolean> modMixinsConfig = new ImmutableMap.Builder<String, Boolean>()
2222
.put(Mods.Names.FORESTRY, true)
23+
.put(Mods.Names.GENDUSTRY, true)
2324
.put(Mods.Names.GREGICALITY_MULTIBLOCKS, true)
2425
.build();
2526

0 commit comments

Comments
 (0)