1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Even more proxy pruning

- Move the "world directory" getter out of the proxy - we can just use
   Forge's code here.
 - Remove the server proxies, as both were empty. We don't tend to
   register any dedicated-server specific code, so I think we can leave
   them out.
This commit is contained in:
SquidDev 2019-01-12 18:20:16 +00:00
parent 63691707fc
commit 1c648850ab
9 changed files with 37 additions and 64 deletions

View File

@ -71,6 +71,7 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
@ -236,11 +237,17 @@ public class ComputerCraft
@Mod.Instance( value = ComputerCraft.MOD_ID )
public static ComputerCraft instance;
@SidedProxy( clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient", serverSide = "dan200.computercraft.server.proxy.ComputerCraftProxyServer" )
public static IComputerCraftProxy proxy;
@SidedProxy(
clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
)
private static IComputerCraftProxy proxy;
@SidedProxy( clientSide = "dan200.computercraft.client.proxy.CCTurtleProxyClient", serverSide = "dan200.computercraft.server.proxy.CCTurtleProxyServer" )
public static ICCTurtleProxy turtleProxy;
@SidedProxy(
clientSide = "dan200.computercraft.client.proxy.CCTurtleProxyClient",
serverSide = "dan200.computercraft.shared.proxy.CCTurtleProxyCommon"
)
private static ICCTurtleProxy turtleProxy;
@Mod.EventHandler
public void preInit( FMLPreInitializationEvent event )
@ -359,11 +366,6 @@ public class ComputerCraft
return new File( getBaseDir(), "resourcepacks" );
}
public static File getWorldDir( World world )
{
return proxy.getWorldDir( world );
}
public static void sendToPlayer( EntityPlayer player, IMessage packet )
{
networkWrapper.sendTo( packet, (EntityPlayerMP) player );
@ -460,7 +462,7 @@ public class ComputerCraft
@Deprecated
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
{
return IDAssigner.getNextIDFromDirectory( new File( getWorldDir( world ), parentSubPath ) );
return IDAssigner.getNextIDFromDirectory( parentSubPath );
}
@Deprecated
@ -468,7 +470,7 @@ public class ComputerCraft
{
try
{
return new FileMount( new File( getWorldDir( world ), subPath ), capacity );
return new FileMount( new File( getWorldDir(), subPath ), capacity );
}
catch( Exception e )
{
@ -688,7 +690,18 @@ public class ComputerCraft
dan200.computercraft.shared.TurtleUpgrades.register( upgrade );
}
public static File getWorldDir()
{
return DimensionManager.getCurrentSaveRootDirectory();
}
//region Compatibility
@Deprecated
public static File getWorldDir( World world )
{
return DimensionManager.getCurrentSaveRootDirectory();
}
@Deprecated
public static IMedia getMedia( ItemStack stack )
{

View File

@ -83,12 +83,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
}
@Override
public File getWorldDir( World world )
{
return world.getSaveHandler().getWorldDirectory();
}
@Override
public void playRecordClient( BlockPos pos, SoundEvent record, String info )
{

View File

@ -1,13 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.server.proxy;
import dan200.computercraft.shared.proxy.CCTurtleProxyCommon;
public class CCTurtleProxyServer extends CCTurtleProxyCommon
{
}

View File

@ -1,22 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.server.proxy;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import java.io.File;
public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
{
@Override
public File getWorldDir( World world )
{
return DimensionManager.getWorld( 0 ).getSaveHandler().getWorldDirectory();
}
}

View File

@ -19,7 +19,6 @@ import net.minecraftforge.common.util.Constants;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Collections;
import java.util.Map;
@ -66,10 +65,7 @@ public final class WiredModemLocalPeripheral
else if( id < 0 || !type.equals( this.type ) )
{
this.type = type;
this.id = IDAssigner.getNextIDFromFile( new File(
ComputerCraft.getWorldDir( world ),
"computer/lastid_" + type + ".txt"
) );
this.id = IDAssigner.getNextIDFromFile( "computer/lastid_" + type + ".txt" );
}
return oldPeripheral == null || !oldPeripheral.equals( peripheral );

View File

@ -11,7 +11,7 @@ import dan200.computercraft.shared.turtle.core.TurtlePlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.EntityRegistry;
public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
public class CCTurtleProxyCommon implements ICCTurtleProxy
{
@Override
public void preInit()

View File

@ -63,7 +63,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import pl.asie.charset.ModCharset;
public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
public class ComputerCraftProxyCommon implements IComputerCraftProxy
{
@Override
public void preInit()

View File

@ -10,9 +10,6 @@ import dan200.computercraft.shared.command.text.TableBuilder;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.io.File;
public interface IComputerCraftProxy
{
@ -22,8 +19,6 @@ public interface IComputerCraftProxy
void initServer( MinecraftServer server );
File getWorldDir( World world );
default void playRecordClient( BlockPos pos, SoundEvent record, String info )
{
}

View File

@ -17,6 +17,16 @@ public class IDAssigner
{
}
public static int getNextIDFromDirectory( String path )
{
return getNextIDFromDirectory( new File( ComputerCraft.getWorldDir(), path ) );
}
public static int getNextIDFromFile( String path )
{
return getNextIDFromFile( new File( ComputerCraft.getWorldDir(), path ) );
}
public static int getNextIDFromDirectory( File dir )
{
return getNextID( dir, true );