Skip to content

Commit

Permalink
Merge branch 'chore/relocate-tools' of https://github.com/Team-EnderI…
Browse files Browse the repository at this point in the history
…O/EnderIO into chore/relocate-tools
  • Loading branch information
Rover656 committed Nov 15, 2023
2 parents a02e7ef + 3095f0f commit e537d8b
Show file tree
Hide file tree
Showing 147 changed files with 1,586 additions and 461 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ij_java_case_statement_on_separate_line = true
ij_java_catch_on_new_line = false
ij_java_class_annotation_wrap = split_into_lines
ij_java_class_brace_style = end_of_line
ij_java_class_count_to_use_import_on_demand = 5
ij_java_class_count_to_use_import_on_demand = 9999
ij_java_class_names_in_javadoc = 1
ij_java_do_not_indent_top_level_class_members = false
ij_java_do_not_wrap_after_single_annotation = true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ Update your `build.gradle` to contain the following:

```groovy
repositories {
maven { url 'https://maven.tterrag.com' }
maven { url 'https://maven.rover656.dev/releases' }
}
dependencies {
// Include Ender IO API for compilation
compileOnly fg.deobf("com.enderio:EnderIO:<VERSION>:api")
// Use EnderIO at runtime
runtimeOnly fg.deobf("com.enderio.EnderIO:<VERSION>")
runtimeOnly fg.deobf("com.enderio:EnderIO:<VERSION>")
}
```
If you need any feature in the api, contact us.
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ plugins {
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id "me.hypherionmc.modutils.modpublisher" version "1.+"
id 'checkstyle'
}

