Skip to content

Commit

Permalink
feat: relay gametest
Browse files Browse the repository at this point in the history
  • Loading branch information
starforcraft committed Dec 14, 2024
1 parent 2691d8f commit 1afd1ba
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected boolean doesBlockStateChangeWarrantNetworkNodeUpdate(final BlockState
public AutocrafterManagerData getMenuData() {
return new AutocrafterManagerData(
getGroups().stream().map(AutocrafterManagerData.Group::of).toList(),
isActive()
mainNetworkNode.isActive()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public void removeWatcher(final AutocraftingMonitorWatcher watcher) {

@Override
public boolean isAutocraftingMonitorActive() {
return isActive();
return mainNetworkNode.isActive();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public AbstractContainerMenu createMenu(final int syncId, final Inventory invent
@Override
public void updateActiveness(final BlockState state, @Nullable final BooleanProperty activenessProperty) {
super.updateActiveness(state, activenessProperty);
final boolean powered = isActive() && mainNetworkNode.isActivated();
final boolean powered = mainNetworkNode.isActive() && mainNetworkNode.isActivated();
final boolean needToUpdatePowered = state.getValue(DetectorBlock.POWERED) != powered;
if (level != null && needToUpdatePowered && poweredChangeTicks++ % POWERED_CHANGE_TICK_RATE == 0) {
level.setBlockAndUpdate(getBlockPos(), state.setValue(DetectorBlock.POWERED, powered));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public GridOperations createOperations(final ResourceType resourceType, final Se

@Override
public boolean isGridActive() {
return isActive();
return mainNetworkNode.isActive();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public final NonNullList<ItemStack> getDrops() {
}

private Optional<Network> getNetwork() {
if (!isActive()) {
if (!mainNetworkNode.isActive()) {
return Optional.empty();
}
return Optional.ofNullable(mainNetworkNode.getNetwork());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected InWorldNetworkNodeContainer createMainContainer(final SimpleNetworkNod
@Override
public void addOutgoingConnections(final ConnectionSink sink) {
super.addOutgoingConnections(sink);
if (receiverKey != null && NetworkTransmitterBlockEntity.this.isActive()) {
if (receiverKey != null && NetworkTransmitterBlockEntity.this.mainNetworkNode.isActive()) {
sink.tryConnect(receiverKey.pos());
}
}
Expand All @@ -108,7 +108,7 @@ public void updateStateInLevel(final BlockState state) {
}

private NetworkTransmitterState calculateState() {
if (!isActive()) {
if (!mainNetworkNode.isActive()) {
return NetworkTransmitterState.INACTIVE;
}
if (receiverKey == null) {
Expand All @@ -124,7 +124,7 @@ private NetworkTransmitterState calculateState() {

NetworkTransmitterData getStatus() {
final Network network = mainNetworkNode.getNetwork();
if (!isActive() || network == null || level == null) {
if (!mainNetworkNode.isActive() || network == null || level == null) {
return INACTIVE;
}
if (receiverKey == null) {
Expand All @@ -145,7 +145,7 @@ NetworkTransmitterData getStatus() {
@Override
public void doWork() {
super.doWork();
if (!isActive() || mainNetworkNode.getNetwork() == null || receiverKey == null) {
if (!mainNetworkNode.isActive() || mainNetworkNode.getNetwork() == null || receiverKey == null) {
return;
}
final boolean receiverFound = isReceiverFoundInNetwork(mainNetworkNode.getNetwork(), receiverKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ boolean isFuzzyMode() {
}

void setFuzzyMode(final boolean fuzzyMode) {
final boolean wasActive = isActive();
final boolean wasActive = mainNetworkNode.isActive();
// Updating fuzzy mode will call the filter's listener as the normalizer will yield different outputs.
// However, when updating a filter the storage resets and "self-removes". If the normalizer yields different
// outputs too early, the self-remove operation will partially fail as the expected resources will be different.
Expand Down Expand Up @@ -191,7 +191,7 @@ void setPassThrough(final boolean passThrough) {
}

boolean isActiveInternal() {
return isActive();
return mainNetworkNode.isActive();
}

Direction getDirectionInternal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,8 @@ protected boolean doesBlockStateChangeWarrantNetworkNodeUpdate(final BlockState
final BlockState newBlockState) {
return AbstractDirectionalBlock.didDirectionChange(oldBlockState, newBlockState);
}

boolean isActive() {
return mainNetworkNode.isActive();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void doWork() {

private void trySendDisplayUpdate(final Level level) {
final long amount = getAmount();
final boolean active = isActive();
final boolean active = mainNetworkNode.isActive();
if ((amount != currentAmount || active != currentlyActive) && displayUpdateRateLimiter.tryAcquire()) {
sendDisplayUpdate(level, amount, active);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ private void sendDisplayUpdate() {
if (level == null) {
return;
}
sendDisplayUpdate(level, getAmount(), isActive());
sendDisplayUpdate(level, getAmount(), mainNetworkNode.isActive());
}

private void sendDisplayUpdate(final Level level, final long amount, final boolean active) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,9 @@ protected boolean calculateActive() {
&& mainNetworkNode.getNetwork().getComponent(EnergyNetworkComponent.class).getStored() >= energyUsage;
}

public boolean isActive() {
return mainNetworkNode.isActive();
}

public void updateActiveness(final BlockState state, @Nullable final BooleanProperty activenessProperty) {
final boolean newActive = calculateActive();
final boolean nodeActivenessNeedsUpdate = newActive != isActive();
final boolean nodeActivenessNeedsUpdate = newActive != mainNetworkNode.isActive();
final boolean blockStateActivenessNeedsUpdate = activenessProperty != null
&& state.getValue(activenessProperty) != newActive;
final boolean activenessNeedsUpdate = nodeActivenessNeedsUpdate || blockStateActivenessNeedsUpdate;
Expand All @@ -106,7 +102,7 @@ protected void activenessChanged(final boolean newActive) {
LOGGER.debug(
"Activeness change for node at {}: {} -> {}",
getBlockPos(),
isActive(),
mainNetworkNode.isActive(),
newActive
);
mainNetworkNode.setActive(newActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static void checkBlockEntityActiveness(final GameTestHelper helper,
pos,
AbstractBaseNetworkNodeContainerBlockEntity.class
);
final boolean actualActive = blockEntity.isActive();
final boolean actualActive = blockEntity.getBlockState().getValue(AbstractActiveColoredDirectionalBlock.ACTIVE);
helper.assertTrue(actualActive == expectedActive, "Activeness of Block Entity should be " + expectedActive
+ " but is " + actualActive);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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 gridPos, GameTestSequence gameTestSequence);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.QuadConsumer;
import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant;

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

import static com.refinedmods.refinedstorage.common.GameTestUtil.RSBLOCKS;
import static com.refinedmods.refinedstorage.common.GameTestUtil.requireBlockEntity;
Expand All @@ -18,7 +16,7 @@ private RelayTestPlots() {
}

static void preparePlot(final GameTestHelper helper,
final QuadConsumer<RelayBlockEntity, BlockPos, BlockPos, GameTestSequence> consumer) {
final RelayConsumer consumer) {
helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault());
helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K));
helper.setBlock(
Expand Down

0 comments on commit 1afd1ba

Please sign in to comment.