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

Pattern registration #678

Merged
merged 14 commits into from
Sep 1, 2024
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
33 changes: 17 additions & 16 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,20 @@ Refined Storage is split up into various modules. Most modules aren't dependent
the `refinedstorage-common`, `refinedstorage-neoforge` and `refinedstorage-fabric` modules have dependencies on
Minecraft.

| Name | Use in addons | Description |
|-------------------------------|---------------|----------------------------------------------------------------------------------------------------------|
| `refinedstorage-core-api` | ✔️ | Contains some utility classes and enums. |
| `refinedstorage-grid-api` | ✔️ | Contains Grid related functionality. |
| `refinedstorage-network-api` | ✔️ | Contains storage network related functionality. |
| `refinedstorage-network` | ❌ | Contains implementations of `refinedstorage-network-api`. |
| `refinedstorage-network-test` | ✔️ | JUnit extension which helps with setting up a network and a network node for testing. |
| `refinedstorage-query-parser` | ✔️ | A query parser, contains a lexer and parser. Only used for Grid query parsing. |
| `refinedstorage-resource-api` | ✔️ | Contains API for handling resources. |
| `refinedstorage-storage-api` | ✔️ | Contains storage related functionality. |
| `refinedstorage-common-api` | ✔️ | Implements the various Refined Storage API modules for use in Minecraft. |
| `refinedstorage-common` | ❌ | Common mod code. Most gameplay code is in here. |
| `refinedstorage-fabric-api` | ✔️ | Additional API for the Fabric platform. |
| `refinedstorage-fabric` | ❌ | The platform module for Fabric. This module contains Fabric specific code. |
| `refinedstorage-neoforge-api` | ✔️ | Additional API for the NeoForge platform. |
| `refinedstorage-neoforge` | ❌ | The platform module for NeoForge. This module contains NeoForge specific code and the integration tests. |
| Name | Use in addons | Description |
|-----------------------------------|---------------|----------------------------------------------------------------------------------------------------------|
| `refinedstorage-core-api` | ✔️ | Contains some utility classes and enums. |
| `refinedstorage-grid-api` | ✔️ | Contains Grid related functionality. |
| `refinedstorage-autocrafting-api` | ✔️ | Contains autocrafting related functionality. |
| `refinedstorage-network-api` | ✔️ | Contains storage network related functionality. |
| `refinedstorage-network` | ❌ | Contains implementations of `refinedstorage-network-api`. |
| `refinedstorage-network-test` | ✔️ | JUnit extension which helps with setting up a network and a network node for testing. |
| `refinedstorage-query-parser` | ✔️ | A query parser, contains a lexer and parser. Only used for Grid query parsing. |
| `refinedstorage-resource-api` | ✔️ | Contains API for handling resources. |
| `refinedstorage-storage-api` | ✔️ | Contains storage related functionality. |
| `refinedstorage-common-api` | ✔️ | Implements the various Refined Storage API modules for use in Minecraft. |
| `refinedstorage-common` | ❌ | Common mod code. Most gameplay code is in here. |
| `refinedstorage-fabric-api` | ✔️ | Additional API for the Fabric platform. |
| `refinedstorage-fabric` | ❌ | The platform module for Fabric. This module contains Fabric specific code. |
| `refinedstorage-neoforge-api` | ✔️ | Additional API for the NeoForge platform. |
| `refinedstorage-neoforge` | ❌ | The platform module for NeoForge. This module contains NeoForge specific code and the integration tests. |
2 changes: 2 additions & 0 deletions .idea/dictionaries/refinedstorage.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Lock until all outputs are received (new, facilitates easier "blocking mode" without redstone)
- Lock until low redstone signal
- Lock until high redstone signal
- Resources in the Grid that are autocraftable now display an orange backdrop and tooltip to indicate whether the resource is autocraftable at a glance.
- Slots used in the Pattern Grid for pattern encoding and Crafting Grid crafting matrix slots now display an orange backdrop and tooltip to indicate whether the item is autocraftable at a glance. This checks patterns from your network and from your inventory.
- Added help tooltip for filtering based on recipe items in the Crafting Grid.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="FileLength">
<property name="max" value="750"/>
<property name="max" value="800"/>
</module>
<module name="NewlineAtEndOfFile"/>
<module name="JavadocPackage"/>
Expand Down
31 changes: 31 additions & 0 deletions refinedstorage-autocrafting-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id("refinedarchitect.base")
}

refinedarchitect {
testing()
mutationTesting()
javadoc()
publishing {
maven = true
}
}

base {
archivesName.set("refinedstorage-autocrafting-api")
}

