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.ContraptionHandler;
|
2020-10-08 20:13:17 +02:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingPhysics;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController;
|
|
|
|
import com.simibubi.create.content.contraptions.wrench.WrenchItem;
|
2020-08-05 22:10:05 +02:00
|
|
|
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;
|
2020-09-23 11:15:32 +02:00
|
|
|
import net.minecraft.resources.IReloadableResourceManager;
|
|
|
|
import net.minecraft.resources.IResourceManager;
|
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;
|
2020-10-08 20:13:17 +02:00
|
|
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
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;
|
2020-10-08 20:13:17 +02:00
|
|
|
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
|
|
import net.minecraftforge.event.world.ChunkEvent;
|
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
|
|
|
}
|
2020-10-08 20:13:17 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onChunkUnloaded(ChunkEvent.Unload event) {
|
|
|
|
CapabilityMinecartController.onChunkUnloaded(event);
|
|
|
|
}
|
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;
|
2020-10-08 20:13:17 +02:00
|
|
|
ContraptionHandler.tick(world);
|
|
|
|
CapabilityMinecartController.tick(world);
|
|
|
|
CouplingPhysics.tick(world);
|
2020-08-05 22:10:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
2020-10-08 20:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onEntityAttackedByPlayer(AttackEntityEvent event) {
|
|
|
|
WrenchItem.wrenchInstaKillsMinecarts(event);
|
2020-08-05 22:10:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverStarted(FMLServerStartingEvent event) {
|
2020-09-22 22:00:44 +02:00
|
|
|
AllCommands.register(event.getServer().getCommandManager().getDispatcher());
|
2020-08-05 22:10:05 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 01:23:09 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
2020-09-23 11:15:32 +02:00
|
|
|
IResourceManager manager = event.getServer().getDataPackRegistries().getResourceManager();
|
|
|
|
if (manager instanceof IReloadableResourceManager)
|
|
|
|
((IReloadableResourceManager) manager).addReloadListener(RecipeFinder.LISTENER);
|
2020-09-04 01:23:09 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2020-10-08 20:13:17 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {
|
|
|
|
CapabilityMinecartController.attach(event);
|
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|