-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0cf95b6
Showing
35 changed files
with
1,913 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.gradle/ | ||
.nb-gradle/ | ||
.settings/ | ||
build/ | ||
eclipse/ | ||
.classpath | ||
.nb-gradle-properties | ||
.project | ||
*.launch | ||
run/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
out/ | ||
/bin/ | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright © 2020 Refined Mods | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the “Software”), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Refined Storage 2 | ||
|
||
The next generation of Refined Storage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
plugins { | ||
id 'fabric-loom' version '0.5-SNAPSHOT' | ||
} | ||
|
||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
archivesBaseName = 'core' | ||
group = 'com.refinedmods.refinedstorage2' | ||
version = '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
minecraft 'com.mojang:minecraft:1.16.3' | ||
mappings 'net.fabricmc:yarn:1.16.3+build.17:v2' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.6.1' | ||
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.encoding = 'UTF-8' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.jvmargs=-Xmx1G |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/com/refinedmods/refinedstorage2/core/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.refinedmods.refinedstorage2.core; | ||
|
||
public enum Action { | ||
SIMULATE, | ||
EXECUTE | ||
} |
27 changes: 27 additions & 0 deletions
27
core/src/main/java/com/refinedmods/refinedstorage2/core/adapter/MinecraftWorldAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.refinedmods.refinedstorage2.core.adapter; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.Optional; | ||
|
||
public class MinecraftWorldAdapter implements WorldAdapter { | ||
private final World world; | ||
private final WorldIdentifier identifier; | ||
|
||
public MinecraftWorldAdapter(World world) { | ||
this.world = world; | ||
this.identifier = new MinecraftWorldIdentifier(world); | ||
} | ||
|
||
@Override | ||
public Optional<BlockEntity> getBlockEntity(BlockPos pos) { | ||
return Optional.ofNullable(world.getBlockEntity(pos)); | ||
} | ||
|
||
@Override | ||
public WorldIdentifier getIdentifier() { | ||
return identifier; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
.../src/main/java/com/refinedmods/refinedstorage2/core/adapter/MinecraftWorldIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.refinedmods.refinedstorage2.core.adapter; | ||
|
||
import net.minecraft.util.Identifier; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.Objects; | ||
|
||
public class MinecraftWorldIdentifier implements WorldIdentifier { | ||
private final Identifier identifier; | ||
|
||
public MinecraftWorldIdentifier(World world) { | ||
this.identifier = world.getRegistryKey().getValue(); | ||
} | ||
|
||
@Override | ||
public Identifier getId() { | ||
return identifier; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MinecraftWorldIdentifier that = (MinecraftWorldIdentifier) o; | ||
return identifier.equals(that.identifier); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(identifier); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/main/java/com/refinedmods/refinedstorage2/core/adapter/WorldAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.refinedmods.refinedstorage2.core.adapter; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.util.Optional; | ||
|
||
public interface WorldAdapter { | ||
Optional<BlockEntity> getBlockEntity(BlockPos pos); | ||
|
||
WorldIdentifier getIdentifier(); | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/com/refinedmods/refinedstorage2/core/adapter/WorldIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.refinedmods.refinedstorage2.core.adapter; | ||
|
||
import net.minecraft.util.Identifier; | ||
|
||
public interface WorldIdentifier { | ||
Identifier getId(); | ||
} |
55 changes: 55 additions & 0 deletions
55
core/src/main/java/com/refinedmods/refinedstorage2/core/graph/BlockEntityGraphScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.refinedmods.refinedstorage2.core.graph; | ||
|
||
import com.refinedmods.refinedstorage2.core.adapter.WorldAdapter; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.HashSet; | ||
import java.util.Queue; | ||
import java.util.Set; | ||
|
||
public class BlockEntityGraphScanner<T extends BlockEntity> implements GraphScanner<T> { | ||
private final Class<T> blockEntityClass; | ||
|
||
public BlockEntityGraphScanner(Class<T> blockEntityClass) { | ||
this.blockEntityClass = blockEntityClass; | ||
} | ||
|
||
@Override | ||
public GraphScannerResult<T> scanAt(WorldAdapter worldAdapter, BlockPos pos, Set<GraphEntry<T>> previousEntries) { | ||
Set<GraphEntry<T>> allEntries = new HashSet<>(); | ||
Set<GraphEntry<T>> removedEntries = new HashSet<>(previousEntries); | ||
Set<GraphEntry<T>> newEntries = new HashSet<>(); | ||
|
||
Queue<GraphScannerRequest> requests = new ArrayDeque<>(); | ||
requests.add(new GraphScannerRequest(worldAdapter, pos)); | ||
|
||
GraphScannerRequest request; | ||
while ((request = requests.poll()) != null) { | ||
handleRequest(allEntries, removedEntries, newEntries, request, requests); | ||
} | ||
|
||
return new GraphScannerResult<>(newEntries, removedEntries, allEntries); | ||
} | ||
|
||
private void handleRequest(Set<GraphEntry<T>> allEntries, Set<GraphEntry<T>> previousEntries, Set<GraphEntry<T>> newEntries, GraphScannerRequest request, Queue<GraphScannerRequest> requests) { | ||
request.getWorldAdapter().getBlockEntity(request.getPos()).ifPresent(blockEntity -> { | ||
if (blockEntity.getClass().isAssignableFrom(blockEntityClass)) { | ||
GraphEntry<T> entry = new GraphEntry<>(request.getWorldAdapter().getIdentifier(), request.getPos(), (T) blockEntity); | ||
|
||
if (allEntries.add(entry)) { | ||
for (Direction direction : Direction.values()) { | ||
requests.add(new GraphScannerRequest(request.getWorldAdapter(), request.getPos().offset(direction))); | ||
} | ||
|
||
boolean entryExistedPreviously = previousEntries.remove(entry); | ||
if (!entryExistedPreviously) { | ||
newEntries.add(entry); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/src/main/java/com/refinedmods/refinedstorage2/core/graph/GraphEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.refinedmods.refinedstorage2.core.graph; | ||
|
||
import com.refinedmods.refinedstorage2.core.adapter.WorldIdentifier; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.util.Objects; | ||
|
||
public class GraphEntry<T> { | ||
private final WorldIdentifier worldIdentifier; | ||
private final BlockPos pos; | ||
private final T element; | ||
|
||
public GraphEntry(WorldIdentifier worldIdentifier, BlockPos pos, T element) { | ||
this.worldIdentifier = worldIdentifier; | ||
this.pos = pos; | ||
this.element = element; | ||
} | ||
|
||
public WorldIdentifier getWorldIdentifier() { | ||
return worldIdentifier; | ||
} | ||
|
||
public BlockPos getPos() { | ||
return pos; | ||
} | ||
|
||
public T getElement() { | ||
return element; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GraphEntry<?> that = (GraphEntry<?>) o; | ||
return worldIdentifier.equals(that.worldIdentifier) && pos.equals(that.pos) && element.equals(that.element); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(worldIdentifier, pos, element); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/java/com/refinedmods/refinedstorage2/core/graph/GraphScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.refinedmods.refinedstorage2.core.graph; | ||
|
||
import com.refinedmods.refinedstorage2.core.adapter.WorldAdapter; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public interface GraphScanner<T> { | ||
GraphScannerResult<T> scanAt(WorldAdapter worldAdapter, BlockPos pos, Set<GraphEntry<T>> previousEntries); | ||
|
||
default GraphScannerResult<T> scanAt(WorldAdapter worldAdapter, BlockPos pos) { | ||
return scanAt(worldAdapter, pos, Collections.emptySet()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/java/com/refinedmods/refinedstorage2/core/graph/GraphScannerRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.refinedmods.refinedstorage2.core.graph; | ||
|
||
import com.refinedmods.refinedstorage2.core.adapter.WorldAdapter; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
class GraphScannerRequest { | ||
private final WorldAdapter worldAdapter; | ||
private final BlockPos pos; | ||
|
||
GraphScannerRequest(WorldAdapter worldAdapter, BlockPos pos) { | ||
this.worldAdapter = worldAdapter; | ||
this.pos = pos; | ||
} | ||
|
||
public WorldAdapter getWorldAdapter() { | ||
return worldAdapter; | ||
} | ||
|
||
public BlockPos getPos() { | ||
return pos; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
core/src/main/java/com/refinedmods/refinedstorage2/core/graph/GraphScannerResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.refinedmods.refinedstorage2.core.graph; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class GraphScannerResult<T> { | ||
private final Set<GraphEntry<T>> newEntries; | ||
private final Set<GraphEntry<T>> removedEntries; | ||
private final Set<GraphEntry<T>> allEntries; | ||
|
||
public GraphScannerResult(Set<GraphEntry<T>> newEntries, Set<GraphEntry<T>> removedEntries, Set<GraphEntry<T>> allEntries) { | ||
this.newEntries = Collections.unmodifiableSet(newEntries); | ||
this.removedEntries = Collections.unmodifiableSet(removedEntries); | ||
this.allEntries = Collections.unmodifiableSet(allEntries); | ||
} | ||
|
||
public Set<GraphEntry<T>> getNewEntries() { | ||
return newEntries; | ||
} | ||
|
||
public Set<GraphEntry<T>> getRemovedEntries() { | ||
return removedEntries; | ||
} | ||
|
||
public Set<GraphEntry<T>> getAllEntries() { | ||
return allEntries; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/com/refinedmods/refinedstorage2/core/list/StackList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.refinedmods.refinedstorage2.core.list; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface StackList<T> { | ||
StackListResult<T> add(T template, int amount); | ||
|
||
Optional<StackListResult<T>> remove(T template, int amount); | ||
|
||
Optional<ItemStack> get(T template); | ||
|
||
Optional<ItemStack> get(UUID id); | ||
|
||
Collection<T> getAll(); | ||
} |
27 changes: 27 additions & 0 deletions
27
core/src/main/java/com/refinedmods/refinedstorage2/core/list/StackListResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.refinedmods.refinedstorage2.core.list; | ||
|
||
import java.util.UUID; | ||
|
||
public class StackListResult<T> { | ||
private final T stack; | ||
private final int change; | ||
private final UUID id; | ||
|
||
public StackListResult(T stack, int change, UUID id) { | ||
this.stack = stack; | ||
this.change = change; | ||
this.id = id; | ||
} | ||
|
||
public T getStack() { | ||
return stack; | ||
} | ||
|
||
public int getChange() { | ||
return change; | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
} |
Oops, something went wrong.