@@ -272,6 +272,12 @@ public enum GameMode {
272272 static final int CAMERA_WIDTH = 1280 ;
273273 static final int CAMERA_HEIGHT = 1024 ;
274274
275+ public FenceBuildingManager getFenceBuildingManager () {
276+ return fenceBuildingManager ;
277+ }
278+
279+
280+
275281 @ Override
276282 public void create () {
277283 // Initialize localization system first (before any UI components)
@@ -2436,13 +2442,24 @@ private void clearLocalWorld() {
24362442 plantedBamboos .clear ();
24372443
24382444 // Clear cleared positions map
2439- clearedPositions .clear ();
2440-
2441- long duration = System .currentTimeMillis () - startTime ;
2442- System .out .println ("Local world cleared successfully in " + duration + "ms" );
2443- System .out .println ("Cleared planted trees and bamboos to prevent singleplayer items in multiplayer" );
2444-
2445- } catch (Exception e ) {
2445+ clearedPositions .clear ();
2446+
2447+ // CRITICAL FIX: Clear fence structures to prevent singleplayer fences in multiplayer
2448+ if (fenceBuildingManager != null ) {
2449+ try {
2450+ fenceBuildingManager .getStructureManager ().clear ();
2451+ fenceBuildingManager .rebuildCollisionBoundaries ();
2452+ System .out .println ("Cleared fence structures for multiplayer" );
2453+ } catch (Exception e ) {
2454+ System .err .println ("Error clearing fence structures: " + e .getMessage ());
2455+ }
2456+ }
2457+
2458+ long duration = System .currentTimeMillis () - startTime ;
2459+ System .out .println ("Local world cleared successfully in " + duration + "ms" );
2460+ System .out .println ("Cleared planted trees and bamboos to prevent singleplayer items in multiplayer" );
2461+
2462+ } catch (Exception e ) {
24462463 System .err .println ("Error clearing local world: " + e .getMessage ());
24472464 e .printStackTrace ();
24482465 // Continue anyway - server state will override
@@ -3649,6 +3666,24 @@ public boolean restoreWorldState(WorldSaveData saveData) {
36493666 }
36503667 }
36513668
3669+ // Restore fence structures from world save
3670+ if (saveData .getFenceStructures () != null && !saveData .getFenceStructures ().isEmpty () && fenceBuildingManager != null ) {
3671+ try {
3672+ int restoredCount = wagemaker .uk .fence .FencePersistenceManager .deserializeFenceStructures (
3673+ saveData .getFenceStructures (),
3674+ fenceBuildingManager .getStructureManager ()
3675+ );
3676+
3677+ // Rebuild collision boundaries after restoration
3678+ fenceBuildingManager .rebuildCollisionBoundaries ();
3679+
3680+ System .out .println ("Restored " + restoredCount + " fence structures from world save" );
3681+ } catch (Exception e ) {
3682+ System .err .println ("Error restoring fence structures: " + e .getMessage ());
3683+ e .printStackTrace ();
3684+ }
3685+ }
3686+
36523687 System .out .println ("World state restoration completed successfully" );
36533688 return true ;
36543689
@@ -3755,6 +3790,17 @@ private void cleanupExistingWorldState() {
37553790 // Clear cleared positions
37563791 clearedPositions .clear ();
37573792
3793+ // Clear fence structures
3794+ if (fenceBuildingManager != null ) {
3795+ try {
3796+ fenceBuildingManager .getStructureManager ().clear ();
3797+ fenceBuildingManager .rebuildCollisionBoundaries ();
3798+ System .out .println ("Cleared fence structures during world cleanup" );
3799+ } catch (Exception e ) {
3800+ System .err .println ("Error clearing fence structures: " + e .getMessage ());
3801+ }
3802+ }
3803+
37583804 System .out .println ("Existing world state cleaned up successfully" );
37593805
37603806 } catch (Exception e ) {
0 commit comments