Skip to content

Commit 7b4b381

Browse files
committed
ApiaryのUI仮完成
1 parent fb20516 commit 7b4b381

20 files changed

Lines changed: 961 additions & 4 deletions

src/main/java/com/github/gtexpert/gtbm/api/gui/GTBMGuiTextures.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ public class GTBMGuiTextures {
1414
.fullImage("textures/gui/icon/gtbm_logo_blinking_yellow.png");
1515
public static final TextureArea GTBM_LOGO_BLINKING_RED = TextureArea
1616
.fullImage("textures/gui/icon/gtbm_logo_blinking_red.png");
17+
18+
// Bee slot overlays
19+
public static final TextureArea QUEEN_OVERLAY = TextureArea
20+
.fullImage("textures/gui/overlay/queen_overlay.png");
21+
public static final TextureArea DRONE_OVERLAY = TextureArea
22+
.fullImage("textures/gui/overlay/drone_overlay.png");
23+
public static final TextureArea UPGRADE_OVERLAY = TextureArea
24+
.fullImage("textures/gui/overlay/upgrade_overlay.png");
1725
}

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

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,215 @@
22

33
import java.util.function.Supplier;
44

5+
import net.bdew.gendustry.api.ApiaryModifiers;
6+
import net.bdew.gendustry.api.items.IApiaryUpgrade;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.nbt.NBTTagCompound;
9+
510
import org.jetbrains.annotations.NotNull;
611

712
import gregtech.api.capability.IEnergyContainer;
813
import gregtech.api.capability.impl.RecipeLogicEnergy;
914
import gregtech.api.metatileentity.MetaTileEntity;
1015
import gregtech.api.recipes.RecipeMap;
1116

