2020-07-24 19:43:33 +02:00
|
|
|
package com.simibubi.create.events;
|
2019-09-03 08:34:02 +02:00
|
|
|
|
2020-07-24 19:43:33 +02:00
|
|
|
import com.simibubi.create.Create;
|
2020-08-05 22:10:05 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionCollider;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.MinecartCouplingHandler;
|
|
|
|
import com.simibubi.create.content.schematics.ServerSchematicLoader;
|
|
|
|
import com.simibubi.create.foundation.command.AllCommands;
|
|
|
|
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
|
|
|
import com.simibubi.create.foundation.utility.WorldAttached;
|
2020-09-04 01:23:09 +02:00
|
|
|
import com.simibubi.create.foundation.utility.recipe.RecipeFinder;
|
2020-05-23 21:03:35 +02:00
|
|
|
|
2020-08-05 22:10:05 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraft.world.IWorld;
|
2020-08-05 22:10:05 +02:00
|
|
|
import net.minecraft.world.World;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.event.TickEvent.Phase;
|
|
|
|
import net.minecraftforge.event.TickEvent.ServerTickEvent;
|
2020-08-05 22:10:05 +02:00
|
|
|
import net.minecraftforge.event.TickEvent.WorldTickEvent;
|
|
|
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
2020-09-04 01:23:09 +02:00
|
|
|
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
|
2020-05-23 21:03:35 +02:00
|
|
|
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
|
|
|
|
|
|
|
@EventBusSubscriber
|
2020-05-23 14:02:38 +02:00
|
|
|
public class CommonEvents {
|
2019-09-03 08:34:02 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
2020-08-05 22:10:05 +02:00
|
|
|
public static void onServerTick(ServerTickEvent event) {
|
|
|
|
if (event.phase == Phase.START)
|
2019-09-03 08:34:02 +02:00
|
|
|
return;
|
2020-08-05 22:10:05 +02:00
|
|
|
if (Create.schematicReceiver == null)
|
|
|
|
Create.schematicReceiver = new ServerSchematicLoader();
|
|
|
|
Create.schematicReceiver.tick();
|
|
|
|
Create.lagger.tick();
|
|
|
|
ServerSpeedProvider.serverTick();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
2020-08-05 22:10:05 +02:00
|
|
|
public static void onWorldTick(WorldTickEvent event) {
|
|
|
|
if (event.phase == Phase.START)
|
|
|
|
return;
|
|
|
|
World world = event.world;
|
|
|
|
ContraptionCollider.runCollisions(world);
|
|
|
|
MinecartCouplingHandler.tick(world);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onUpdateLivingEntity(LivingUpdateEvent event) {
|
|
|
|
LivingEntity entityLiving = event.getEntityLiving();
|
|
|
|
World world = entityLiving.world;
|
|
|
|
if (world == null)
|
|
|
|
return;
|
|
|
|
ContraptionHandler.entitiesWhoJustDismountedGetSentToTheRightLocation(entityLiving, world);
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
2020-09-04 01:23:09 +02:00
|
|
|
|
2020-05-23 21:03:35 +02:00
|
|
|
@SubscribeEvent
|
2020-08-05 22:10:05 +02:00
|
|
|
public static void onEntityAdded(EntityJoinWorldEvent event) {
|
|
|
|
Entity entity = event.getEntity();
|
|
|
|
World world = event.getWorld();
|
|
|
|
ContraptionHandler.addSpawnedContraptionsToCollisionList(entity, world);
|
|
|
|
MinecartCouplingHandler.handleAddedMinecart(entity, world);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverStarted(FMLServerStartingEvent event) {
|
|
|
|
AllCommands.register(event.getCommandDispatcher());
|
|
|
|
}
|
|
|
|
|
2020-09-04 01:23:09 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
|
|
|
event.getServer()
|
|
|
|
.getResourceManager()
|
|
|
|
.addReloadListener(RecipeFinder.LISTENER);
|
|
|
|
}
|
|
|
|
|
2020-08-05 22:10:05 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverStopped(FMLServerStoppingEvent event) {
|
|
|
|
Create.schematicReceiver.shutdown();
|
2020-05-23 21:03:35 +02:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 23:03:52 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onLoadWorld(WorldEvent.Load event) {
|
|
|
|
IWorld world = event.getWorld();
|
2020-01-05 19:41:38 +01:00
|
|
|
Create.redstoneLinkNetworkHandler.onLoadWorld(world);
|
2019-11-01 01:09:38 +01:00
|
|
|
Create.torquePropagator.onLoadWorld(world);
|
2019-09-03 23:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onUnloadWorld(WorldEvent.Unload event) {
|
|
|
|
IWorld world = event.getWorld();
|
2020-01-05 19:41:38 +01:00
|
|
|
Create.redstoneLinkNetworkHandler.onUnloadWorld(world);
|
2019-11-01 01:09:38 +01:00
|
|
|
Create.torquePropagator.onUnloadWorld(world);
|
2020-08-05 22:10:05 +02:00
|
|
|
WorldAttached.invalidateWorld(world);
|
2019-09-03 23:03:52 +02:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|