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
|
2020-01-01 00:09:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
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-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;
|
Backport 1.15's terminal rendering code (#412)
This is a backport of 1.15's terminal rendering code with some further
improvements. This duplicates a fair bit of code, and is much more
efficient.
I expect the work done in #409 will supersede this, but that's unlikely
to make its way into the next release so it's worth getting this in for
now.
- Refactor a lot of common terminal code into
`FixedWithFontRenderer`. This shouldn't change any behaviour, but
makes a lot of our terminal renderers (printed pages, terminals,
monitors) a lot cleaner.
- Terminal rendering is done using a single mode/vertex format. Rather
than drawing an untextured quad for the background colours, we use an
entirely white piece of the terminal font. This allows us to batch
draws together more elegantly.
- Some minor optimisations:
- Skip rendering `"\0"` and `" "` characters. These characters occur
pretty often, especially on blank monitors and, as the font is empty
here, it is safe to skip them.
- Batch together adjacent background cells of the same colour. Again,
most terminals will have large runs of the same colour, so this is a
worthwhile optimisation.
These optimisations do mean that terminal performance is no longer
consistent as "noisy" terminals will have worse performance. This is
annoying, but still worthwhile.
- Switch monitor rendering over to use VBOs.
We also add a config option to switch between rendering backends. By
default we'll choose the best one compatible with your GPU, but there
is a config option to switch between VBOS (reasonable performance) and
display lists (bad).
When benchmarking 30 full-sized monitors rendering a static image, this
improves my FPS[^1] from 7 to 95. This is obviously an extreme case -
monitor updates are still slow, and so more frequently updating screens
will still be less than stellar.
[^1]: My graphics card is an Intel HD Graphics 520. Obviously numbers
will vary.
2020-04-21 09:43:26 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
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;
|
2019-04-02 10:50:13 +00:00
|
|
|
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
2017-05-01 13:32:39 +00:00
|
|
|
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;
|
2019-07-30 14:20:08 +00:00
|
|
|
import net.minecraftforge.fml.common.*;
|
2017-05-01 13:32:39 +00:00
|
|
|
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;
|
2019-07-30 14:20:08 +00:00
|
|
|
import java.util.*;
|
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(
|
2019-03-30 16:41:45 +00:00
|
|
|
modid = ComputerCraft.MOD_ID, name = ComputerCraft.NAME, version = ComputerCraft.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";
|
2019-03-30 16:41:45 +00:00
|
|
|
static final String VERSION = "${version}";
|
|
|
|
static final String NAME = "CC: Tweaked";
|
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;
|
2020-05-13 09:26:59 +00:00
|
|
|
public static boolean logPeripheralErrors = true;
|
|
|
|
public static boolean commandRequireCreative = true;
|
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;
|
2020-04-19 19:11:49 +00:00
|
|
|
public static int httpMaxWebsocketMessage = 128 * 1024;
|
2019-01-11 11:33:05 +00:00
|
|
|
|
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;
|
Backport 1.15's terminal rendering code (#412)
This is a backport of 1.15's terminal rendering code with some further
improvements. This duplicates a fair bit of code, and is much more
efficient.
I expect the work done in #409 will supersede this, but that's unlikely
to make its way into the next release so it's worth getting this in for
now.
- Refactor a lot of common terminal code into
`FixedWithFontRenderer`. This shouldn't change any behaviour, but
makes a lot of our terminal renderers (printed pages, terminals,
monitors) a lot cleaner.
- Terminal rendering is done using a single mode/vertex format. Rather
than drawing an untextured quad for the background colours, we use an
entirely white piece of the terminal font. This allows us to batch
draws together more elegantly.
- Some minor optimisations:
- Skip rendering `"\0"` and `" "` characters. These characters occur
pretty often, especially on blank monitors and, as the font is empty
here, it is safe to skip them.
- Batch together adjacent background cells of the same colour. Again,
most terminals will have large runs of the same colour, so this is a
worthwhile optimisation.
These optimisations do mean that terminal performance is no longer
consistent as "noisy" terminals will have worse performance. This is
annoying, but still worthwhile.
- Switch monitor rendering over to use VBOs.
We also add a config option to switch between rendering backends. By
default we'll choose the best one compatible with your GPU, but there
is a config option to switch between VBOS (reasonable performance) and
display lists (bad).
When benchmarking 30 full-sized monitors rendering a static image, this
improves my FPS[^1] from 7 to 95. This is obviously an extreme case -
monitor updates are still slow, and so more frequently updating screens
will still be less than stellar.
[^1]: My graphics card is an Intel HD Graphics 520. Obviously numbers
will vary.
2020-04-21 09:43:26 +00:00
|
|
|
public static MonitorRenderer monitorRenderer = MonitorRenderer.BEST;
|
2020-05-20 07:44:44 +00:00
|
|
|
public static long monitorBandwidth = 1_000_000;
|
2019-01-05 20:12:02 +00:00
|
|
|
|
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"
|
|
|
|
)
|
2019-04-02 10:50:13 +00:00
|
|
|
private static ComputerCraftProxyCommon 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 )
|
|
|
|
{
|
2019-04-02 10:50:13 +00:00
|
|
|
ComputerCraftProxyCommon.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()
|
|
|
|
{
|
2019-03-30 16:41:45 +00:00
|
|
|
return VERSION;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 14:20:08 +00:00
|
|
|
private static void loadFromFile( List<IMount> mounts, File file, String path, boolean allowMissing )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( file.isFile() )
|
|
|
|
{
|
|
|
|
mounts.add( new JarMount( file, path ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
File subResource = new File( file, path );
|
|
|
|
if( subResource.exists() ) mounts.add( new FileMount( subResource, 0 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IOException | RuntimeException e )
|
|
|
|
{
|
|
|
|
if( allowMissing && e instanceof FileNotFoundException ) return;
|
|
|
|
ComputerCraft.log.error( "Could not load mount '" + path + " 'from '" + file.getName() + "'", e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 14:20:08 +00:00
|
|
|
// Mount from mod jars, preferring the specified one.
|
2017-05-01 13:32:39 +00:00
|
|
|
File modJar = getContainingJar( modClass );
|
2019-07-30 14:20:08 +00:00
|
|
|
Set<File> otherMods = new HashSet<>();
|
|
|
|
for( ModContainer container : Loader.instance().getActiveModList() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-07-30 14:20:08 +00:00
|
|
|
File modFile = container.getSource();
|
|
|
|
if( modFile != null && !modFile.equals( modJar ) && modFile.exists() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-07-30 14:20:08 +00:00
|
|
|
otherMods.add( container.getSource() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 14:20:08 +00:00
|
|
|
for( File file : otherMods )
|
|
|
|
{
|
|
|
|
loadFromFile( mounts, file, subPath, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( modJar != null )
|
|
|
|
{
|
|
|
|
loadFromFile( mounts, modJar, subPath, false );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-07-30 14:20:08 +00:00
|
|
|
File resourcePack = new File( resourcePackDir, resourcePackName );
|
|
|
|
loadFromFile( mounts, resourcePack, subPath, true );
|
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 )
|
|
|
|
{
|
2020-05-20 07:44:44 +00:00
|
|
|
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
|
|
|
}
|