Skip to content

Commit

Permalink
Merge as much code from CC-Tweaked/mc-1.18.x into CC:R as possible.
Browse files Browse the repository at this point in the history
Hopefully this will make tracking changes and merging future CC: Tweaked
development easier! A lot of this is making whitespace and method
ordering even with Tweaked to bring down the diffs, but it also fast
forwards us to CC:T 1.99.0 features.
  • Loading branch information
toad-dev committed Dec 8, 2021
1 parent 34760d3 commit f880396
Show file tree
Hide file tree
Showing 259 changed files with 7,297 additions and 8,844 deletions.
8 changes: 5 additions & 3 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
image:
file: .gitpod.Dockerfile
file: config/gitpod/Dockerfile

ports:
- port: 25565
onOpen: notify

vscode:
extensions:
- eamodio.gitlens
- github.vscode-pull-request-github
- ms-azuretools.vscode-docker
- redhat.java
- richardwillis.vscode-gradle
- vscjava.vscode-java-debug
- vscode.github


tasks:
- init: ./gradlew
- name: Setup pre-commit hool
init: pre-commit install --config config/pre-commit/config.yml --allow-missing-config
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'

cctJavadoc 'cc.tweaked:cct-javadoc:1.4.1'
cctJavadoc 'cc.tweaked:cct-javadoc:1.4.2'
}

processResources {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion doc/events/redstone.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module: [kind=event] redstone
---

The @{redstone} event is fired whenever any redstone inputs on the computer change.
The @{event!redstone} event is fired whenever any redstone inputs on the computer change.

## Example
Prints a message when a redstone input changes:
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/dan200/computercraft/ComputerCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to [email protected]
*/

package dan200.computercraft;

import dan200.computercraft.core.apis.http.options.Action;
import dan200.computercraft.core.apis.http.options.AddressRule;
import dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
import dan200.computercraft.shared.Registry.ModBlocks;
import dan200.computercraft.shared.common.ColourableRecipe;
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
Expand Down Expand Up @@ -37,24 +36,20 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static dan200.computercraft.shared.ComputerCraftRegistry.init;
import static dan200.computercraft.shared.Registry.init;

public final class ComputerCraft implements ModInitializer
{
public static final String MOD_ID = "computercraft";

// Configuration fields
public static int computerSpaceLimit = 1000 * 1000;
public static int floppySpaceLimit = 125 * 1000;
public static int maximumFilesOpen = 128;
public static boolean disableLua51Features = false;
public static String defaultComputerSettings = "";
public static boolean debugEnable = true;
public static boolean logComputerErrors = true;
public static boolean commandRequireCreative = true;

Expand All @@ -64,10 +59,11 @@ public final class ComputerCraft implements ModInitializer

public static boolean httpEnabled = true;
public static boolean httpWebsocketEnabled = true;
public static List<AddressRule> httpRules = Collections.unmodifiableList( Arrays.asList(
public static List<AddressRule> httpRules = List.of(
AddressRule.parse( "$private", null, Action.DENY.toPartial() ),
AddressRule.parse( "*", null, Action.ALLOW.toPartial() )
) );
);

public static int httpMaxRequests = 16;
public static int httpMaxWebsockets = 4;
public static int httpDownloadBandwidth = 32 * 1024 * 1024;
Expand All @@ -80,7 +76,6 @@ public final class ComputerCraft implements ModInitializer
public static int modemHighAltitudeRangeDuringStorm = 384;
public static int maxNotesPerTick = 8;
public static MonitorRenderer monitorRenderer = MonitorRenderer.BEST;
public static double monitorDistanceSq = 4096;
public static int monitorDistance = 65;
public static long monitorBandwidth = 1_000_000;

Expand All @@ -98,6 +93,7 @@ public final class ComputerCraft implements ModInitializer

public static int pocketTermWidth = 26;
public static int pocketTermHeight = 20;

public static int monitorWidth = 8;
public static int monitorHeight = 6;

Expand Down
69 changes: 25 additions & 44 deletions src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to [email protected]
*/

package dan200.computercraft;

import dan200.computercraft.api.ComputerCraftAPI.IComputerCraftAPI;
Expand Down Expand Up @@ -35,7 +34,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -59,36 +57,24 @@ private ComputerCraftAPIImpl()

public static InputStream getResourceFile( String domain, String subPath )
{
MinecraftServer server = GameInstanceUtils.getServer();
if( server != null )
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) GameInstanceUtils.getServer()).callGetResourceManager();
try
{
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).callGetResourceManager();
try
{
return manager.getResource( new ResourceLocation( domain, subPath ) )
.getInputStream();
}
catch( IOException ignored )
{
return null;
}
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
}
catch( IOException ignored )
{
return null;
}
return null;
}

@Nonnull
@Override
public String getInstalledVersion()
{
if( version != null )
{
return version;
}
return version = FabricLoader.getInstance()
.getModContainer( ComputerCraft.MOD_ID )
.map( x -> x.getMetadata()
.getVersion()
.toString() )
if( version != null ) return version;
return version = FabricLoader.getInstance().getModContainer( ComputerCraft.MOD_ID )
.map( x -> x.getMetadata().getVersion().toString() )
.orElse( "unknown" );
}

Expand All @@ -114,14 +100,9 @@ public IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String
@Override
public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
{
MinecraftServer server = GameInstanceUtils.getServer();
if( server != null )
{
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).callGetResourceManager();
ResourceMount mount = ResourceMount.get( domain, subPath, manager );
return mount.exists( "" ) ? mount : null;
}
return null;
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) GameInstanceUtils.getServer()).callGetResourceManager();
ResourceMount mount = ResourceMount.get( domain, subPath, manager );
return mount.exists( "" ) ? mount : null;
}

