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;
|
2021-09-16 20:14:38 +02:00
|
|
|
import com.simibubi.create.content.curiosities.toolbox.ToolboxHandler;
|
2021-09-19 02:40:57 +02:00
|
|
|
import com.simibubi.create.content.curiosities.weapons.PotatoProjectileTypeManager;
|
2020-12-12 12:32:32 +01:00
|
|
|
import com.simibubi.create.content.curiosities.zapper.ZapperInteractionHandler;
|
|
|
|
import com.simibubi.create.content.curiosities.zapper.ZapperItem;
|
2021-05-26 22:03:06 +02:00
|
|
|
import com.simibubi.create.content.logistics.item.LinkedControllerServerHandler;
|
2020-08-05 22:10:05 +02:00
|
|
|
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;
|
2021-11-11 07:15:26 +01:00
|
|
|
import com.simibubi.create.foundation.worldgen.AllWorldFeatures;
|
2021-04-08 19:22:11 +02:00
|
|
|
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
import net.minecraft.tags.FluidTags;
|
2021-11-02 00:08:20 +01:00
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.Level;
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.level.material.FluidState;
|
2021-11-11 07:15:26 +01:00
|
|
|
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
2020-10-20 19:37:30 +02:00
|
|
|
import net.minecraftforge.event.AddReloadListenerEvent;
|
2020-10-08 20:13:17 +02:00
|
|
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
2021-03-20 12:58:02 +01:00
|
|
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
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;
|
2021-09-16 20:14:38 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
|
2020-12-03 20:41:55 +01:00
|
|
|
import net.minecraftforge.event.world.BlockEvent.FluidPlaceBlockEvent;
|
2021-11-11 07:15:26 +01:00
|
|
|
import net.minecraftforge.event.world.BiomeLoadingEvent;
|
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;
|
2021-11-11 07:15:26 +01:00
|
|
|
import net.minecraftforge.eventbus.api.EventPriority;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraftforge.fmlserverevents.FMLServerStoppingEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
|
|
|
|
@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;
|
2021-05-23 03:00:10 +02:00
|
|
|
Create.SCHEMATIC_RECEIVER.tick();
|
|
|
|
Create.LAGGER.tick();
|
2020-08-05 22:10:05 +02:00
|
|
|
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
|
|
|
|
2021-09-16 20:14:38 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void playerLoggedIn(PlayerLoggedInEvent event) {
|
2021-11-02 00:08:20 +01:00
|
|
|
Player player = event.getPlayer();
|
2021-09-16 20:14:38 +02:00
|
|
|
ToolboxHandler.playerLogin(player);
|
|
|
|
}
|
|
|
|
|
2020-12-03 20:41:55 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void whenFluidsMeet(FluidPlaceBlockEvent event) {
|
|
|
|
BlockState blockState = event.getOriginalState();
|
2020-12-05 11:42:14 +01:00
|
|
|
FluidState fluidState = blockState.getFluidState();
|
2020-12-03 20:41:55 +01:00
|
|
|
BlockPos pos = event.getPos();
|
2021-11-02 00:08:20 +01:00
|
|
|
LevelAccessor world = event.getWorld();
|
2020-12-03 20:41:55 +01:00
|
|
|
|
2021-07-15 11:32:03 +02:00
|
|
|
if (fluidState.isSource() && FluidHelper.isLava(fluidState.getType()))
|
2020-12-03 20:41:55 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (Direction direction : Iterate.directions) {
|
2021-09-16 20:14:38 +02:00
|
|
|
FluidState metFluidState =
|
|
|
|
fluidState.isSource() ? fluidState : world.getFluidState(pos.relative(direction));
|
2021-07-15 11:32:03 +02:00
|
|
|
if (!metFluidState.is(FluidTags.WATER))
|
2020-12-03 20:41:55 +01:00
|
|
|
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;
|
2021-11-02 00:08:20 +01:00
|
|
|
Level world = event.world;
|
2020-10-08 20:13:17 +02:00
|
|
|
ContraptionHandler.tick(world);
|
|
|
|
CapabilityMinecartController.tick(world);
|
|
|
|
CouplingPhysics.tick(world);
|
2021-05-26 22:03:06 +02:00
|
|
|
LinkedControllerServerHandler.tick(world);
|
2020-08-05 22:10:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onUpdateLivingEntity(LivingUpdateEvent event) {
|
|
|
|
LivingEntity entityLiving = event.getEntityLiving();
|
2021-11-02 00:08:20 +01:00
|
|
|
Level world = entityLiving.level;
|
2020-08-05 22:10:05 +02:00
|
|
|
if (world == null)
|
|
|
|
return;
|
|
|
|
ContraptionHandler.entitiesWhoJustDismountedGetSentToTheRightLocation(entityLiving, world);
|
2021-09-16 20:14:38 +02:00
|
|
|
ToolboxHandler.entityTick(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();
|
2021-11-02 00:08:20 +01:00
|
|
|
Level world = event.getWorld();
|
2020-08-05 22:10:05 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-09-19 02:40:57 +02:00
|
|
|
@SubscribeEvent
|
2021-03-20 12:58:02 +01:00
|
|
|
public static void registerCommands(RegisterCommandsEvent event) {
|
|
|
|
AllCommands.register(event.getDispatcher());
|
2020-08-05 22:10:05 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 01:23:09 +02:00
|
|
|
@SubscribeEvent
|
2020-10-20 19:37:30 +02:00
|
|
|
public static void registerReloadListeners(AddReloadListenerEvent event) {
|
|
|
|
event.addListener(RecipeFinder.LISTENER);
|
|
|
|
event.addListener(PotionMixingRecipeManager.LISTENER);
|
2020-11-14 15:22:32 +01:00
|
|
|
event.addListener(FluidTransferRecipes.LISTENER);
|
2021-09-19 02:40:57 +02:00
|
|
|
event.addListener(PotatoProjectileTypeManager.ReloadListener.INSTANCE);
|
2020-09-04 01:23:09 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 22:10:05 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void serverStopped(FMLServerStoppingEvent event) {
|
2021-05-23 03:00:10 +02:00
|
|
|
Create.SCHEMATIC_RECEIVER.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) {
|
2021-11-02 00:08:20 +01:00
|
|
|
LevelAccessor world = event.getWorld();
|
2021-05-23 03:00:10 +02:00
|
|
|
Create.REDSTONE_LINK_NETWORK_HANDLER.onLoadWorld(world);
|
|
|
|
Create.TORQUE_PROPAGATOR.onLoadWorld(world);
|
2019-09-03 23:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onUnloadWorld(WorldEvent.Unload event) {
|
2021-11-02 00:08:20 +01:00
|
|
|
LevelAccessor world = event.getWorld();
|
2021-05-23 03:00:10 +02:00
|
|
|
Create.REDSTONE_LINK_NETWORK_HANDLER.onUnloadWorld(world);
|
|
|
|
Create.TORQUE_PROPAGATOR.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
|
|
|
|
2021-11-11 07:15:26 +01:00
|
|
|
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
|
|
public static void onBiomeLoad(BiomeLoadingEvent event) {
|
|
|
|
AllWorldFeatures.reload(event);
|
|
|
|
}
|
|
|
|
|
2021-11-02 00:08:20 +01:00
|
|
|
public static void leftClickEmpty(ServerPlayer player) {
|
2021-07-15 11:32:03 +02:00
|
|
|
ItemStack stack = player.getMainHandItem();
|
2020-12-12 12:32:32 +01:00
|
|
|
if (stack.getItem() instanceof ZapperItem) {
|
|
|
|
ZapperInteractionHandler.trySelect(stack, player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 07:15:26 +01:00
|
|
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
|
|
|
public static class ModBusEvents {
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerCapabilities(RegisterCapabilitiesEvent event) {
|
|
|
|
event.register(CapabilityMinecartController.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|