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

Relay gametest #748

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public RelayBlockEntity(final BlockPos pos, final BlockState state) {
this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters(
ResourceContainerImpl.createForFilter(),
this::setChanged,
this::filterContainerChanged
this::setFilters
);
this.mainNetworkNode.setFilterNormalizer(filter.createNormalizer());
this.containers.addContainer(
Expand All @@ -98,7 +98,7 @@ void setFuzzyMode(final boolean fuzzyMode) {
mainNetworkNode.setActive(wasActive);
}

private void filterContainerChanged(final Set<ResourceKey> filters) {
void setFilters(final Set<ResourceKey> filters) {
mainNetworkNode.setFilters(filters);
setChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.network.Network;
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
Expand All @@ -17,13 +17,16 @@
import com.refinedmods.refinedstorage.common.content.Items;
import com.refinedmods.refinedstorage.common.iface.ExportedResourcesContainer;
import com.refinedmods.refinedstorage.common.iface.InterfaceBlockEntity;
import com.refinedmods.refinedstorage.common.support.AbstractActiveColoredDirectionalBlock;
import com.refinedmods.refinedstorage.common.support.network.AbstractBaseNetworkNodeContainerBlockEntity;
import com.refinedmods.refinedstorage.common.support.resource.FluidResource;
import com.refinedmods.refinedstorage.common.support.resource.ItemResource;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.annotation.Nullable;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -71,6 +74,19 @@ public static Runnable networkIsAvailable(final GameTestHelper helper,
};
}

public static void checkBlockEntityActiveness(final GameTestHelper helper,
final BlockPos pos,
final boolean expectedActive) {
final var blockEntity = requireBlockEntity(
helper,
pos,
AbstractBaseNetworkNodeContainerBlockEntity.class
);
final boolean actualActive = blockEntity.getBlockState().getValue(AbstractActiveColoredDirectionalBlock.ACTIVE);
helper.assertTrue(actualActive == expectedActive, "Activeness of Block Entity should be " + expectedActive
+ " but is " + actualActive);
}

public static void insert(final GameTestHelper helper,
final Network network,
final Item resource,
Expand Down Expand Up @@ -229,14 +245,25 @@ private static Runnable assertResourceContainerEmpty(final Component displayName
};
}

public static Runnable energyStoredExactly(final EnergyStorage storage,
final long energyAmount) {
return () -> {
if (storage.getStored() != energyAmount) {
throw new GameTestAssertException("Energy stored should be: " + energyAmount
+ " but is " + storage.getStored());
}
};
public static Runnable checkEnergyInNetwork(final GameTestHelper helper,
final BlockPos pos,
final Function<Long, Long> storedConsumer) {
return networkIsAvailable(helper, pos, network -> {
final EnergyNetworkComponent energyComponent = network.getComponent(EnergyNetworkComponent.class);

long storedEnergy = energyComponent.getStored();
storedEnergy = storedConsumer.apply(storedEnergy);

energyStoredExactly(storedEnergy, energyComponent.getCapacity());
});
}

public static void energyStoredExactly(final long storedEnergy,
final long energyAmount) {
if (storedEnergy != energyAmount) {
throw new GameTestAssertException("Energy stored should be: " + energyAmount
+ " but is " + storedEnergy);
}
}

public static Runnable interfaceContainsExactly(final GameTestHelper helper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public static void shouldConsumeEnergy(final GameTestHelper helper) {
// Assert
sequence
.thenIdle(20)
.thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity()))
.thenExecute(() -> energyStoredExactly(energyStorage.getStored(), energyStorage.getCapacity()))
.thenWaitUntil(() -> helper.setBlock(pos.above(), RSBLOCKS.getGrid().getDefault()))
.thenIdle(1)
.thenExecute(energyStoredExactly(
energyStorage,
.thenExecute(() -> energyStoredExactly(
energyStorage.getStored(),
energyStorage.getCapacity() - Platform.INSTANCE.getConfig().getGrid().getEnergyUsage()
))
.thenIdle(9)
.thenExecute(energyStoredExactly(
energyStorage,
.thenExecute(() -> energyStoredExactly(
energyStorage.getStored(),
energyStorage.getCapacity() - Platform.INSTANCE.getConfig().getGrid().getEnergyUsage() * 10
))
.thenSucceed();
Expand All @@ -62,10 +62,10 @@ public static void shouldNotConsumeEnergy(final GameTestHelper helper) {
// Assert
sequence
.thenIdle(20)
.thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity()))
.thenExecute(() -> energyStoredExactly(energyStorage.getStored(), energyStorage.getCapacity()))
.thenWaitUntil(() -> helper.setBlock(pos.above(), RSBLOCKS.getGrid().getDefault()))
.thenIdle(20)
.thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity()))
.thenExecute(() -> energyStoredExactly(energyStorage.getStored(), energyStorage.getCapacity()))
.thenSucceed();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.refinedmods.refinedstorage.common.networking;

import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTestSequence;

@FunctionalInterface
public interface RelayConsumer {
void accept(RelayBlockEntity relayBlockEntity,
BlockPos pos,
BlockPos subnetworkPos,
GameTestSequence gameTestSequence);
}
Loading
Loading