Fix WorldData initialization

This commit is contained in:
Sebastian Hartte
2020-07-02 01:28:02 +02:00
parent 2dd2b5d034
commit c7b1ab756b
3 changed files with 28 additions and 4 deletions
@@ -13,6 +13,7 @@ import appeng.core.AppEng;
import appeng.core.AppEngBase;
import appeng.core.features.registries.PartModels;
import appeng.core.sync.network.ClientNetworkHandler;
import appeng.core.worlddata.WorldData;
import appeng.entity.*;
import appeng.hooks.ClientTickHandler;
import appeng.util.Platform;
@@ -22,6 +23,7 @@ import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.entity.ItemEntityRenderer;
import net.minecraft.client.render.model.BakedModel;
@@ -69,6 +71,12 @@ public final class AppEngClient extends AppEngBase {
registerEntityRenderers();
registerItemColors();
registerTextures();
// On the client, we'll register for server startup/shutdown to properly setup WorldData
// each time the integrated server starts&stops
ServerLifecycleEvents.SERVER_STARTED.register(WorldData::onServerStarting);
ServerLifecycleEvents.SERVER_STOPPING.register(server -> WorldData.instance().onServerStopping());
ServerLifecycleEvents.SERVER_STOPPED.register(server -> WorldData.instance().onServerStoppped());
}
@Override
+5 -4
View File
@@ -18,6 +18,9 @@
package appeng.core.api;
import appeng.api.util.AEPartLocation;
import appeng.me.GridConnection;
import appeng.me.GridNode;
import com.google.common.base.Preconditions;
import appeng.api.exceptions.FailedConnectionException;
@@ -42,8 +45,7 @@ public class ApiGrid implements IGridHelper {
throw new IllegalStateException("Grid features for " + blk + " are server side only.");
}
// FIXME FABRIC return new GridNode(blk);
throw new IllegalStateException();
return new GridNode(blk);
}
@Override
@@ -51,8 +53,7 @@ public class ApiGrid implements IGridHelper {
Preconditions.checkNotNull(a);
Preconditions.checkNotNull(b);
// FIXME FABRIC return GridConnection.create(a, b, AEPartLocation.INTERNAL);
throw new IllegalStateException();
return GridConnection.create(a, b, AEPartLocation.INTERNAL);
}
}
@@ -6,7 +6,9 @@ import appeng.client.ActionKey;
import appeng.client.EffectType;
import appeng.core.AppEngBase;
import appeng.core.sync.network.ServerNetworkHandler;
import appeng.core.worlddata.WorldData;
import appeng.hooks.TickHandler;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.server.PlayerStream;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.InputUtil;
@@ -32,6 +34,19 @@ public final class AppEngServer extends AppEngBase {
this.server = server;
this.networkHandler = new ServerNetworkHandler();
this.tickHandler = new TickHandler();
// For a dedicated server, the lifecycle of WorldData is much simpler
WorldData.onServerStarting(server);
ServerLifecycleEvents.SERVER_STOPPING.register(s -> onServerStopping());
ServerLifecycleEvents.SERVER_STOPPED.register(s -> onServerStopped());
}
private void onServerStopping() {
WorldData.instance().onServerStopping();
}
private void onServerStopped() {
WorldData.instance().onServerStoppped();
}
@Override