dependencies {
api(libs.apiguardian)
api(project(":refinedstorage-resource-api"))
api(project(":refinedstorage-core-api"))
api(project(":refinedstorage-storage-api"))
api(project(":refinedstorage-query-parser"))
implementation(libs.slf4j.api)
testImplementation(libs.junit.api)
testImplementation(libs.junit.params)
testImplementation(libs.assertj)
testImplementation(libs.mockito)
testRuntimeOnly(libs.junit.engine)
testRuntimeOnly(libs.slf4j.impl)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

import java.util.Set;

import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.6")
public interface Pattern {
Set<ResourceKey> getOutputResources();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

import java.util.Set;

import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.8")
public interface PatternRepository {
void add(Pattern pattern);

void remove(Pattern pattern);

Set<ResourceKey> getOutputs();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

import java.util.HashSet;
import java.util.Set;

public class PatternRepositoryImpl implements PatternRepository {
private final Set<Pattern> patterns = new HashSet<>();
private final Set<ResourceKey> outputs = new HashSet<>();

@Override
public void add(final Pattern pattern) {
patterns.add(pattern);
outputs.addAll(pattern.getOutputResources());
}

@Override
public void remove(final Pattern pattern) {
patterns.remove(pattern);
for (final ResourceKey output : pattern.getOutputResources()) {
final boolean noOtherPatternHasThisOutput = patterns.stream()
.noneMatch(otherPattern -> otherPattern.getOutputResources().contains(output));
if (noOtherPatternHasThisOutput) {
outputs.remove(output);
}
}
}

@Override
public Set<ResourceKey> getOutputs() {
return outputs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@FieldsAndMethodsAreNonnullByDefault
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

public enum FakeResources implements ResourceKey {
A,
B,
C
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class PatternRepositoryImplTest {
private PatternRepositoryImpl sut;

@BeforeEach
void setUp() {
sut = new PatternRepositoryImpl();
}

@Test
void testDefaultState() {
// Assert
assertThat(sut.getOutputs()).isEmpty();
}

@Test
void shouldAddPattern() {
// Act
sut.add(new SimplePattern(FakeResources.A));

// Assert
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.A);
}

@Test
void shouldAddMultiplePatterns() {
// Act
sut.add(new SimplePattern(FakeResources.A));
sut.add(new SimplePattern(FakeResources.B));

// Assert
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder(
FakeResources.A,
FakeResources.B
);
}

@Test
void shouldRemovePattern() {
// Arrange
final SimplePattern a = new SimplePattern(FakeResources.A);
final SimplePattern b = new SimplePattern(FakeResources.B);

sut.add(a);
sut.add(b);

// Act
sut.remove(a);

// Assert
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.B);
}

@Test
void shouldRemoveMultiplePatterns() {
// Arrange
final SimplePattern a = new SimplePattern(FakeResources.A);
final SimplePattern b = new SimplePattern(FakeResources.B);

sut.add(a);
sut.add(b);

// Act
sut.remove(a);
sut.remove(b);

// Assert
assertThat(sut.getOutputs()).isEmpty();
}

@Test
void shouldRemovePatternButNotRemoveOutputIfAnotherPatternStillHasThatOutput() {
// Arrange
final SimplePattern a = new SimplePattern(FakeResources.A);
final SimplePattern b = new SimplePattern(FakeResources.B, FakeResources.A);

sut.add(a);
sut.add(b);

// Act
sut.remove(a);

// Assert
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder(
FakeResources.A,
FakeResources.B
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

import java.util.Set;

public class SimplePattern implements Pattern {
private final Set<ResourceKey> outputs;

public SimplePattern(final ResourceKey... outputs) {
this.outputs = Set.of(outputs);
}

@Override
public Set<ResourceKey> getOutputResources() {
return outputs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@FieldsAndMethodsAreNonnullByDefault
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
1 change: 1 addition & 0 deletions refinedstorage-common-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dependencies {
api(project(":refinedstorage-resource-api"))
api(project(":refinedstorage-network-api"))
api(project(":refinedstorage-grid-api"))
api(project(":refinedstorage-autocrafting-api"))
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.refinedmods.refinedstorage.common.api;

import com.refinedmods.refinedstorage.api.autocrafting.Pattern;
import com.refinedmods.refinedstorage.api.core.component.ComponentMapFactory;
import com.refinedmods.refinedstorage.api.network.Network;
import com.refinedmods.refinedstorage.api.network.NetworkComponent;
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.autocrafting.Pattern;
import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.refinedmods.refinedstorage.common.api;

import com.refinedmods.refinedstorage.api.autocrafting.Pattern;
import com.refinedmods.refinedstorage.api.core.component.ComponentMapFactory;
import com.refinedmods.refinedstorage.api.network.Network;
import com.refinedmods.refinedstorage.api.network.NetworkComponent;
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.autocrafting.Pattern;
import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.refinedmods.refinedstorage.common.api.autocrafting;

import com.refinedmods.refinedstorage.api.autocrafting.Pattern;

import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.Storage;
import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType;

import java.util.List;
import java.util.Set;

import net.minecraft.server.level.ServerPlayer;
import org.apiguardian.api.API;
Expand All @@ -24,5 +26,7 @@ public interface Grid {

List<TrackedResourceAmount> getResources(Class<? extends Actor> actorType);

Set<PlatformResourceKey> getCraftableResources();

GridOperations createOperations(ResourceType resourceType, ServerPlayer player);
}
Loading
Loading