17+
import forestry.api.apiculture.*;
18+
import forestry.api.genetics.AlleleManager;
19+
import forestry.core.errors.EnumErrorCode;
20+
1221
public class IndustrialApiaryLogic extends RecipeLogicEnergy {
1322

23+
private static final int BASE_EU_PER_TICK = 32;
24+
25+
private IBeeRoot beeRoot;
26+
private IBeekeepingLogic beekeepingLogic;
27+
private boolean needsMovePrincess;
28+
1429
public IndustrialApiaryLogic(@NotNull MetaTileEntity metaTileEntity, RecipeMap<?> recipeMap,
1530
Supplier<IEnergyContainer> energyContainer) {
1631
super(metaTileEntity, recipeMap, energyContainer);
1732
}
33+
34+
private MetaTileEntityIndustrialApiary getApiary() {
35+
return (MetaTileEntityIndustrialApiary) metaTileEntity;
36+
}
37+
38+
// ---- Bee system initialization ----
39+
40+
public IBeeRoot getBeeRoot() {
41+
if (beeRoot == null) {
42+
beeRoot = (IBeeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootBees");
43+
}
44+
return beeRoot;
45+
}
46+
47+
private void initBeekeepingLogic() {
48+
if (beekeepingLogic == null && metaTileEntity.getWorld() != null) {
49+
IBeeRoot root = getBeeRoot();
50+
if (root != null) {
51+
beekeepingLogic = root.createBeekeepingLogic(getApiary());
52+
}
53+
}
54+
}
55+
56+
public IBeekeepingLogic getBeekeepingLogic() {
57+
return beekeepingLogic;
58+
}
59+
60+
// ---- Modifier management ----
61+
62+
public void updateModifiers() {
63+
MetaTileEntityIndustrialApiary apiary = getApiary();
64+
ApiaryModifiers mods = apiary.getModifiers();
65+
if (mods == null) return;
66+
67+
mods.territory = 1;
68+
mods.mutation = 1;
69+
mods.lifespan = 1;
70+
mods.production = 1;
71+
mods.flowering = 1;
72+
mods.geneticDecay = 1;
73+
mods.energy = 1;
74+
mods.temperature = 0;
75+
mods.humidity = 0;
76+
mods.isSealed = false;
77+
mods.isSelfLighted = false;
78+
mods.isSunlightSimulated = false;
79+
mods.isAutomated = false;
80+
mods.isCollectingPollen = false;
81+
mods.biomeOverride = null;
82+
83+
var upgradeInventory = apiary.getUpgradeInventory();
84+
if (upgradeInventory == null) return;
85+
86+
for (int i = 0; i < upgradeInventory.getSlots(); i++) {
87+
ItemStack stack = upgradeInventory.getStackInSlot(i);
88+
if (!stack.isEmpty() && stack.getItem() instanceof IApiaryUpgrade) {
89+
((IApiaryUpgrade) stack.getItem()).applyModifiers(mods, stack);
90+
}
91+
}
92+
}
93+
94+
public int getEUPerTick() {
95+
ApiaryModifiers mods = getApiary().getModifiers();
96+
if (mods == null) return BASE_EU_PER_TICK;
97+
return (int) (BASE_EU_PER_TICK * mods.energy);
98+
}
99+
100+
// ---- Core tick logic ----
101+
102+
@Override
103+
public void update() {
104+
if (metaTileEntity.getWorld() == null || metaTileEntity.getWorld().isRemote) return;
105+
106+
initBeekeepingLogic();
107+
if (beekeepingLogic == null) return;
108+
109+
MetaTileEntityIndustrialApiary apiary = getApiary();
110+
needsMovePrincess = false;
111+
112+
// Update modifiers from upgrades
113+
updateModifiers();
114+
115+
// Power check
116+
int euPerTick = getEUPerTick();
117+
boolean hasPower = getEnergyStored() >= euPerTick;
118+
119+
apiary.getErrorLogic().setCondition(!hasPower, EnumErrorCode.NO_POWER);
120+
121+
// Beekeeping tick
122+
boolean canWork = beekeepingLogic.canWork();
123+
boolean isWorking = hasPower && workingEnabled && canWork;
124+
125+
if (isWorking) {
126+
beekeepingLogic.doWork();
127+
drawEnergy(euPerTick, false);
128+
}
129+
130+
// GT energy indicator: only show when actively working but can't draw power
131+
// (matches GT default: only during active recipe processing)
132+
if (canWork && workingEnabled && !hasPower) {
133+
hasNotEnoughEnergy = true;
134+
} else if (hasNotEnoughEnergy && getEnergyInputPerSecond() > 19L * euPerTick) {
135+
hasNotEnoughEnergy = false;
136+
}
137+
138+
// Auto-move princess to queen slot
139+
if (needsMovePrincess && apiary.getQueen().isEmpty()) {
140+
doMovePrincess();
141+
}
142+
143+
// Update GT active state
144+
boolean hasQueen = !apiary.getQueen().isEmpty();
145+
boolean shouldBeActive = isWorking || (hasQueen && canWork && workingEnabled);
146+
147+
if (isActive != shouldBeActive) {
148+
setActive(shouldBeActive);
149+
}
150+
151+
// Progress for GUI
152+
if (hasQueen && beekeepingLogic.getBeeProgressPercent() > 0) {
153+
progressTime = beekeepingLogic.getBeeProgressPercent();
154+
maxProgressTime = 100;
155+
} else {
156+
progressTime = 0;
157+
maxProgressTime = 0;
158+
}
159+
}
160+
161+
public float getBeeProgress() {
162+
if (beekeepingLogic == null || getApiary().getQueen().isEmpty()) return 0;
163+
return beekeepingLogic.getBeeProgressPercent() / 100F;
164+
}
165+
166+
// ---- Princess auto-move ----
167+
168+
public void setNeedsMovePrincess() {
169+
needsMovePrincess = true;
170+
}
171+
172+
private void doMovePrincess() {
173+
if (beeRoot == null) return;
174+
MetaTileEntityIndustrialApiary apiary = getApiary();
175+
for (int i = 0; i < apiary.getExportItems().getSlots(); i++) {
176+
ItemStack stack = apiary.getExportItems().getStackInSlot(i);
177+
if (!stack.isEmpty() && beeRoot.isMember(stack, EnumBeeType.PRINCESS)) {
178+
apiary.setQueen(stack);
179+
apiary.getExportItems().setStackInSlot(i, ItemStack.EMPTY);
180+
return;
181+
}
182+
}
183+
}
184+
185+
// ---- Override recipe logic (no-op) ----
186+
187+
@Override
188+
protected void trySearchNewRecipe() {}
189+
190+
@Override
191+
protected void updateRecipeProgress() {}
192+
193+
// ---- NBT: save/load beekeeping state ----
194+
195+
@Override
196+
public NBTTagCompound serializeNBT() {
197+
NBTTagCompound tag = super.serializeNBT();
198+
if (beekeepingLogic != null) {
199+
NBTTagCompound beeTag = new NBTTagCompound();
200+
beekeepingLogic.writeToNBT(beeTag);
201+
tag.setTag("BeekeepingLogic", beeTag);
202+
}
203+
return tag;
204+
}
205+
206+
@Override
207+
public void deserializeNBT(@NotNull NBTTagCompound compound) {
208+
super.deserializeNBT(compound);
209+
if (compound.hasKey("BeekeepingLogic")) {
210+
initBeekeepingLogic();
211+
if (beekeepingLogic != null) {
212+
beekeepingLogic.readFromNBT(compound.getCompoundTag("BeekeepingLogic"));
213+
}
214+
}
215+
}
18216
}

0 commit comments

Comments
 (0)