apply plugin: 'org.spongepowered.mixin'
Expand Down Expand Up @@ -262,6 +261,9 @@ dependencies {
// Jade
runtimeOnly fg.deobf("curse.maven:jade-324717:${jade_cf_id}")

//fluxnetworks
runtimeOnly fg.deobf("curse.maven:fluxnetworks-248020:4651164")

//Flywheel
compileOnly fg.deobf("com.jozufozu.flywheel:flywheel-forge-1.20.1:0.6.9-5") // REMOVE When crash is fixed

Expand Down
3 changes: 2 additions & 1 deletion src/api/java/com/enderio/api/conduit/IConduitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ default boolean canBeReplacedBy(IConduitType<?> other) {

T createExtendedConduitData(Level level, BlockPos pos);

default <K> Optional<LazyOptional<K>> proxyCapability(Capability<K> cap, T extendedConduitData, @Nullable Direction direction) {
default <K> Optional<LazyOptional<K>> proxyCapability(Capability<K> cap, T extendedConduitData, Level level, BlockPos pos, @Nullable Direction direction,
Optional<NodeIdentifier.IOState> state) {
return Optional.empty();
}

Expand Down
59 changes: 25 additions & 34 deletions src/conduits/java/com/enderio/conduits/common/ConduitShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private <T> T getLookUpValue(Map<T, VoxelShape> shapes, BlockPos pos, HitResult

private void updateTotalShape() {
this.totalShape = Shapes.empty();
this.conduitShapes.values().forEach(s -> this.totalShape = Shapes.join(this.totalShape, s, BooleanOp.OR));
this.conduitShapes.values().forEach(s -> this.totalShape = Shapes.joinUnoptimized(this.totalShape, s, BooleanOp.OR));
totalShape.optimize();
}

Expand All @@ -94,8 +94,8 @@ private void updateShapeForConduit(ConduitBundle conduitBundle, IConduitType<?>
VoxelShape directionShape = directionShapes.getOrDefault(direction, Shapes.empty());
if (conduitBundle.getConnection(direction).getConnectionState(conduitType) instanceof DynamicConnectionState) {
VoxelShape connectorShape = rotateVoxelShape(CONNECTOR, direction);
directionShape = Shapes.join(directionShape, connectorShape, BooleanOp.OR);
conduitShape = Shapes.join(conduitShape, connectorShape, BooleanOp.OR);
directionShape = Shapes.joinUnoptimized(directionShape, connectorShape, BooleanOp.OR);
conduitShape = Shapes.joinUnoptimized(conduitShape, connectorShape, BooleanOp.OR);
}
var connectedTypes = conduitBundle.getConnection(direction).getConnectedTypes();
if (connectedTypes.contains(conduitType)) {
Expand All @@ -104,68 +104,56 @@ private void updateShapeForConduit(ConduitBundle conduitBundle, IConduitType<?>
offsets.computeIfAbsent(conduitType, ignored -> new ArrayList<>()).add(offset);
VoxelShape connectionShape = rotateVoxelShape(CONNECTION, direction).move(offset.getX() * 3f / 16f, offset.getY() * 3f / 16f,
offset.getZ() * 3f / 16f);
directionShape = Shapes.join(directionShape, connectionShape, BooleanOp.OR);
conduitShape = Shapes.join(conduitShape, connectionShape, BooleanOp.OR);
directionShape = Shapes.joinUnoptimized(directionShape, connectionShape, BooleanOp.OR);
conduitShape = Shapes.joinUnoptimized(conduitShape, connectionShape, BooleanOp.OR);
}
directionShapes.put(direction, directionShape.optimize());
}

var allTypes = conduitBundle.getTypes();
@Nullable Area box = null;
Map<IConduitType<?>, Integer> notRendered = new HashMap<>();
List<IConduitType<?>> rendered = new ArrayList<>();
@Nullable IConduitType<?> notRendered = null;
int i = allTypes.indexOf(conduitType);
if (i == -1) {
conduitShapes.put(conduitType, Shapes.block());
return;
}

var type = allTypes.get(i);
@Nullable List<Vec3i> offsetsForType = offsets.get(type);
if (offsetsForType != null) {
//all are pointing to the same xyz reference meaning that we can draw the core
if (offsetsForType.stream().distinct().count() == 1) {
rendered.add(type);
} else {
if (offsetsForType.stream().distinct().count() != 1) {
box = new Area(offsetsForType.toArray(new Vec3i[0]));
}
} else {
notRendered.put(type, i);
notRendered = type;
}

Set<Vec3i> duplicateFinder = new HashSet<>();
//rendered have only one distinct pos, so I can safely assume get(0) is valid
List<Vec3i> duplicatePositions = rendered.stream().map(offsets::get).map(l -> l.get(0)).filter(n -> !duplicateFinder.add(n)).toList();
for (Vec3i duplicatePosition : duplicatePositions) {
if (box == null) {
box = new Area(duplicatePosition);
} else {
box.makeContain(duplicatePosition);
}
}
for (IConduitType<?> toRender : rendered) {
if (box == null || !box.contains(offsetsForType.get(0))) {
conduitShape = Shapes.join(conduitShape,
CORE.move(offsetsForType.get(0).getX() * 3f / 16f, offsetsForType.get(0).getY() * 3f / 16f, offsetsForType.get(0).getZ() * 3f / 16f),
BooleanOp.OR);
}
if (offsetsForType != null && (box == null || !box.contains(offsetsForType.get(0)))) {
conduitShape = Shapes.joinUnoptimized(conduitShape,
CORE.move(offsetsForType.get(0).getX() * 3f / 16f, offsetsForType.get(0).getY() * 3f / 16f, offsetsForType.get(0).getZ() * 3f / 16f),
BooleanOp.OR);
}

if (box != null) {
for (Map.Entry<IConduitType<?>, Integer> notRenderedEntry : notRendered.entrySet()) {
Vec3i offset = OffsetHelper.translationFor(axis, OffsetHelper.offsetConduit(notRenderedEntry.getValue(), allTypes.size()));
if (notRendered != null) {
Vec3i offset = OffsetHelper.translationFor(axis, OffsetHelper.offsetConduit(i, allTypes.size()));
if (!box.contains(offset)) {
conduitShape = Shapes.join(conduitShape, CORE.move(offset.getX() * 3f / 16f, offset.getY() * 3f / 16f, offset.getZ() * 3f / 16f),
conduitShape = Shapes.joinUnoptimized(conduitShape, CORE.move(offset.getX() * 3f / 16f, offset.getY() * 3f / 16f, offset.getZ() * 3f / 16f),
BooleanOp.OR);
}
}
conduitShape = Shapes.join(conduitShape, CORE.move(box.getMin().getX() * 3f / 16f, box.getMin().getY() * 3f / 16f, box.getMin().getZ() * 3f / 16f),

conduitShape = Shapes.joinUnoptimized(conduitShape, CORE.move(box.getMin().getX() * 3f / 16f, box.getMin().getY() * 3f / 16f, box.getMin().getZ() * 3f / 16f),
BooleanOp.OR);
} else {
for (Map.Entry<IConduitType<?>, Integer> notRenderedEntry : notRendered.entrySet()) {
Vec3i offset = OffsetHelper.translationFor(axis, OffsetHelper.offsetConduit(notRenderedEntry.getValue(), allTypes.size()));
conduitShape = Shapes.join(conduitShape, CORE.move(offset.getX() * 3f / 16f, offset.getY() * 3f / 16f, offset.getZ() * 3f / 16f), BooleanOp.OR);
if (notRendered != null) {
Vec3i offset = OffsetHelper.translationFor(axis, OffsetHelper.offsetConduit(i, allTypes.size()));
conduitShape = Shapes.joinUnoptimized(conduitShape, CORE.move(offset.getX() * 3f / 16f, offset.getY() * 3f / 16f, offset.getZ() * 3f / 16f), BooleanOp.OR);
}
}

conduitShapes.put(conduitType, conduitShape.optimize());
}

Expand All @@ -185,14 +173,17 @@ public static VoxelShape rotateVoxelShape(VoxelShape toRotate, Direction directi
} else {
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(minX, minZ, minY, maxX, maxZ, maxY)));
}

return buffer[1];
}

for (int i = 0; i < (direction.get2DDataValue()) % 4; i++) {
buffer[0].forAllBoxes(
(minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = Shapes.empty();
}

return buffer[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,12 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory,
public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable Direction side) {
for (IConduitType<?> type : bundle.getTypes()) {
NodeIdentifier<?> node = bundle.getNodeFor(type);
Optional<NodeIdentifier.IOState> state = Optional.empty();
if (node != null && side != null) {
state = node.getIOState(side);
}
var proxiedCap = type.proxyCapability(cap,
node == null ? type.createExtendedConduitData(level, getBlockPos()).cast() : node.getExtendedConduitData().cast(), side);
node == null ? type.createExtendedConduitData(level, getBlockPos()).cast() : node.getExtendedConduitData().cast(), level, worldPosition, side, state);

if (proxiedCap.isPresent()) {
return proxiedCap.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public RightClickAction addType(Level level, IConduitType<?> type, Player player
}

//some conduit says no (like higher energy conduit)
if (types.stream().anyMatch(existingConduit -> !existingConduit.canBeInSameBlock(type))) {
if (types.stream().anyMatch(existingConduit -> !existingConduit.canBeInSameBlock(type) || !type.canBeInSameBlock(existingConduit))) {
return new RightClickAction.Blocked();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.enderio.EnderIO;
import com.enderio.api.conduit.IConduitMenuData;
import com.enderio.api.conduit.IConduitType;
import com.enderio.api.conduit.NodeIdentifier;
import com.enderio.api.conduit.TieredConduit;
import com.enderio.api.conduit.ticker.IConduitTicker;
import com.enderio.api.misc.ColorControl;
Expand Down Expand Up @@ -52,7 +53,7 @@ public AE2InWorldConduitNodeHost createExtendedConduitData(Level level, BlockPos
}

@Override
public <K> Optional<LazyOptional<K>> proxyCapability(Capability<K> cap, AE2InWorldConduitNodeHost extendedConduitData, @Nullable Direction direction) {
public <K> Optional<LazyOptional<K>> proxyCapability(Capability<K> cap, AE2InWorldConduitNodeHost extendedConduitData, Level level, BlockPos pos, @Nullable Direction direction, Optional<NodeIdentifier.IOState> state) {
if (getCapability() == cap) {
return Optional.of(extendedConduitData.selfCap.cast());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public static class Blocks {
private static void init() {}

public static final TagKey<Block> REDSTONE_CONNECTABLE = BlockTags.create(EnderIO.loc("redstone_connectable"));
public static final TagKey<Block> ENERGY_CABLE = BlockTags.create(EnderIO.loc("energy_cable"));
}
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,108 @@
package com.enderio.conduits.common.types;

import com.enderio.api.conduit.IConduitType;
import com.enderio.api.conduit.NodeIdentifier;
import com.enderio.api.conduit.ticker.CapabilityAwareConduitTicker;
import com.enderio.api.misc.ColorControl;
import com.enderio.conduits.common.tag.ConduitTags;
import dev.gigaherz.graph3.Graph;
import dev.gigaherz.graph3.Mergeable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.energy.IEnergyStorage;
import org.apache.commons.lang3.function.TriFunction;

import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

public class EnergyConduitTicker extends CapabilityAwareConduitTicker<IEnergyStorage> {

public EnergyConduitTicker() {
}

@Override
public void tickGraph(IConduitType<?> type, List<NodeIdentifier<?>> loadedNodes, ServerLevel level, Graph<Mergeable.Dummy> graph, TriFunction<ServerLevel, BlockPos, ColorControl, Boolean> isRedstoneActive) {
super.tickGraph(type, loadedNodes, level, graph, isRedstoneActive);
for (NodeIdentifier<?> node : loadedNodes) {
EnergyExtendedData energyExtendedData = node.getExtendedConduitData().castTo(EnergyExtendedData.class);
IEnergyStorage energy = energyExtendedData.selfCap
.resolve()
.orElseThrow();
if (energy.getEnergyStored() == 0) {
energyExtendedData.setCapacity(500);
continue;
}
int previousStored = energy.getEnergyStored();
for (NodeIdentifier<?> otherNode : loadedNodes) {
for (Direction dir: Direction.values()) {
if (otherNode.getIOState(dir).map(NodeIdentifier.IOState::isInsert).orElse(false)) {
BlockEntity be = level.getBlockEntity(otherNode.getPos().relative(dir));
if (be == null) {
continue;
}
Optional<IEnergyStorage> capability = be.getCapability(ForgeCapabilities.ENERGY, dir.getOpposite()).resolve();
if (capability.isPresent()) {
IEnergyStorage insert = capability.get();
extractEnergy(energy, List.of(insert), 0, i -> {});
}
}
}
}
if (energy.getEnergyStored() == 0) {
if (previousStored == energy.getMaxEnergyStored()) {
energyExtendedData.setCapacity(Math.min(1_000_000_000, 2 * energyExtendedData.getCapacity()));
} else if (previousStored < energyExtendedData.getCapacity() / 2) {
energyExtendedData.setCapacity(Math.max(500, energyExtendedData.getCapacity() / 2));
}
} else if (energy.getEnergyStored() > 0) {
energyExtendedData.setCapacity(Math.max(500, energy.getEnergyStored()));
}
}
}
@Override
public void tickCapabilityGraph(IConduitType<?> type, List<CapabilityConnection> inserts, List<CapabilityConnection> extracts, ServerLevel level,
Graph<Mergeable.Dummy> graph, TriFunction<ServerLevel, BlockPos, ColorControl, Boolean> isRedstoneActive) {

toNextExtract:

for (CapabilityConnection extract : extracts) {
IEnergyStorage extractHandler = extract.cap;
int availableForExtraction = extractHandler.extractEnergy(Integer.MAX_VALUE, true);
if (availableForExtraction <= 0) {
continue;
}

EnergyExtendedData.EnergySidedData sidedExtractData = extract.data.castTo(EnergyExtendedData.class).compute(extract.direction);
extractEnergy(extractHandler, inserts.stream().map(con -> con.cap).toList(), sidedExtractData.rotatingIndex, i -> sidedExtractData.rotatingIndex = i);
}
}

if (inserts.size() <= sidedExtractData.rotatingIndex) {
sidedExtractData.rotatingIndex = 0;
}
private void extractEnergy(IEnergyStorage extractHandler, List<IEnergyStorage> inserts, int startingIndex, Consumer<Integer> rotationIndexSetter) {

for (int j = sidedExtractData.rotatingIndex; j < sidedExtractData.rotatingIndex + inserts.size(); j++) {
int insertIndex = j % inserts.size();
CapabilityConnection insert = inserts.get(insertIndex);
int availableForExtraction = extractHandler.extractEnergy(Integer.MAX_VALUE, true);
if (availableForExtraction <= 0) {
return;
}

int inserted = insert.cap.receiveEnergy(availableForExtraction, false);
extractHandler.extractEnergy(inserted, false);
if (inserts.size() <= startingIndex) {
startingIndex = 0;
rotationIndexSetter.accept(0);
}

if (inserted == availableForExtraction) {
sidedExtractData.rotatingIndex += (insertIndex) + 1;
continue toNextExtract;
}
for (int j = startingIndex; j < startingIndex + inserts.size(); j++) {
int insertIndex = j % inserts.size();
IEnergyStorage insert = inserts.get(insertIndex);

availableForExtraction -= inserted;
int inserted = insert.receiveEnergy(availableForExtraction, false);
extractHandler.extractEnergy(inserted, false);

if (inserted == availableForExtraction) {
rotationIndexSetter.accept(startingIndex + (insertIndex) + 1);
return;
}

availableForExtraction -= inserted;
}
}

Expand All @@ -67,4 +119,9 @@ public int getTickRate() {
public Capability<IEnergyStorage> getCapability() {
return ForgeCapabilities.ENERGY;
}

@Override
public boolean canConnectTo(Level level, BlockPos conduitPos, Direction direction) {
return super.canConnectTo(level, conduitPos, direction) && !level.getBlockState(conduitPos.relative(direction)).is(ConduitTags.Blocks.ENERGY_CABLE);
}
}
Loading

0 comments on commit e537d8b

Please sign in to comment.