2020-07-24 19:43:33 +02:00
|
|
|
package com.simibubi.create.events;
|
2019-09-03 08:34:02 +02:00
|
|
|
|
2020-12-03 20:41:55 +01:00
|
|
|
import com.simibubi.create.AllFluids;
|
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;
|
2020-11-13 20:56:39 +01:00
|
|
|
import com.simibubi.create.content.contraptions.fluids.recipe.FluidTransferRecipes;
|
|
|
|
import com.simibubi.create.content.contraptions.fluids.recipe.PotionMixingRecipeManager;
|
2020-10-08 20:13:17 +02:00
|
|
|
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;
|
2020-12-03 20:41:55 +01:00
|
|
|
import com.simibubi.create.foundation.fluid.FluidHelper;
|
|
|
|
import com.simibubi.create.foundation.utility.Iterate;
|
2020-08-05 22:10:05 +02:00
|
|
|
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-12-03 20:41:55 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2020-08-05 22:10:05 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
2020-12-03 20:41:55 +01:00
|
|
|
import net.minecraft.fluid.IFluidState;
|
2020-10-19 22:07:05 +02:00
|
|
|
import net.minecraft.resources.IReloadableResourceManager;
|
2020-12-03 20:41:55 +01:00
|
|
|
import net.minecraft.tags.FluidTags;
|
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
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;
|
2020-11-27 20:37:10 +01:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
2020-12-03 20:41:55 +01:00
|
|
|
import net.minecraftforge.event.world.BlockEvent.FluidPlaceBlockEvent;
|
2020-10-08 20:13:17 +02:00
|
|
|
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-19 22:07:05 +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
|
|
|
|
2020-12-03 20:41:55 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void whenFluidsMeet(FluidPlaceBlockEvent event) {
|
|
|
|
BlockState blockState = event.getOriginalState();
|
|
|
|
IFluidState fluidState = blockState.getFluidState();
|
|
|
|
BlockPos pos = event.getPos();
|
|
|
|
IWorld world = event.getWorld();
|
|
|
|
|
|
|
|
if (fluidState.isSource() && FluidHelper.isLava(fluidState.getFluid()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Direction direction : Iterate.directions) {
|
|
|
|
IFluidState metFluidState = fluidState.isSource() ? fluidState : world.getFluidState(pos.offset(direction));
|
|
|
|
if (!metFluidState.isTagged(FluidTags.WATER))
|
|
|
|
continue;
|
|
|
|
BlockState lavaInteraction = AllFluids.getLavaInteraction(metFluidState);
|
|
|
|
if (lavaInteraction == null)
|
|
|
|
continue;
|
|
|
|
event.setNewState(lavaInteraction);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2020-10-19 22:07:05 +02:00
|
|
|
|
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) {
|
|
|
|
AllCommands.register(event.getCommandDispatcher());
|
|
|
|
}
|
|
|
|
|
2020-09-04 01:23:09 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
2020-10-19 22:07:05 +02:00
|
|
|
IReloadableResourceManager resourceManager = event.getServer()
|
|
|
|
.getResourceManager();
|
|
|
|
resourceManager.addReloadListener(RecipeFinder.LISTENER);
|
|
|
|
resourceManager.addReloadListener(PotionMixingRecipeManager.LISTENER);
|
2020-11-13 20:56:39 +01:00
|
|
|
resourceManager.addReloadListener(FluidTransferRecipes.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-19 22:07:05 +02:00
|
|
|
|
2020-10-08 20:13:17 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {
|
|
|
|
CapabilityMinecartController.attach(event);
|
|
|
|
}
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2020-11-27 20:37:10 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void startTracking(PlayerEvent.StartTracking event) {
|
|
|
|
CapabilityMinecartController.startTracking(event);
|
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|