Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and cleanup #1817

Merged
merged 9 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

A Minecraft Forge mod all about Redstone circuity.

| Release Branch | MC Version | Status |
|----------------------|:----------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Release Branch | MC Version | Status |
|------------------------|:----------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `publish/1.18/release` | 1.18.2 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.18-release.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.18/beta` | 1.18.2 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.18-beta.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.18/beta` | 1.18.2 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.18-beta.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.16/release` | 1.16.5 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.16-release.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.16/beta` | 1.16.5 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.16-beta.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.15/beta` | 1.15.2 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.15-beta.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.16/beta` | 1.16.5 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.16-beta.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |
| `publish/1.15/beta` | 1.15.2 | [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MrTJP/3ef501bc64c896a86fd706dfea8ba367/raw/projectred-badge-1.15-beta.json)](https://www.curseforge.com/minecraft/mc-mods/project-red-core) |

## Development Environment Setup

Expand All @@ -20,7 +20,7 @@ Project Red uses a standard Forge Gradle environment. Setup steps should be the
git checkout https://github.com/MrTJP/ProjectRed.git .
```

2. Build the project:
2. Build the project:
```
./gradlew build
```
Expand All @@ -29,8 +29,37 @@ Project Red uses a standard Forge Gradle environment. Setup steps should be the
```
./gradlew genIntellijRuns
```

4. Open the project directory in Intellij IDEA and give it a few minutes to set up and index the Gradle project.

### Building Locally

You can re-build jar files locally by running `./gradlew build`. The jars can be found in `./<module>/build/libs`.

## ProjectRed API

### Setup
ProjectRed API can be consumed by your ForgeGradle project by adding the following to your `build.gradle`:
```groovy
// Add repository
repositories {
maven { url = "https://proxy-maven.covers1624.net/" }
}

// Add dependency (replace ${mc_version} and ${pr_version} with the desired versions)
dependencies {
/* minecraft dependency is here */

// compile against the API but do not include it at runtime
compileOnly fg.deobf("mrtjp:ProjectRed-${mc_version}:${pr_version}:api")

// at runtime, use the full mod jars of the required modules
runtimeOnly fg.deobf("mrtjp:ProjectRed-${mc_version}:${pr_version}:core")
runtimeOnly fg.deobf("mrtjp:ProjectRed-${mc_version}:${pr_version}:integration")
runtimeOnly fg.deobf("mrtjp:ProjectRed-${mc_version}:${pr_version}:transmission")
// etc...
}
```

### Usage
The primary entrypoint into the API is `mrtjp.projectred.api.ProjectRedAPI` where you will find static fields for each module of ProjectRed. If a module is installed, its corresponding field will be a non-null implementor of that module's API. See the javadocs for more information.
13 changes: 13 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id 'net.minecraftforge.gradle'
}

minecraft {
mappings channel: mcp_mappings, version: mc_version
// accessTransformer = file("../core/src/main/resources/META-INF/accesstransformer.cfg")
}

dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mrtjp.projectred.api;

import javax.annotation.Nullable;

/**
* Implemented by parts that can emit bundled cable signals. If you are a
* tile entity, see {@link IBundledTile}
Expand All @@ -22,5 +24,5 @@ public interface IBundledEmitter
* The return value will be used immediately, so the returned array may be
* overwritten by the next call to getBundledSignal.
*/
byte[] getBundledSignal(int dir);
@Nullable byte[] getBundledSignal(int dir);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mrtjp.projectred.api;

import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;

import javax.annotation.Nullable;

/**
* Class used instead of implementing IBundledTile, where it would be very,
* very inconvienient (such as when PR adds this functionality to other mods).
Expand Down Expand Up @@ -44,7 +46,7 @@ public interface IBundledTileInteraction
* @param world The World
* @param pos The coordinates of the block being checked
* @param side The side we want the signal for.
* @return The byte array of all the signals.
* @return The byte array of all the signals. Null is equivalent to zero signal.
*/
byte[] getBundledSignal(Level world, BlockPos pos, Direction side);
@Nullable byte[] getBundledSignal(Level world, BlockPos pos, Direction side);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mrtjp.projectred.api;

import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;

import javax.annotation.Nullable;

public interface ITransmissionAPI
{
/**
Expand All @@ -20,11 +22,11 @@ public interface ITransmissionAPI
* emitted to this block.
*
* @param world The world containing the block
* @param pos The coordinates of the block/tile querying signal
* @param side The side of the block
* @param pos The coordinates of the block/tile querying signal
* @param side The side of the block
* @return A bundled signal {@link IBundledEmitter}
*/
byte[] getBundledInput(Level world, BlockPos pos, Direction side);
@Nullable byte[] getBundledInput(Level world, BlockPos pos, Direction side);

/**
* Checks to see if the position specified contains a bundled cable.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mrtjp.projectred.api;

import javax.annotation.Nullable;

/**
* Central API class for ProjectRed. APIs are split up by module. If a specific
* module is installed, the appropriate field will contain an implementor of that
Expand All @@ -23,10 +25,12 @@ public final class ProjectRedAPI
/**
* API used for Frame-based movement.
*/
@Nullable
public static IExpansionAPI expansionAPI;

/**
* API used for interacting with wires.
*/
@Nullable
public static ITransmissionAPI transmissionAPI;
}
9 changes: 9 additions & 0 deletions api/src/main/java/mrtjp/projectred/api/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package mrtjp.projectred.api;

import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ publishing {
}
publications {
ProjectRed(MavenPublication) {
artifact project(':api').jar
artifact project(':core').jar
artifact project(':expansion').jar
artifact project(':exploration').jar
Expand Down
3 changes: 3 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ plugins {

String mod_id = 'projectred_core'

// Include all sources from API project
sourceSets.main.java.srcDirs += ['../api/src/main/java']

minecraft {
mappings channel: mcp_mappings, version: mc_version
accessTransformer = file("src/main/resources/META-INF/accesstransformer.cfg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import mrtjp.projectred.core.ProjectRedCore;
import mrtjp.projectred.api.IBundledTileInteraction;
import mrtjp.projectred.api.ProjectRedAPI;
import mrtjp.projectred.core.BundledSignalsLib;
import mrtjp.projectred.core.ProjectRedCore;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
Expand All @@ -29,6 +29,7 @@ public static void init(Object ccModObject) {
private static class CCPRBundledRedstoneProvider implements IBundledRedstoneProvider {
@Override
public int getBundledRedstoneOutput(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side) {
assert ProjectRedAPI.transmissionAPI != null;
byte[] signal = ProjectRedAPI.transmissionAPI.getBundledInput(world, pos.relative(side), side.getOpposite());
return BundledSignalsLib.packDigital(signal);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package mrtjp.projectred.compatibility;

import net.covers1624.quack.annotation.FieldsAreNonnullByDefault;
import net.covers1624.quack.annotation.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
23 changes: 12 additions & 11 deletions core/src/main/java/mrtjp/projectred/core/BundledSignalsLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -30,7 +31,7 @@ public static void registerBundledTileInteraction(IBundledTileInteraction intera
interactions.add(interaction);
}

public static byte[] getBundledInput(Level world, BlockPos pos, Direction facing) {
public static @Nullable byte[] getBundledInput(Level world, BlockPos pos, Direction facing) {

int side = facing.ordinal();
BlockEntity tile = world.getBlockEntity(pos.relative(facing));
Expand Down Expand Up @@ -81,7 +82,7 @@ public static boolean isValidInteractionFor(Level world, BlockPos pos, Direction
return false;
}

public static byte[] getBundledSignalViaInteraction(Level world, BlockPos pos, Direction side) {
public static @Nullable byte[] getBundledSignalViaInteraction(Level world, BlockPos pos, Direction side) {
for (IBundledTileInteraction interaction : interactions) {
if (interaction.isValidInteractionFor(world, pos, side)) {
return interaction.getBundledSignal(world, pos, side);
Expand All @@ -93,7 +94,7 @@ public static byte[] getBundledSignalViaInteraction(Level world, BlockPos pos, D

//region Signal utilities

public static boolean signalsEqual(byte[] signal1, byte[] signal2) {
public static boolean signalsEqual(@Nullable byte[] signal1, @Nullable byte[] signal2) {
if (signal1 == null) return isSignalZero(signal2);
if (signal2 == null) return isSignalZero(signal1);
if (signal1.length != signal2.length) return false;
Expand All @@ -103,15 +104,15 @@ public static boolean signalsEqual(byte[] signal1, byte[] signal2) {
return true;
}

public static boolean isSignalZero(byte[] signal) {
public static boolean isSignalZero(@Nullable byte[] signal) {
if (signal == null) return true;
for (byte b : signal) {
if (b != 0) return false;
}
return true;
}

public static boolean isSignalZero(byte[] signal, int mask) {
public static boolean isSignalZero(@Nullable byte[] signal, int mask) {
if (signal == null) return true;
for (int i = 0; i < signal.length; i++) {
if ((mask & 1 << i) != 0 && signal[i] != 0) return false;
Expand Down Expand Up @@ -139,7 +140,7 @@ public static void applyChangeMask(byte[] source, byte[] dest, int mask) {
}
}

public static byte[] raiseSignal(byte[] signal, byte[] source) {
public static byte[] raiseSignal(@Nullable byte[] signal, @Nullable byte[] source) {
if (signal == null) signal = new byte[16];
if (source == null) return signal;
for (int i = 0; i < 16; i++) {
Expand All @@ -150,20 +151,20 @@ public static byte[] raiseSignal(byte[] signal, byte[] source) {
return signal;
}

public static byte[] copySignal(byte[] signal) {
public static @Nullable byte[] copySignal(@Nullable byte[] signal) {
return signal == null ? null : signal.clone();
}

public static void saveSignal(CompoundTag tag, String key, byte[] signal) {
public static void saveSignal(CompoundTag tag, String key, @Nullable byte[] signal) {
if (signal != null) tag.putByteArray(key, signal);
}

public static byte[] loadSignal(CompoundTag tag, String key) {
public static @Nullable byte[] loadSignal(CompoundTag tag, String key) {
if (tag.contains(key)) return tag.getByteArray(key).clone();
return null;
}

public static int packDigital(byte[] signal) {
public static int packDigital(@Nullable byte[] signal) {
if (signal == null) return 0;
int packed = 0;
for (int i = 0; i < 16; i++) {
Expand All @@ -172,7 +173,7 @@ public static int packDigital(byte[] signal) {
return packed;
}

public static byte[] unpackDigital(byte[] signal, int packed) {
public static @Nullable byte[] unpackDigital(@Nullable byte[] signal, int packed) {
if (packed == 0) {
if (signal != null) Arrays.fill(signal, (byte) 0);
return signal;
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/mrtjp/projectred/core/CenterLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;

public class CenterLookup {

//Starting conditions
Expand All @@ -19,14 +21,14 @@ public class CenterLookup {
// Located objects
public final BlockState state;
public final Block block;
public final BlockEntity tile;
public final MultiPart part;
public final @Nullable BlockEntity tile;
public final @Nullable MultiPart part;

// Conditions for reverse lookup
public final BlockPos otherPos;
public final int otherDirection;

public CenterLookup(Level world, BlockPos pos, int direction, BlockState state, BlockEntity tile, MultiPart part, BlockPos otherPos, int otherDirection) {
public CenterLookup(Level world, BlockPos pos, int direction, BlockState state, @Nullable BlockEntity tile, @Nullable MultiPart part, BlockPos otherPos, int otherDirection) {
this.world = world;
this.pos = pos;
this.direction = direction;
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/mrtjp/projectred/core/Configurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class Configurator {
/* Compatibility */
public static boolean compat_CCBundledCable = true;

/* Fabrication */
public static int autoCompileTileLimit = 20;

public static void load() {
ConfigFile configFile = new ConfigFile(MOD_ID).path(Paths.get("config/ProjectRed.cfg"));
ConfigCategory config = configFile.load();
Expand Down Expand Up @@ -90,6 +93,9 @@ private static void loadValues(ConfigCategory config) {

ConfigCategory compat = config.getCategory("compatibility").setComment("Control the loading of various compatibility hooks. These settings are ignored unless the Compatibility module is installed.");
compat_CCBundledCable = compat.getValue("computercraft").setDefaultBoolean(compat_CCBundledCable).setComment("This allows computers to connect to bundled cables with the RS API.").getBoolean();

ConfigCategory fab = config.getCategory("fabrication").setComment("Settings for Fabrication circuit compilation");
autoCompileTileLimit = fab.getValue("auto_compile_tile_limit").setDefaultInt(autoCompileTileLimit).setComment("Tile count before auto-compile becomes disallowed (-1 to always allow, 0 to never allow). Recommended to keep this very low on servers.").getInt();
}

private static void loadAndDeleteLegacyValues(ConfigCategory config) {
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/mrtjp/projectred/core/CoreNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import java.util.Objects;

import static mrtjp.projectred.core.ProjectRedCore.MOD_ID;

public class CoreNetwork {
Expand Down Expand Up @@ -52,7 +54,7 @@ private static class ClientHandler implements ICustomPacketHandler.IClientPacket
public void handlePacket(PacketCustom packet, Minecraft mc, ClientPacketListener handler) {
switch (packet.getType()) {
case NET_TILE_PACKET_TO_CLIENT:
handleTilePacket(mc.level, packet);
handleTilePacket(Objects.requireNonNull(mc.level), packet);
break;
default:
// unknown key
Expand Down
Loading
Loading