11package com .github .gtexpert .gtbm .integration .gendustry .metatileentities ;
22
3+ import java .io .IOException ;
34import java .util .Collections ;
45import java .util .function .Function ;
56
1011import net .minecraft .entity .player .EntityPlayer ;
1112import net .minecraft .item .ItemStack ;
1213import net .minecraft .nbt .NBTTagCompound ;
14+ import net .minecraft .network .PacketBuffer ;
1315import net .minecraft .util .EnumFacing ;
1416import net .minecraft .util .NonNullList ;
1517import net .minecraft .util .ResourceLocation ;
1921import net .minecraft .world .biome .Biome ;
2022import net .minecraftforge .items .IItemHandlerModifiable ;
2123
24+ import org .jetbrains .annotations .NotNull ;
25+
2226import com .mojang .authlib .GameProfile ;
2327
2428import gregtech .api .GTValues ;
3337import gregtech .client .renderer .ICubeRenderer ;
3438
3539import com .github .gtexpert .gtbm .api .gui .GTBMGuiTextures ;
40+ import com .github .gtexpert .gtbm .api .util .ModLog ;
3641import com .github .gtexpert .gtbm .common .metatileentities .GTBMSimpleMachineMetaTileEntity ;
3742import com .github .gtexpert .gtbm .integration .forestry .util .BeeProductHelper ;
3843import com .github .gtexpert .gtbm .integration .gendustry .util .ApiaryModifierBridge ;
4449import forestry .api .genetics .IIndividual ;
4550import forestry .core .errors .ErrorLogic ;
4651import forestry .core .owner .OwnerHandler ;
52+ import io .netty .buffer .Unpooled ;
4753
4854public 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 ----
0 commit comments