1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-05 03:47:56 +00:00

Separate custom client and server events.

This commit is contained in:
Toad-Dev
2021-12-26 13:53:46 -08:00
parent 7a50bf3979
commit 654c7571c1
7 changed files with 44 additions and 30 deletions

View File

@@ -15,7 +15,7 @@ import dan200.computercraft.client.render.TileEntityTurtleRenderer;
import dan200.computercraft.client.render.TurtleModelLoader; import dan200.computercraft.client.render.TurtleModelLoader;
import dan200.computercraft.client.render.TurtlePlayerRenderer; import dan200.computercraft.client.render.TurtlePlayerRenderer;
import dan200.computercraft.client.sound.SpeakerManager; import dan200.computercraft.client.sound.SpeakerManager;
import dan200.computercraft.fabric.events.ComputerCraftCustomEvents; import dan200.computercraft.fabric.events.CustomClientEvents;
import dan200.computercraft.shared.Registry; import dan200.computercraft.shared.Registry;
import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.common.ContainerHeldItem;
import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.common.IColouredItem;
@@ -70,12 +70,12 @@ public final class ComputerCraftProxyClient implements ClientModInitializer
ServerTickEvents.START_SERVER_TICK.register( server -> PauseAwareTimer.tick() ); ServerTickEvents.START_SERVER_TICK.register( server -> PauseAwareTimer.tick() );
ComputerCraftCustomEvents.CLIENT_UNLOAD_WORLD_EVENT.register( () -> { CustomClientEvents.CLIENT_UNLOAD_WORLD_EVENT.register( () -> {
SpeakerManager.reset(); SpeakerManager.reset();
ClientMonitor.destroyAll(); ClientMonitor.destroyAll();
} ); } );
ComputerCraftCustomEvents.PLAY_STREAMING_AUDIO_EVENT.register( SpeakerManager::playStreaming ); CustomClientEvents.PLAY_STREAMING_AUDIO_EVENT.register( SpeakerManager::playStreaming );
// Config // Config
ClientLifecycleEvents.CLIENT_STARTED.register( Config::clientStarted ); ClientLifecycleEvents.CLIENT_STARTED.register( Config::clientStarted );

View File

@@ -10,10 +10,8 @@ import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.resources.sounds.SoundInstance; import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.SoundEngine; import net.minecraft.client.sounds.SoundEngine;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.ChunkPos;
public final class ComputerCraftCustomEvents public class CustomClientEvents
{ {
public static final Event<ClientUnloadWorld> CLIENT_UNLOAD_WORLD_EVENT = EventFactory.createArrayBacked( ClientUnloadWorld.class, public static final Event<ClientUnloadWorld> CLIENT_UNLOAD_WORLD_EVENT = EventFactory.createArrayBacked( ClientUnloadWorld.class,
callbacks -> () -> { callbacks -> () -> {
@@ -23,14 +21,6 @@ public final class ComputerCraftCustomEvents
} }
} ); } );
public static final Event<ServerPlayerLoadedChunk> SERVER_PLAYER_LOADED_CHUNK_EVENT = EventFactory.createArrayBacked( ServerPlayerLoadedChunk.class,
callbacks -> ( serverPlayer, chunkPos ) -> {
for( ServerPlayerLoadedChunk callback : callbacks )
{
callback.onServerPlayerLoadedChunk( serverPlayer, chunkPos );
}
} );
public static final Event<PlayStreamingAudio> PLAY_STREAMING_AUDIO_EVENT = EventFactory.createArrayBacked( PlayStreamingAudio.class, public static final Event<PlayStreamingAudio> PLAY_STREAMING_AUDIO_EVENT = EventFactory.createArrayBacked( PlayStreamingAudio.class,
callbacks -> ( engine, soundInstance, channel ) -> { callbacks -> ( engine, soundInstance, channel ) -> {
for( PlayStreamingAudio callback : callbacks ) for( PlayStreamingAudio callback : callbacks )
@@ -46,12 +36,6 @@ public final class ComputerCraftCustomEvents
void onClientUnloadWorld(); void onClientUnloadWorld();
} }
@FunctionalInterface
public interface ServerPlayerLoadedChunk
{
void onServerPlayerLoadedChunk( ServerPlayer player, ChunkPos chunkPos );
}
@FunctionalInterface @FunctionalInterface
public interface PlayStreamingAudio public interface PlayStreamingAudio
{ {

View File

@@ -0,0 +1,30 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.fabric.events;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.ChunkPos;
public final class CustomServerEvents
{
public static final Event<ServerPlayerLoadedChunk> SERVER_PLAYER_LOADED_CHUNK_EVENT = EventFactory.createArrayBacked( ServerPlayerLoadedChunk.class,
callbacks -> ( serverPlayer, chunkPos ) -> {
for( ServerPlayerLoadedChunk callback : callbacks )
{
callback.onServerPlayerLoadedChunk( serverPlayer, chunkPos );
}
} );
@FunctionalInterface
public interface ServerPlayerLoadedChunk
{
void onServerPlayerLoadedChunk( ServerPlayer player, ChunkPos chunkPos );
}
}

View File

@@ -5,7 +5,7 @@
*/ */
package dan200.computercraft.fabric.mixin; package dan200.computercraft.fabric.mixin;
import dan200.computercraft.fabric.events.ComputerCraftCustomEvents; import dan200.computercraft.fabric.events.CustomServerEvents;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@@ -38,7 +38,7 @@ public class MixinChunkMap
// { // {
// if( serverPlayer.level == this.level && bl ) // if( serverPlayer.level == this.level && bl )
// { // {
// ComputerCraftCustomEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.invoker().onServerPlayerLoadedChunk( serverPlayer, chunkPos ); // CustomServerEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.invoker().onServerPlayerLoadedChunk( serverPlayer, chunkPos );
// } // }
// } // }
@@ -46,7 +46,7 @@ public class MixinChunkMap
@Inject( method = "playerLoadedChunk", at = @At( value = "HEAD" ) ) @Inject( method = "playerLoadedChunk", at = @At( value = "HEAD" ) )
private void playerLoadedChunk( ServerPlayer serverPlayer, MutableObject<ClientboundLevelChunkWithLightPacket> mutableObject, LevelChunk levelChunk, CallbackInfo ci ) private void playerLoadedChunk( ServerPlayer serverPlayer, MutableObject<ClientboundLevelChunkWithLightPacket> mutableObject, LevelChunk levelChunk, CallbackInfo ci )
{ {
ComputerCraftCustomEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.invoker().onServerPlayerLoadedChunk( serverPlayer, levelChunk.getPos() ); CustomServerEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.invoker().onServerPlayerLoadedChunk( serverPlayer, levelChunk.getPos() );
} }
} }

View File

@@ -6,7 +6,7 @@
package dan200.computercraft.fabric.mixin; package dan200.computercraft.fabric.mixin;
import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.FrameInfo;
import dan200.computercraft.fabric.events.ComputerCraftCustomEvents; import dan200.computercraft.fabric.events.CustomClientEvents;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
@@ -27,12 +27,12 @@ public abstract class MixinMinecraft
@Inject( method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At( "RETURN" ) ) @Inject( method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At( "RETURN" ) )
private void disconnectAfter( Screen screen, CallbackInfo info ) private void disconnectAfter( Screen screen, CallbackInfo info )
{ {
ComputerCraftCustomEvents.CLIENT_UNLOAD_WORLD_EVENT.invoker().onClientUnloadWorld(); CustomClientEvents.CLIENT_UNLOAD_WORLD_EVENT.invoker().onClientUnloadWorld();
} }
@Inject( method = "setLevel", at = @At( "RETURN" ) ) @Inject( method = "setLevel", at = @At( "RETURN" ) )
private void setLevel( ClientLevel world, CallbackInfo info ) private void setLevel( ClientLevel world, CallbackInfo info )
{ {
ComputerCraftCustomEvents.CLIENT_UNLOAD_WORLD_EVENT.invoker().onClientUnloadWorld(); CustomClientEvents.CLIENT_UNLOAD_WORLD_EVENT.invoker().onClientUnloadWorld();
} }
} }

