Create/src/main/java/com/simibubi/create/events/CommonEvents.java

252 lines
9.4 KiB
Java
Raw Normal View History

package com.simibubi.create.events;
import com.simibubi.create.AllFluids;
import com.simibubi.create.Create;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler;
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls.ControlsServerHandler;
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;
import com.simibubi.create.content.curiosities.toolbox.ToolboxHandler;
import com.simibubi.create.content.curiosities.weapons.PotatoProjectileTypeManager;
import com.simibubi.create.content.curiosities.zapper.ZapperInteractionHandler;
import com.simibubi.create.content.curiosities.zapper.ZapperItem;
import com.simibubi.create.content.logistics.item.LinkedControllerServerHandler;
2022-02-01 01:14:21 +01:00
import com.simibubi.create.content.logistics.trains.entity.CarriageEntityHandler;
import com.simibubi.create.foundation.ModFilePackResources;
import com.simibubi.create.foundation.command.AllCommands;
import com.simibubi.create.foundation.fluid.FluidHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.foundation.utility.WorldAttached;
import com.simibubi.create.foundation.utility.recipe.RecipeFinder;
import com.simibubi.create.foundation.worldgen.AllWorldFeatures;
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.server.packs.PackType;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackSource;
2021-11-02 06:18:30 +01:00
import net.minecraft.tags.FluidTags;
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;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.event.AddPackFindersEvent;
2020-10-20 19:37:30 +02:00
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.OnDatapackSyncEvent;
Merge branch 'mc1.15/dev' into mc1.16/dev # Conflicts: # src/generated/resources/.cache/cache # src/generated/resources/assets/create/blockstates/andesite_funnel.json # src/generated/resources/assets/create/blockstates/brass_funnel.json # src/generated/resources/assets/create/lang/unfinished/de_de.json # src/generated/resources/assets/create/lang/unfinished/es_es.json # src/generated/resources/assets/create/lang/unfinished/fr_fr.json # src/generated/resources/assets/create/lang/unfinished/it_it.json # src/generated/resources/assets/create/lang/unfinished/ja_jp.json # src/generated/resources/assets/create/lang/unfinished/ko_kr.json # src/generated/resources/assets/create/lang/unfinished/nl_nl.json # src/generated/resources/assets/create/lang/unfinished/pt_br.json # src/main/java/com/simibubi/create/AllBlocks.java # src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java # src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java # src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticle.java # src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java # src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelFilterSlotPositioning.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java # src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java # src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java # src/main/java/com/simibubi/create/events/ClientEvents.java # src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java # src/main/java/com/simibubi/create/foundation/collision/CollisionDebugger.java # src/main/java/com/simibubi/create/foundation/collision/OBBCollider.java # src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java # src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java # src/main/java/com/simibubi/create/foundation/gui/AllIcons.java # src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java # src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java # src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java # src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java # src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java # src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java # src/main/java/com/simibubi/create/foundation/render/backend/Backend.java # src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java # src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java # src/main/java/com/simibubi/create/foundation/utility/ColorHelper.java # src/main/java/com/simibubi/create/foundation/utility/Lang.java # src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java # src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java # src/main/java/com/simibubi/create/foundation/utility/VecHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/util/PoleHelper.java
2021-03-20 12:58:02 +01:00
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.TickEvent.WorldTickEvent;
2022-02-01 01:14:21 +01:00
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.event.world.BiomeLoadingEvent;
2021-11-12 08:15:42 +01:00
import net.minecraftforge.event.world.BlockEvent.FluidPlaceBlockEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.forgespi.language.IModFileInfo;
import net.minecraftforge.forgespi.locating.IModFile;
@EventBusSubscriber
2020-05-23 14:02:38 +02:00
public class CommonEvents {
@SubscribeEvent
public static void onServerTick(ServerTickEvent event) {
if (event.phase == Phase.START)
return;
Create.SCHEMATIC_RECEIVER.tick();
Create.LAGGER.tick();
ServerSpeedProvider.serverTick();
Create.RAILWAYS.sync.serverTick();
}
@SubscribeEvent
public static void onChunkUnloaded(ChunkEvent.Unload event) {
CapabilityMinecartController.onChunkUnloaded(event);
}
@SubscribeEvent
public static void playerLoggedIn(PlayerLoggedInEvent event) {
Player player = event.getPlayer();
ToolboxHandler.playerLogin(player);
2022-02-01 01:14:21 +01:00
Create.RAILWAYS.playerLogin(player);
}
@SubscribeEvent
public static void playerLoggedOut(PlayerLoggedOutEvent event) {
Player player = event.getPlayer();
Create.RAILWAYS.playerLogout(player);
}
@SubscribeEvent
public static void whenFluidsMeet(FluidPlaceBlockEvent event) {
BlockState blockState = event.getOriginalState();
2020-12-05 11:42:14 +01:00
FluidState fluidState = blockState.getFluidState();
BlockPos pos = event.getPos();
LevelAccessor world = event.getWorld();
2021-07-15 11:32:03 +02:00
if (fluidState.isSource() && FluidHelper.isLava(fluidState.getType()))
return;
for (Direction direction : Iterate.directions) {
FluidState metFluidState =
fluidState.isSource() ? fluidState : world.getFluidState(pos.relative(direction));
2021-07-15 11:32:03 +02:00
if (!metFluidState.is(FluidTags.WATER))
continue;
BlockState lavaInteraction = AllFluids.getLavaInteraction(metFluidState);
if (lavaInteraction == null)
continue;
event.setNewState(lavaInteraction);
break;
}
}
@SubscribeEvent
public static void onWorldTick(WorldTickEvent event) {
if (event.phase == Phase.START)
return;
Level world = event.world;
ContraptionHandler.tick(world);
CapabilityMinecartController.tick(world);
CouplingPhysics.tick(world);
LinkedControllerServerHandler.tick(world);
ControlsServerHandler.tick(world);
2022-02-01 01:14:21 +01:00
Create.RAILWAYS.tick(world);
}
@SubscribeEvent
public static void onUpdateLivingEntity(LivingUpdateEvent event) {
LivingEntity entityLiving = event.getEntityLiving();
Level world = entityLiving.level;
if (world == null)
return;
ContraptionHandler.entitiesWhoJustDismountedGetSentToTheRightLocation(entityLiving, world);
ToolboxHandler.entityTick(entityLiving, world);
}
@SubscribeEvent
public static void onEntityAdded(EntityJoinWorldEvent event) {
Entity entity = event.getEntity();
Level world = event.getWorld();
ContraptionHandler.addSpawnedContraptionsToCollisionList(entity, world);
}
@SubscribeEvent
public static void onEntityAttackedByPlayer(AttackEntityEvent event) {
WrenchItem.wrenchInstaKillsMinecarts(event);
}
@SubscribeEvent
Merge branch 'mc1.15/dev' into mc1.16/dev # Conflicts: # src/generated/resources/.cache/cache # src/generated/resources/assets/create/blockstates/andesite_funnel.json # src/generated/resources/assets/create/blockstates/brass_funnel.json # src/generated/resources/assets/create/lang/unfinished/de_de.json # src/generated/resources/assets/create/lang/unfinished/es_es.json # src/generated/resources/assets/create/lang/unfinished/fr_fr.json # src/generated/resources/assets/create/lang/unfinished/it_it.json # src/generated/resources/assets/create/lang/unfinished/ja_jp.json # src/generated/resources/assets/create/lang/unfinished/ko_kr.json # src/generated/resources/assets/create/lang/unfinished/nl_nl.json # src/generated/resources/assets/create/lang/unfinished/pt_br.json # src/main/java/com/simibubi/create/AllBlocks.java # src/main/java/com/simibubi/create/compat/jei/category/CreateRecipeCategory.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/ContraptionActorData.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/LinearChassisBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java # src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java # src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java # src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java # src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticle.java # src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java # src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItem.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelFilterSlotPositioning.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java # src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java # src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPoint.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AbstractFilterScreen.java # src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java # src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java # src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java # src/main/java/com/simibubi/create/events/ClientEvents.java # src/main/java/com/simibubi/create/foundation/block/connected/ConnectedTextureBehaviour.java # src/main/java/com/simibubi/create/foundation/collision/CollisionDebugger.java # src/main/java/com/simibubi/create/foundation/collision/OBBCollider.java # src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java # src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java # src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java # src/main/java/com/simibubi/create/foundation/gui/AllIcons.java # src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java # src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java # src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java # src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java # src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java # src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java # src/main/java/com/simibubi/create/foundation/render/backend/Backend.java # src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java # src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java # src/main/java/com/simibubi/create/foundation/utility/ColorHelper.java # src/main/java/com/simibubi/create/foundation/utility/Lang.java # src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java # src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java # src/main/java/com/simibubi/create/foundation/utility/VecHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java # src/main/java/com/simibubi/create/foundation/utility/placement/util/PoleHelper.java
2021-03-20 12:58:02 +01:00
public static void registerCommands(RegisterCommandsEvent event) {
AllCommands.register(event.getDispatcher());
}
2022-02-01 01:14:21 +01:00
@SubscribeEvent
public static void onEntityEnterSection(EntityEvent.EnteringSection event) {
CarriageEntityHandler.onEntityEnterSection(event);
}
@SubscribeEvent
public static void addReloadListeners(AddReloadListenerEvent event) {
2020-10-20 19:37:30 +02:00
event.addListener(RecipeFinder.LISTENER);
event.addListener(PotatoProjectileTypeManager.ReloadListener.INSTANCE);
}
@SubscribeEvent
public static void onDatapackSync(OnDatapackSyncEvent event) {
ServerPlayer player = event.getPlayer();
if (player != null) {
PotatoProjectileTypeManager.syncTo(player);
} else {
PotatoProjectileTypeManager.syncToAll();
}
}
@SubscribeEvent
public static void serverStopping(ServerStoppingEvent event) {
Create.SCHEMATIC_RECEIVER.shutdown();
}
@SubscribeEvent
public static void onLoadWorld(WorldEvent.Load event) {
LevelAccessor world = event.getWorld();
Create.REDSTONE_LINK_NETWORK_HANDLER.onLoadWorld(world);
Create.TORQUE_PROPAGATOR.onLoadWorld(world);
2022-02-01 01:14:21 +01:00
Create.RAILWAYS.levelLoaded(world);
}
@SubscribeEvent
public static void onUnloadWorld(WorldEvent.Unload event) {
LevelAccessor world = event.getWorld();
Create.REDSTONE_LINK_NETWORK_HANDLER.onUnloadWorld(world);
Create.TORQUE_PROPAGATOR.onUnloadWorld(world);
WorldAttached.invalidateWorld(world);
}
@SubscribeEvent
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {
CapabilityMinecartController.attach(event);
}
@SubscribeEvent
public static void startTracking(PlayerEvent.StartTracking event) {
CapabilityMinecartController.startTracking(event);
}
@SubscribeEvent(priority = EventPriority.HIGH)
public static void onBiomeLoad(BiomeLoadingEvent event) {
AllWorldFeatures.reload(event);
}
public static void leftClickEmpty(ServerPlayer player) {
2021-07-15 11:32:03 +02:00
ItemStack stack = player.getMainHandItem();
if (stack.getItem() instanceof ZapperItem) {
ZapperInteractionHandler.trySelect(stack, player);
}
}
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
public static class ModBusEvents {
@SubscribeEvent
public static void registerCapabilities(RegisterCapabilitiesEvent event) {
event.register(CapabilityMinecartController.class);
}
@SubscribeEvent
public static void addPackFinders(AddPackFindersEvent event) {
if (event.getPackType() == PackType.CLIENT_RESOURCES) {
IModFileInfo modFileInfo = ModList.get().getModFileById(Create.ID);
if (modFileInfo == null) {
Create.LOGGER.error("Could not find Create mod file info; built-in resource packs will be missing!");
return;
}
IModFile modFile = modFileInfo.getFile();
event.addRepositorySource((consumer, constructor) -> {
consumer.accept(Pack.create(Create.asResource("legacy_copper").toString(), false, () -> new ModFilePackResources("Create Legacy Copper", modFile, "resourcepacks/legacy_copper"), constructor, Pack.Position.TOP, PackSource.DEFAULT));
});
}
}
}
}