mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-15 04:30:29 +00:00
Merge branch 'mc-1.15.x' into mc-1.16.x
This commit is contained in:
commit
4efde2b294
@ -16,15 +16,10 @@ import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@ -82,6 +77,7 @@ public final class ComputerCraft
|
||||
public static int modemHighAltitudeRangeDuringStorm = 384;
|
||||
public static int maxNotesPerTick = 8;
|
||||
public static MonitorRenderer monitorRenderer = MonitorRenderer.BEST;
|
||||
public static double monitorDistanceSq = 4096;
|
||||
public static long monitorBandwidth = 1_000_000;
|
||||
|
||||
public static boolean turtlesNeedFuel = true;
|
||||
@ -138,17 +134,4 @@ public final class ComputerCraft
|
||||
Config.setup();
|
||||
Registry.setup();
|
||||
}
|
||||
|
||||
public static InputStream getResourceFile( String domain, String subPath )
|
||||
{
|
||||
IResourceManager manager = ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().func_240970_h_();
|
||||
try
|
||||
{
|
||||
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
|
||||
}
|
||||
catch( IOException ignored )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import dan200.computercraft.shared.wired.WiredNode;
|
||||
import net.minecraft.resources.IReloadableResourceManager;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
@ -36,6 +37,8 @@ import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static dan200.computercraft.shared.Capabilities.CAPABILITY_WIRED_ELEMENT;
|
||||
|
||||
@ -49,6 +52,19 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
{
|
||||
}
|
||||
|
||||
public static InputStream getResourceFile( String domain, String subPath )
|
||||
{
|
||||
IReloadableResourceManager manager = (IReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().func_240970_h_();
|
||||
try
|
||||
{
|
||||
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
|
||||
}
|
||||
catch( IOException ignored )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getInstalledVersion()
|
||||
|
@ -15,8 +15,7 @@ import javax.annotation.Nullable;
|
||||
* The interface that defines a peripheral.
|
||||
*
|
||||
* In order to expose a peripheral for your block or tile entity, you may either attach a {@link Capability}, or
|
||||
* register a {@link IPeripheralProvider}. It is <em>not</em> recommended to implement {@link IPeripheral} directly on
|
||||
* the tile.
|
||||
* register a {@link IPeripheralProvider}. This <em>cannot</em> be implemented {@link IPeripheral} directly on the tile.
|
||||
*
|
||||
* Peripherals should provide a series of methods to the user, either using {@link LuaFunction} or by implementing
|
||||
* {@link IDynamicPeripheral}.
|
||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
@ -85,7 +86,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +99,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +117,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +146,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +166,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +188,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,9 +196,9 @@ class MountWrapper
|
||||
{
|
||||
if( writableMount == null ) throw exceptionOf( path, "Access denied" );
|
||||
|
||||
path = toLocal( path );
|
||||
try
|
||||
{
|
||||
path = toLocal( path );
|
||||
if( mount.exists( path ) )
|
||||
{
|
||||
writableMount.delete( path );
|
||||
@ -209,7 +210,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +244,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +282,7 @@ class MountWrapper
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
throw localExceptionOf( e );
|
||||
throw localExceptionOf( path, e );
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +291,7 @@ class MountWrapper
|
||||
return FileSystem.toLocal( path, location );
|
||||
}
|
||||
|
||||
private FileSystemException localExceptionOf( IOException e )
|
||||
private FileSystemException localExceptionOf( @Nullable String localPath, @Nonnull IOException e )
|
||||
{
|
||||
if( !location.isEmpty() && e instanceof FileOperationException )
|
||||
{
|
||||
@ -298,6 +299,14 @@ class MountWrapper
|
||||
if( ex.getFilename() != null ) return localExceptionOf( ex.getFilename(), ex.getMessage() );
|
||||
}
|
||||
|
||||
if( e instanceof java.nio.file.FileSystemException )
|
||||
{
|
||||
// This error will contain the absolute path, leaking information about where MC is installed. We drop that,
|
||||
// just taking the reason. We assume that the error refers to the input path.
|
||||
String message = ((java.nio.file.FileSystemException) e).getReason().trim();
|
||||
return localPath == null ? new FileSystemException( message ) : localExceptionOf( localPath, message );
|
||||
}
|
||||
|
||||
return new FileSystemException( e.getMessage() );
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,7 @@ public final class Config
|
||||
private static final ConfigValue<Boolean> genericPeripheral;
|
||||
|
||||
private static final ConfigValue<MonitorRenderer> monitorRenderer;
|
||||
private static final ConfigValue<Integer> monitorDistance;
|
||||
|
||||
private static final ForgeConfigSpec serverSpec;
|
||||
private static final ForgeConfigSpec clientSpec;
|
||||
@ -311,6 +312,10 @@ public final class Config
|
||||
.comment( "The renderer to use for monitors. Generally this should be kept at \"best\" - if " +
|
||||
"monitors have performance issues, you may wish to experiment with alternative renderers." )
|
||||
.defineEnum( "monitor_renderer", MonitorRenderer.BEST );
|
||||
monitorDistance = clientBuilder
|
||||
.comment( "The maximum distance monitors will render at. This defaults to the standard tile entity limit, " +
|
||||
"but may be extended if you wish to build larger monitors." )
|
||||
.defineInRange( "monitor_distance", 64, 16, 1024 );
|
||||
clientSpec = clientBuilder.build();
|
||||
}
|
||||
|
||||
@ -379,6 +384,7 @@ public final class Config
|
||||
|
||||
// Client
|
||||
ComputerCraft.monitorRenderer = monitorRenderer.get();
|
||||
ComputerCraft.monitorDistanceSq = monitorDistance.get() * monitorDistance.get();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -6,6 +6,7 @@
|
||||
package dan200.computercraft.shared.computer.core;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.ComputerCraftAPIImpl;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
@ -333,7 +334,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
@Override
|
||||
public InputStream createResourceFile( String domain, String subPath )
|
||||
{
|
||||
return ComputerCraft.getResourceFile( domain, subPath );
|
||||
return ComputerCraftAPIImpl.getResourceFile( domain, subPath );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -690,4 +690,10 @@ public class TileMonitor extends TileGeneric
|
||||
return new AxisAlignedBB( pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxRenderDistanceSquared()
|
||||
{
|
||||
return ComputerCraft.monitorDistanceSq;
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +99,15 @@ describe("The fs library", function()
|
||||
handle.close()
|
||||
expect.error(handle.close):eq("attempt to use a closed file")
|
||||
end)
|
||||
|
||||
it("fails gracefully when opening 'CON' on Windows", function()
|
||||
local ok, err = fs.open("test-files/con", "w")
|
||||
if ok then fs.delete("test-files/con") return end
|
||||
|
||||
-- On my Windows/Java version the message appears to be "Incorrect function.". It may not be
|
||||
-- consistent though, and honestly doesn't matter too much.
|
||||
expect(err):str_match("^/test%-files/con: .*")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("writing in binary mode", function()
|
||||
|
Loading…
Reference in New Issue
Block a user