mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-09 18:03:08 +00:00
Move our message model to be closer to Forge's
It's rather embarassing that it's been restructured _again_, but I think this is a nice middle-ground. The previous implementation was written mostly for Fabric, which doesn't always map perfectly to Forge. - Move the message identifier into the registration phrase. It's not really a property of the message itself, rather a property of the registry, so better suited there. - Move message handling into the message itself. Honestly, it was just ending up being rather messy mixing the logic in two places. This also means we can drop some proxy methods, as it's easier to have conditionally loaded methods. - Move network registry into a dedicated class, as that's what we're doing for everything else.
This commit is contained in:
@@ -43,6 +43,7 @@ import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.common.ItemPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
@@ -70,7 +71,6 @@ import dan200.computercraft.shared.util.IoUtil;
|
||||
import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
||||
import dan200.computercraft.shared.wired.WiredNode;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -85,9 +85,6 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.*;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -242,9 +239,6 @@ public class ComputerCraft
|
||||
public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
|
||||
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
||||
|
||||
// Networking
|
||||
public static SimpleNetworkWrapper networkWrapper;
|
||||
|
||||
// Creative
|
||||
public static CreativeTabMain mainCreativeTab;
|
||||
|
||||
@@ -279,7 +273,7 @@ public class ComputerCraft
|
||||
Config.load( event.getSuggestedConfigurationFile() );
|
||||
|
||||
// Setup network
|
||||
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel( ComputerCraft.MOD_ID );
|
||||
NetworkHandler.setup();
|
||||
|
||||
proxy.preInit();
|
||||
turtleProxy.preInit();
|
||||
@@ -387,26 +381,6 @@ public class ComputerCraft
|
||||
return new File( getBaseDir(), "resourcepacks" );
|
||||
}
|
||||
|
||||
public static void sendToPlayer( EntityPlayer player, IMessage packet )
|
||||
{
|
||||
networkWrapper.sendTo( packet, (EntityPlayerMP) player );
|
||||
}
|
||||
|
||||
public static void sendToAllPlayers( IMessage packet )
|
||||
{
|
||||
networkWrapper.sendToAll( packet );
|
||||
}
|
||||
|
||||
public static void sendToServer( IMessage packet )
|
||||
{
|
||||
networkWrapper.sendToServer( packet );
|
||||
}
|
||||
|
||||
public static void sendToAllAround( IMessage packet, NetworkRegistry.TargetPoint point )
|
||||
{
|
||||
networkWrapper.sendToAllAround( packet, point );
|
||||
}
|
||||
|
||||
public static boolean canPlayerUseCommands( EntityPlayer player )
|
||||
{
|
||||
MinecraftServer server = player.getServer();
|
||||
|
||||
Reference in New Issue
Block a user