2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2019-01-01 01:10:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
2017-05-01 21:13:25 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
package dan200.computercraft;
|
|
|
|
|
|
|
|
import dan200.computercraft.api.filesystem.IMount;
|
|
|
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
2017-11-18 13:40:38 +00:00
|
|
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.media.IMedia;
|
|
|
|
import dan200.computercraft.api.media.IMediaProvider;
|
2017-05-06 20:19:55 +00:00
|
|
|
import dan200.computercraft.api.network.IPacketNetwork;
|
2018-02-21 15:29:34 +00:00
|
|
|
import dan200.computercraft.api.network.wired.IWiredElement;
|
|
|
|
import dan200.computercraft.api.network.wired.IWiredNode;
|
2019-01-02 17:37:16 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
|
|
|
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
|
2017-05-02 00:46:17 +00:00
|
|
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
2018-02-16 10:37:47 +00:00
|
|
|
import dan200.computercraft.api.turtle.event.TurtleAction;
|
2017-06-11 20:40:08 +00:00
|
|
|
import dan200.computercraft.core.apis.AddressPredicate;
|
2018-12-10 23:46:50 +00:00
|
|
|
import dan200.computercraft.core.apis.ApiFactories;
|
2019-01-11 11:33:05 +00:00
|
|
|
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
2019-03-19 12:24:36 +00:00
|
|
|
import dan200.computercraft.core.computer.MainThread;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.core.filesystem.ComboMount;
|
|
|
|
import dan200.computercraft.core.filesystem.FileMount;
|
2019-01-16 17:25:46 +00:00
|
|
|
import dan200.computercraft.core.filesystem.JarMount;
|
2018-04-17 08:22:26 +00:00
|
|
|
import dan200.computercraft.core.tracking.Tracking;
|
2018-12-10 23:46:50 +00:00
|
|
|
import dan200.computercraft.shared.*;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
|
|
|
|
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
|
|
|
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
|
|
|
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
2019-01-12 19:01:32 +00:00
|
|
|
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
|
|
|
import dan200.computercraft.shared.computer.items.ItemComputer;
|
2017-05-01 13:32:39 +00:00
|
|
|
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.peripheral.common.BlockPeripheral;
|
2019-01-12 19:01:32 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.common.ItemPeripheral;
|
2018-12-27 11:32:29 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
|
|
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
2019-01-12 19:01:32 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.modem.wired.ItemCable;
|
2018-12-27 10:10:44 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem;
|
2019-01-12 19:01:32 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.modem.wireless.ItemAdvancedModem;
|
2018-12-27 10:10:44 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
2017-05-02 00:46:17 +00:00
|
|
|
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
2017-05-12 18:57:48 +00:00
|
|
|
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.proxy.IComputerCraftProxy;
|
|
|
|
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
2019-01-12 19:01:32 +00:00
|
|
|
import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced;
|
|
|
|
import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy;
|
|
|
|
import dan200.computercraft.shared.turtle.items.ItemTurtleNormal;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.turtle.upgrades.*;
|
2018-11-16 12:29:29 +00:00
|
|
|
import dan200.computercraft.shared.util.CreativeTabMain;
|
|
|
|
import dan200.computercraft.shared.util.IDAssigner;
|
2019-01-11 11:33:05 +00:00
|
|
|
import dan200.computercraft.shared.util.IoUtil;
|
2018-03-24 11:57:36 +00:00
|
|
|
import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
2018-02-21 15:29:34 +00:00
|
|
|
import dan200.computercraft.shared.wired.WiredNode;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2019-01-12 19:01:32 +00:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
2018-03-24 11:57:36 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2017-05-01 14:39:03 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-05-01 13:51:26 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-02-21 15:29:34 +00:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.world.World;
|
2019-01-12 18:20:16 +00:00
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2017-05-01 13:32:39 +00:00
|
|
|
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.relauncher.Side;
|
2017-05-13 21:26:35 +00:00
|
|
|
import org.apache.logging.log4j.Logger;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-07-14 20:50:51 +00:00
|
|
|
import java.io.*;
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.URL;
|
2018-12-10 23:46:50 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2019-03-21 13:31:58 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2017-07-14 20:50:51 +00:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipFile;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 21:13:25 +00:00
|
|
|
@Mod(
|
2017-11-15 16:25:10 +00:00
|
|
|
modid = ComputerCraft.MOD_ID, name = "CC: Tweaked", version = "${version}",
|
2018-11-21 18:11:14 +00:00
|
|
|
guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory",
|
|
|
|
dependencies = "required:forge@[14.23.4.2746,)"
|
2017-05-01 21:13:25 +00:00
|
|
|
)
|
2017-05-01 13:32:39 +00:00
|
|
|
public class ComputerCraft
|
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
public static final String MOD_ID = "computercraft";
|
2017-05-07 00:42:32 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Configuration options
|
2019-01-05 20:12:02 +00:00
|
|
|
public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
|
|
|
|
public static final String[] DEFAULT_HTTP_BLACKLIST = new String[] {
|
2017-06-28 21:33:20 +00:00
|
|
|
"127.0.0.0/8",
|
|
|
|
"10.0.0.0/8",
|
|
|
|
"172.16.0.0/12",
|
|
|
|
"192.168.0.0/16",
|
|
|
|
"fd00::/8",
|
|
|
|
};
|
2017-11-15 11:57:52 +00:00
|
|
|
|
2019-01-05 20:12:02 +00:00
|
|
|
public static int computerSpaceLimit = 1000 * 1000;
|
|
|
|
public static int floppySpaceLimit = 125 * 1000;
|
|
|
|
public static int maximumFilesOpen = 128;
|
2017-05-01 13:32:39 +00:00
|
|
|
public static boolean disable_lua51_features = false;
|
|
|
|
public static String default_computer_settings = "";
|
2019-01-05 20:12:02 +00:00
|
|
|
public static boolean debug_enable = true;
|
2017-05-16 18:35:07 +00:00
|
|
|
public static boolean logPeripheralErrors = false;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-03-21 13:31:58 +00:00
|
|
|
public static int computer_threads = 1;
|
|
|
|
public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
|
|
|
|
public static long maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( 5 );
|
|
|
|
|
2019-01-05 20:12:02 +00:00
|
|
|
public static boolean http_enable = true;
|
|
|
|
public static boolean http_websocket_enable = true;
|
|
|
|
public static AddressPredicate http_whitelist = new AddressPredicate( DEFAULT_HTTP_WHITELIST );
|
|
|
|
public static AddressPredicate http_blacklist = new AddressPredicate( DEFAULT_HTTP_BLACKLIST );
|
|
|
|
|
2019-01-11 21:11:22 +00:00
|
|
|
public static int httpTimeout = 30000;
|
2019-01-11 11:33:05 +00:00
|
|
|
public static int httpMaxRequests = 16;
|
|
|
|
public static long httpMaxDownload = 16 * 1024 * 1024;
|
|
|
|
public static long httpMaxUpload = 4 * 1024 * 1024;
|
|
|
|
public static int httpMaxWebsockets = 4;
|
|
|
|
public static int httpMaxWebsocketMessage = Websocket.MAX_MESSAGE_SIZE;
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public static boolean enableCommandBlock = false;
|
2019-01-05 20:12:02 +00:00
|
|
|
public static int modem_range = 64;
|
|
|
|
public static int modem_highAltitudeRange = 384;
|
|
|
|
public static int modem_rangeDuringStorm = 64;
|
|
|
|
public static int modem_highAltitudeRangeDuringStorm = 384;
|
|
|
|
public static int maxNotesPerTick = 8;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public static boolean turtlesNeedFuel = true;
|
|
|
|
public static int turtleFuelLimit = 20000;
|
|
|
|
public static int advancedTurtleFuelLimit = 100000;
|
|
|
|
public static boolean turtlesObeyBlockProtection = true;
|
|
|
|
public static boolean turtlesCanPush = true;
|
2018-02-16 10:37:47 +00:00
|
|
|
public static EnumSet<TurtleAction> turtleDisabledActions = EnumSet.noneOf( TurtleAction.class );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
public static final int terminalWidth_computer = 51;
|
2017-05-01 14:48:44 +00:00
|
|
|
public static final int terminalHeight_computer = 19;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
public static final int terminalWidth_turtle = 39;
|
|
|
|
public static final int terminalHeight_turtle = 13;
|
|
|
|
|
|
|
|
public static final int terminalWidth_pocketComputer = 26;
|
|
|
|
public static final int terminalHeight_pocketComputer = 20;
|
|
|
|
|
|
|
|
// Blocks and Items
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final class Blocks
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
public static BlockComputer computer;
|
2019-01-12 17:51:26 +00:00
|
|
|
public static BlockCommandComputer commandComputer;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public static BlockTurtle turtle;
|
|
|
|
public static BlockTurtle turtleExpanded;
|
|
|
|
public static BlockTurtle turtleAdvanced;
|
2019-01-12 17:51:26 +00:00
|
|
|
|
|
|
|
public static BlockPeripheral peripheral;
|
|
|
|
public static BlockCable cable;
|
2017-05-01 13:32:39 +00:00
|
|
|
public static BlockAdvancedModem advancedModem;
|
2018-02-21 15:40:08 +00:00
|
|
|
public static BlockWiredModemFull wiredModemFull;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final class Items
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2019-01-12 19:01:32 +00:00
|
|
|
public static ItemComputer computer;
|
|
|
|
public static ItemCommandComputer commandComputer;
|
|
|
|
|
|
|
|
public static ItemTurtleLegacy turtle;
|
|
|
|
public static ItemTurtleNormal turtleExpanded;
|
|
|
|
public static ItemTurtleAdvanced turtleAdvanced;
|
|
|
|
|
2019-01-12 17:51:26 +00:00
|
|
|
public static ItemPocketComputer pocketComputer;
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public static ItemDiskLegacy disk;
|
|
|
|
public static ItemDiskExpanded diskExpanded;
|
|
|
|
public static ItemTreasureDisk treasureDisk;
|
2019-01-12 17:51:26 +00:00
|
|
|
|
|
|
|
public static ItemPrintout printout;
|
2019-01-12 19:01:32 +00:00
|
|
|
|
|
|
|
public static ItemPeripheral peripheral;
|
|
|
|
public static ItemAdvancedModem advancedModem;
|
|
|
|
public static ItemCable cable;
|
|
|
|
public static ItemBlock wiredModemFull;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final class TurtleUpgrades
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
public static TurtleModem wirelessModem;
|
2019-01-12 17:51:26 +00:00
|
|
|
public static TurtleModem advancedModem;
|
|
|
|
public static TurtleSpeaker speaker;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public static TurtleCraftingTable craftingTable;
|
|
|
|
public static TurtleSword diamondSword;
|
|
|
|
public static TurtleShovel diamondShovel;
|
|
|
|
public static TurtleTool diamondPickaxe;
|
|
|
|
public static TurtleAxe diamondAxe;
|
|
|
|
public static TurtleHoe diamondHoe;
|
|
|
|
}
|
|
|
|
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final class PocketUpgrades
|
2017-05-02 00:46:17 +00:00
|
|
|
{
|
|
|
|
public static PocketModem wirelessModem;
|
|
|
|
public static PocketModem advancedModem;
|
2019-01-12 17:51:26 +00:00
|
|
|
public static PocketSpeaker speaker;
|
2019-01-20 16:16:02 +00:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public static PocketSpeaker pocketSpeaker;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final class Upgrades
|
2019-01-25 22:03:44 +00:00
|
|
|
{
|
2019-01-20 16:16:02 +00:00
|
|
|
public static TurtleModem advancedModem;
|
2017-05-02 00:46:17 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
// Registries
|
2019-01-12 17:51:26 +00:00
|
|
|
public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
|
|
|
|
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// Creative
|
|
|
|
public static CreativeTabMain mainCreativeTab;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-13 21:26:35 +00:00
|
|
|
// Logging
|
|
|
|
public static Logger log;
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
// Peripheral providers. This is still here to ensure compatibility with Plethora and Computronics
|
|
|
|
public static List<IPeripheralProvider> peripheralProviders = new ArrayList<>();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
// Implementation
|
2019-03-29 21:21:39 +00:00
|
|
|
@Mod.Instance( ComputerCraft.MOD_ID )
|
2017-05-01 14:48:44 +00:00
|
|
|
public static ComputerCraft instance;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2019-01-12 18:20:16 +00:00
|
|
|
@SidedProxy(
|
|
|
|
clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
|
|
|
|
serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
|
|
|
|
)
|
|
|
|
private static IComputerCraftProxy proxy;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Mod.EventHandler
|
|
|
|
public void preInit( FMLPreInitializationEvent event )
|
|
|
|
{
|
2017-05-13 21:26:35 +00:00
|
|
|
log = event.getModLog();
|
2017-05-08 18:28:50 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
// Load config
|
2019-01-05 20:12:02 +00:00
|
|
|
Config.load( event.getSuggestedConfigurationFile() );
|
2018-02-16 09:33:40 +00:00
|
|
|
|
|
|
|
proxy.preInit();
|
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Mod.EventHandler
|
|
|
|
public void init( FMLInitializationEvent event )
|
|
|
|
{
|
|
|
|
proxy.init();
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
@Mod.EventHandler
|
|
|
|
public void onServerStarting( FMLServerStartingEvent event )
|
|
|
|
{
|
2018-04-20 18:39:53 +00:00
|
|
|
proxy.initServer( event.getServer() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Mod.EventHandler
|
|
|
|
public void onServerStart( FMLServerStartedEvent event )
|
|
|
|
{
|
|
|
|
if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
|
|
|
|
{
|
|
|
|
ComputerCraft.serverComputerRegistry.reset();
|
|
|
|
WirelessNetwork.resetNetworks();
|
2019-03-19 12:24:36 +00:00
|
|
|
MainThread.reset();
|
2018-04-17 08:22:26 +00:00
|
|
|
Tracking.reset();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Mod.EventHandler
|
|
|
|
public void onServerStopped( FMLServerStoppedEvent event )
|
|
|
|
{
|
|
|
|
if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
|
|
|
|
{
|
|
|
|
ComputerCraft.serverComputerRegistry.reset();
|
|
|
|
WirelessNetwork.resetNetworks();
|
2019-03-19 12:24:36 +00:00
|
|
|
MainThread.reset();
|
2018-04-17 08:22:26 +00:00
|
|
|
Tracking.reset();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getVersion()
|
|
|
|
{
|
|
|
|
return "${version}";
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
private static File getBaseDir()
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
return FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
private static File getResourcePackDir()
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
return new File( getBaseDir(), "resourcepacks" );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public static void registerPermissionProvider( ITurtlePermissionProvider provider )
|
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
TurtlePermissions.register( provider );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-02 00:46:17 +00:00
|
|
|
public static void registerPocketUpgrade( IPocketUpgrade upgrade )
|
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
dan200.computercraft.shared.PocketUpgrades.register( upgrade );
|
2017-05-02 00:46:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public static void registerPeripheralProvider( IPeripheralProvider provider )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
Peripherals.register( provider );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public static void registerBundledRedstoneProvider( IBundledRedstoneProvider provider )
|
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
BundledRedstone.register( provider );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public static void registerMediaProvider( IMediaProvider provider )
|
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
MediaProviders.register( provider );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
|
|
|
public static void registerAPIFactory( ILuaAPIFactory factory )
|
2017-11-18 13:40:38 +00:00
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
ApiFactories.register( factory );
|
2017-11-18 13:40:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2018-02-21 15:29:34 +00:00
|
|
|
public static IWiredNode createWiredNodeForElement( IWiredElement element )
|
|
|
|
{
|
|
|
|
return new WiredNode( element );
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2018-02-21 15:29:34 +00:00
|
|
|
public static IWiredElement getWiredElementAt( IBlockAccess world, BlockPos pos, EnumFacing side )
|
|
|
|
{
|
2018-03-24 11:57:36 +00:00
|
|
|
TileEntity tile = world.getTileEntity( pos );
|
|
|
|
return tile != null && tile.hasCapability( CapabilityWiredElement.CAPABILITY, side )
|
|
|
|
? tile.getCapability( CapabilityWiredElement.CAPABILITY, side )
|
|
|
|
: null;
|
2018-02-21 15:29:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
return BundledRedstone.getDefaultOutput( world, pos, side );
|
2017-05-02 00:46:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-12-10 15:37:40 +00:00
|
|
|
public static IPacketNetwork getWirelessNetwork()
|
2017-05-06 20:19:55 +00:00
|
|
|
{
|
|
|
|
return WirelessNetwork.getUniversal();
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 14:48:44 +00:00
|
|
|
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
|
|
|
|
{
|
2019-01-12 18:20:16 +00:00
|
|
|
return IDAssigner.getNextIDFromDirectory( parentSubPath );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 14:48:44 +00:00
|
|
|
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-01-12 18:20:16 +00:00
|
|
|
return new FileMount( new File( getWorldDir(), subPath ), capacity );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
catch( Exception e )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-06 23:07:42 +00:00
|
|
|
public static IMount createResourceMount( Class<?> modClass, String domain, String subPath )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
// Start building list of mounts
|
2017-06-12 20:08:35 +00:00
|
|
|
List<IMount> mounts = new ArrayList<>();
|
2017-05-01 13:32:39 +00:00
|
|
|
subPath = "assets/" + domain + "/" + subPath;
|
|
|
|
|
|
|
|
// Mount from debug dir
|
|
|
|
File codeDir = getDebugCodeDir( modClass );
|
|
|
|
if( codeDir != null )
|
|
|
|
{
|
|
|
|
File subResource = new File( codeDir, subPath );
|
|
|
|
if( subResource.exists() )
|
|
|
|
{
|
|
|
|
IMount resourcePackMount = new FileMount( subResource, 0 );
|
|
|
|
mounts.add( resourcePackMount );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mount from mod jar
|
|
|
|
File modJar = getContainingJar( modClass );
|
|
|
|
if( modJar != null )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-01-16 17:25:46 +00:00
|
|
|
mounts.add( new JarMount( modJar, subPath ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-01-16 17:25:46 +00:00
|
|
|
catch( IOException | RuntimeException e )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-09-21 15:00:26 +00:00
|
|
|
ComputerCraft.log.error( "Could not load mount from mod jar", e );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mount from resource packs
|
|
|
|
File resourcePackDir = getResourcePackDir();
|
|
|
|
if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
|
|
|
|
{
|
|
|
|
String[] resourcePacks = resourcePackDir.list();
|
2018-10-29 15:59:43 +00:00
|
|
|
for( String resourcePackName : resourcePacks )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-10-29 15:59:43 +00:00
|
|
|
File resourcePack = new File( resourcePackDir, resourcePackName );
|
2017-05-01 13:32:39 +00:00
|
|
|
if( !resourcePack.isDirectory() )
|
|
|
|
{
|
|
|
|
// Mount a resource pack from a jar
|
2019-01-16 17:25:46 +00:00
|
|
|
mounts.add( new JarMount( resourcePack, subPath ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Mount a resource pack from a folder
|
|
|
|
File subResource = new File( resourcePack, subPath );
|
2019-01-16 17:25:46 +00:00
|
|
|
if( subResource.exists() ) mounts.add( new FileMount( subResource, 0 ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-16 17:25:46 +00:00
|
|
|
catch( IOException | RuntimeException e )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-10-29 15:59:43 +00:00
|
|
|
ComputerCraft.log.error( "Could not load resource pack '" + resourcePackName + "'", e );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the combination of all the mounts found
|
|
|
|
if( mounts.size() >= 2 )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
IMount[] mountArray = new IMount[mounts.size()];
|
2017-05-01 13:32:39 +00:00
|
|
|
mounts.toArray( mountArray );
|
|
|
|
return new ComboMount( mountArray );
|
|
|
|
}
|
|
|
|
else if( mounts.size() == 1 )
|
|
|
|
{
|
|
|
|
return mounts.get( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 20:50:51 +00:00
|
|
|
public static InputStream getResourceFile( Class<?> modClass, String domain, String subPath )
|
|
|
|
{
|
|
|
|
// Start searching in possible locations
|
|
|
|
subPath = "assets/" + domain + "/" + subPath;
|
|
|
|
|
|
|
|
// Look in resource packs
|
|
|
|
File resourcePackDir = getResourcePackDir();
|
|
|
|
if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
|
|
|
|
{
|
|
|
|
String[] resourcePacks = resourcePackDir.list();
|
|
|
|
for( String resourcePackPath : resourcePacks )
|
|
|
|
{
|
|
|
|
File resourcePack = new File( resourcePackDir, resourcePackPath );
|
|
|
|
if( resourcePack.isDirectory() )
|
|
|
|
{
|
|
|
|
// Mount a resource pack from a folder
|
|
|
|
File subResource = new File( resourcePack, subPath );
|
|
|
|
if( subResource.exists() && subResource.isFile() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new FileInputStream( subResource );
|
|
|
|
}
|
|
|
|
catch( FileNotFoundException ignored )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ZipFile zipFile = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final ZipFile zip = zipFile = new ZipFile( resourcePack );
|
|
|
|
ZipEntry entry = zipFile.getEntry( subPath );
|
|
|
|
if( entry != null )
|
|
|
|
{
|
|
|
|
// Return a custom InputStream which will close the original zip when finished.
|
|
|
|
return new FilterInputStream( zipFile.getInputStream( entry ) )
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void close() throws IOException
|
|
|
|
{
|
|
|
|
super.close();
|
|
|
|
zip.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-11 11:33:05 +00:00
|
|
|
IoUtil.closeQuietly( zipFile );
|
2017-07-14 20:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IOException e )
|
|
|
|
{
|
2019-01-11 11:33:05 +00:00
|
|
|
if( zipFile != null ) IoUtil.closeQuietly( zipFile );
|
2017-07-14 20:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look in debug dir
|
|
|
|
File codeDir = getDebugCodeDir( modClass );
|
|
|
|
if( codeDir != null )
|
|
|
|
{
|
|
|
|
File subResource = new File( codeDir, subPath );
|
|
|
|
if( subResource.exists() && subResource.isFile() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new FileInputStream( subResource );
|
|
|
|
}
|
|
|
|
catch( FileNotFoundException ignored )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look in class loader
|
|
|
|
return modClass.getClassLoader().getResourceAsStream( subPath );
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
private static File getContainingJar( Class<?> modClass )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
2019-03-29 21:21:39 +00:00
|
|
|
int bangIndex = path.indexOf( '!' );
|
2017-05-01 14:48:44 +00:00
|
|
|
if( bangIndex >= 0 )
|
|
|
|
{
|
|
|
|
path = path.substring( 0, bangIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
URL url;
|
2018-12-23 17:46:58 +00:00
|
|
|
try
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
url = new URL( path );
|
2018-12-23 17:46:58 +00:00
|
|
|
}
|
|
|
|
catch( MalformedURLException e1 )
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
File file;
|
2018-12-23 17:46:58 +00:00
|
|
|
try
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
file = new File( url.toURI() );
|
2018-12-23 17:46:58 +00:00
|
|
|
}
|
|
|
|
catch( URISyntaxException e )
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
file = new File( url.getPath() );
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
private static File getDebugCodeDir( Class<?> modClass )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
2019-03-29 21:21:39 +00:00
|
|
|
int bangIndex = path.indexOf( '!' );
|
2018-12-10 23:46:50 +00:00
|
|
|
return bangIndex >= 0 ? null : new File( new File( path ).getParentFile(), "../.." );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public static void registerTurtleUpgrade( ITurtleUpgrade upgrade )
|
|
|
|
{
|
2019-01-12 17:51:26 +00:00
|
|
|
dan200.computercraft.shared.TurtleUpgrades.register( upgrade );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-11-21 18:11:14 +00:00
|
|
|
|
2019-01-12 18:20:16 +00:00
|
|
|
public static File getWorldDir()
|
|
|
|
{
|
|
|
|
return DimensionManager.getCurrentSaveRootDirectory();
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
//region Compatibility
|
2019-01-12 18:20:16 +00:00
|
|
|
@Deprecated
|
|
|
|
public static File getWorldDir( World world )
|
|
|
|
{
|
|
|
|
return DimensionManager.getCurrentSaveRootDirectory();
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
|
|
|
public static IMedia getMedia( ItemStack stack )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
return MediaProviders.get( stack );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
|
|
|
public static IPocketUpgrade getPocketUpgrade( ItemStack stack )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-10 23:46:50 +00:00
|
|
|
return dan200.computercraft.shared.PocketUpgrades.get( stack );
|
2018-07-05 20:19:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 23:46:50 +00:00
|
|
|
@Deprecated
|
|
|
|
public static ITurtleUpgrade getTurtleUpgrade( ItemStack stack )
|
2018-07-05 20:19:04 +00:00
|
|
|
{
|
2019-01-12 17:51:26 +00:00
|
|
|
return dan200.computercraft.shared.TurtleUpgrades.get( stack );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-01-02 17:37:16 +00:00
|
|
|
|
2019-01-05 18:50:47 +00:00
|
|
|
@Deprecated
|
|
|
|
public static IPocketUpgrade getPocketUpgrade( String id )
|
|
|
|
{
|
|
|
|
return dan200.computercraft.shared.PocketUpgrades.get( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public static ITurtleUpgrade getTurtleUpgrade( String id )
|
|
|
|
{
|
2019-01-12 17:51:26 +00:00
|
|
|
return dan200.computercraft.shared.TurtleUpgrades.get( id );
|
2019-01-05 18:50:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-02 17:37:16 +00:00
|
|
|
@Deprecated
|
|
|
|
public static IPeripheral getPeripheralAt( World world, BlockPos pos, EnumFacing side )
|
|
|
|
{
|
|
|
|
return Peripherals.getPeripheral( world, pos, side );
|
|
|
|
}
|
2019-03-16 01:54:11 +00:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public static boolean canPlayerUseCommands( EntityPlayer player )
|
|
|
|
{
|
|
|
|
MinecraftServer server = player.getServer();
|
|
|
|
return server != null && server.getPlayerList().canSendCommands( player.getGameProfile() );
|
|
|
|
}
|
2018-12-10 23:46:50 +00:00
|
|
|
//endregion
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|