55import gregtech .api .metatileentity .multiblock .MultiblockAbility ;
66import gregtech .api .metatileentity .multiblock .RecipeMapMultiblockController ;
77import gregtech .api .recipes .Recipe ;
8+ import gregtech .common .sound .GTSoundEvents ;
9+ import net .minecraft .network .PacketBuffer ;
10+ import net .minecraft .util .SoundEvent ;
811import net .minecraftforge .items .IItemHandlerModifiable ;
912
13+ import javax .annotation .Nullable ;
1014import java .util .List ;
1115
1216import static gregtech .api .metatileentity .MetaTileEntity .addItemsToItemHandler ;
@@ -17,6 +21,12 @@ public class MultiblockRecipeLogic extends AbstractRecipeLogic {
1721 /** Indicates that a structure fails to meet requirements for proceeding with the active recipe */
1822 protected boolean isJammed = false ;
1923
24+ /** DataIDs for packets */
25+ private static final class DataIDs {
26+ /** Jammed state changed */
27+ private static final int JAMMED = 3 ;
28+ }
29+
2030 private boolean invalidated = true ;
2131
2232 public MultiblockRecipeLogic (RecipeMapMultiblockController tileEntity ) {
@@ -121,8 +131,15 @@ private void checkIfJammed() {
121131 metaTileEntity .getNotifiedItemOutputList ().clear ();
122132 metaTileEntity .getNotifiedFluidOutputList ().clear ();
123133
134+ // remember prior value
135+ boolean oldJammed = this .isJammed ;
136+
124137 // Jam if we can't output all items and fluids, or we fail whatever other conditions the controller imposes
125138 this .isJammed = !(canFitItems && canFitFluids && controller .checkRecipe (previousRecipe , false ));
139+
140+ // Sync state if changed
141+ if (this .isJammed != oldJammed )
142+ writeCustomData (DataIDs .JAMMED , buf -> buf .writeBoolean (this .isJammed ));
126143 }
127144 }
128145
@@ -163,4 +180,31 @@ protected void completeRecipe() {
163180 if (!this .isJammed )
164181 super .completeRecipe ();
165182 }
183+
184+ @ Override
185+ public void writeInitialData (PacketBuffer buf ) {
186+ super .writeInitialData (buf );
187+ buf .writeBoolean (isJammed );
188+ }
189+
190+ @ Override
191+ public void receiveInitialData (PacketBuffer buf ) {
192+ super .receiveInitialData (buf );
193+ isJammed = buf .readBoolean ();
194+ }
195+
196+ @ Override
197+ public void receiveCustomData (int dataId , PacketBuffer buf ) {
198+ super .receiveCustomData (dataId , buf );
199+ if (dataId == DataIDs .JAMMED )
200+ isJammed = buf .readBoolean ();
201+ }
202+
203+ @ Override
204+ @ Nullable
205+ public SoundEvent getSound () {
206+ if (isActive && (isJammed || hasNotEnoughEnergy ))
207+ return GTSoundEvents .INTERRUPTED ;
208+ return recipeMap .getSound ();
209+ }
166210}
0 commit comments