@Override
Expand All @@ -131,39 +112,39 @@ public void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
}

@Override
public void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
public void registerGenericSource( @Nonnull GenericSource source )
{
TurtleUpgrades.register( upgrade );
GenericMethod.register( source );
}

@Override
public void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
public void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
{
BundledRedstone.register( provider );
TurtleUpgrades.register( upgrade );
}

@Override
public int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
public void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
{
return BundledRedstone.getDefaultOutput( world, pos, side );
PocketUpgrades.register( upgrade );
}

@Override
public void registerMediaProvider( @Nonnull IMediaProvider provider )
public void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
{
MediaProviders.register( provider );
BundledRedstone.register( provider );
}

@Override
public void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
public int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
{
PocketUpgrades.register( upgrade );
return BundledRedstone.getDefaultOutput( world, pos, side );
}

@Override
public void registerGenericSource( @Nonnull GenericSource source )
public void registerMediaProvider( @Nonnull IMediaProvider provider )
{
GenericMethod.register( source );
MediaProviders.register( provider );
}

@Nonnull
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/dan200/computercraft/api/ComputerCraftAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@
*/
public final class ComputerCraftAPI
{
public static final String MOD_ID = "computercraft";

@Nonnull
public static String getInstalledVersion()
{
return getInstance().getInstalledVersion();
}

@Nonnull
@Deprecated
public static String getAPIVersion()
{
return getInstalledVersion();
}

/**
* Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
*
Expand Down Expand Up @@ -139,9 +134,9 @@ public static void registerGenericSource( @Nonnull GenericSource source )
}

/**
* Registers a new turtle turtle for use in ComputerCraft. After calling this,
* users should be able to craft Turtles with your new turtle. It is recommended to call
* this during the load() method of your mod.
* Registers a new turtle upgrade for use in ComputerCraft. After calling this,
* users should be able to craft Turtles with your upgrade's ItemStack. It is
* recommended to call this during the load() method of your mod.
*
* @param upgrade The turtle upgrade to register.
* @see ITurtleUpgrade
Expand All @@ -151,6 +146,19 @@ public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
getInstance().registerTurtleUpgrade( upgrade );
}

/**
* Registers a new pocket upgrade for use in ComputerCraft. After calling this,
* users should be able to craft pocket computers with your upgrade's ItemStack. It is
* recommended to call this during the load() method of your mod.
*
* @param upgrade The pocket upgrade to register.
* @see IPocketUpgrade
*/
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
{
getInstance().registerPocketUpgrade( upgrade );
}

/**
* Registers a bundled redstone provider to provide bundled redstone output for blocks.
*
Expand Down Expand Up @@ -188,11 +196,6 @@ public static void registerMediaProvider( @Nonnull IMediaProvider provider )
getInstance().registerMediaProvider( provider );
}

public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
{
getInstance().registerPocketUpgrade( upgrade );
}

/**
* Attempt to get the game-wide wireless network.
*
Expand Down Expand Up @@ -273,14 +276,13 @@ public interface IComputerCraftAPI

void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade );

void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade );

void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );

int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );

void registerMediaProvider( @Nonnull IMediaProvider provider );

void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade );

@Nonnull
IPacketNetwork getWirelessNetwork();

Expand Down
65 changes: 65 additions & 0 deletions src/main/java/dan200/computercraft/api/ComputerCraftTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api;

import dan200.computercraft.ComputerCraft;
import net.fabricmc.fabric.api.tag.TagFactory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;

/**
* Tags provided by ComputerCraft.
*/
public class ComputerCraftTags
{
public static class Items
{
public static final Tag.Named<Item> COMPUTER = make( "computer" );
public static final Tag.Named<Item> TURTLE = make( "turtle" );
public static final Tag.Named<Item> WIRED_MODEM = make( "wired_modem" );
public static final Tag.Named<Item> MONITOR = make( "monitor" );

private static Tag.Named<Item> make( String name )
{
return TagFactory.ITEM.create( new ResourceLocation( ComputerCraft.MOD_ID, name ) );
}
}

public static class Blocks
{
public static final Tag.Named<Block> COMPUTER = make( "computer" );
public static final Tag.Named<Block> TURTLE = make( "turtle" );
public static final Tag.Named<Block> WIRED_MODEM = make( "wired_modem" );
public static final Tag.Named<Block> MONITOR = make( "monitor" );

/**
* Blocks which can be broken by any turtle tool.
*/
public static final Tag.Named<Block> TURTLE_ALWAYS_BREAKABLE = make( "turtle_always_breakable" );

/**
* Blocks which can be broken by the default shovel tool.
*/
public static final Tag.Named<Block> TURTLE_SHOVEL_BREAKABLE = make( "turtle_shovel_harvestable" );

/**
* Blocks which can be broken with the default sword tool.
*/
public static final Tag.Named<Block> TURTLE_SWORD_BREAKABLE = make( "turtle_sword_harvestable" );

/**
* Blocks which can be broken with the default hoe tool.
*/
public static final Tag.Named<Block> TURTLE_HOE_BREAKABLE = make( "turtle_hoe_harvestable" );

private static Tag.Named<Block> make( String name )
{
return TagFactory.BLOCK.create( new ResourceLocation( ComputerCraft.MOD_ID, name ) );
}
}
}
Loading

0 comments on commit f880396

Please sign in to comment.