View File

@@ -6,7 +6,7 @@
package dan200.computercraft.fabric.mixin; package dan200.computercraft.fabric.mixin;
import com.mojang.blaze3d.audio.Channel; import com.mojang.blaze3d.audio.Channel;
import dan200.computercraft.fabric.events.ComputerCraftCustomEvents; import dan200.computercraft.fabric.events.CustomClientEvents;
import net.minecraft.client.resources.sounds.SoundInstance; import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.AudioStream; import net.minecraft.client.sounds.AudioStream;
import net.minecraft.client.sounds.SoundEngine; import net.minecraft.client.sounds.SoundEngine;
@@ -31,7 +31,7 @@ public class MixinSoundEngine
) )
private static void onStreamingSourcePlay( AudioStream audioStream, Channel channel, CallbackInfo ci ) private static void onStreamingSourcePlay( AudioStream audioStream, Channel channel, CallbackInfo ci )
{ {
if( ComputerCraftCustomEvents.PLAY_STREAMING_AUDIO_EVENT.invoker().onPlayStreamingAudio( thisCapture, soundInstanceCapture, channel ) ) if( CustomClientEvents.PLAY_STREAMING_AUDIO_EVENT.invoker().onPlayStreamingAudio( thisCapture, soundInstanceCapture, channel ) )
{ {
ci.cancel(); ci.cancel();
} }

View File

@@ -6,7 +6,7 @@
package dan200.computercraft.shared.peripheral.monitor; package dan200.computercraft.shared.peripheral.monitor;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.fabric.events.ComputerCraftCustomEvents; import dan200.computercraft.fabric.events.CustomServerEvents;
import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.client.MonitorClientMessage; import dan200.computercraft.shared.network.client.MonitorClientMessage;
import dan200.computercraft.shared.network.client.TerminalState; import dan200.computercraft.shared.network.client.TerminalState;
@@ -36,7 +36,7 @@ public final class MonitorWatcher
public static void init() public static void init()
{ {
ServerTickEvents.END_SERVER_TICK.register( MonitorWatcher::onTick ); ServerTickEvents.END_SERVER_TICK.register( MonitorWatcher::onTick );
ComputerCraftCustomEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.register( MonitorWatcher::onWatch ); CustomServerEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.register( MonitorWatcher::onWatch );
} }
static void enqueue( TileMonitor monitor ) static void enqueue( TileMonitor monitor )