Skip to content

Commit

Permalink
chore: remove test update code
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Dec 29, 2024
1 parent 4abaaa0 commit fe2b28f
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ public interface TaskStatusProvider {
void cancel(TaskId taskId);

void cancelAll();

void testUpdate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ public void removed(final Player removedPlayer) {
}
}

@Override
public void broadcastChanges() {
super.broadcastChanges();
if (autocraftingMonitor != null) {
autocraftingMonitor.testUpdate();
}
}

void setListener(@Nullable final AutocraftingMonitorListener listener) {
this.listener = listener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ public void cancelAll() {
getAutocrafting().ifPresent(AutocraftingNetworkComponent::cancelAll);
}

@Override
public void testUpdate() {
getAutocrafting().ifPresent(AutocraftingNetworkComponent::testUpdate);
}

@Override
public void addWatcher(final AutocraftingMonitorWatcher watcher) {
watchers.add(watcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,16 @@
import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus;
import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusListener;
import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusProvider;
import com.refinedmods.refinedstorage.common.support.resource.ItemResource;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;

import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

public class TaskStatusProviderImpl implements TaskStatusProvider {
private static final Item[] ITEM_SET = new Item[] {
Items.DIRT,
Items.DIAMOND,
Items.GOLD_INGOT,
Items.ACACIA_WOOD,
Items.BEEHIVE
};

private final List<TaskStatus> statuses = new ArrayList<>();
private final Set<TaskStatusListener> listeners = new HashSet<>();
private final Random r = new Random();
private int ticks;

@Override
public List<TaskStatus> getStatuses() {
Expand Down Expand Up @@ -65,58 +48,4 @@ public void cancelAll() {
statuses.clear();
copy.forEach(s -> listeners.forEach(l -> l.taskRemoved(s.info().id())));
}

@Override
public void testUpdate() {
if (ticks++ % 10 != 0) {
return;
}
final int chance = r.nextInt(100);
if (chance < 50 && statuses.size() < 100) {
final TaskStatus status = generateTaskStatus();
statuses.add(status);
listeners.forEach(l -> l.taskAdded(status));
} else if (chance < 85 && !statuses.isEmpty()) {
final int idx = r.nextInt(statuses.size());
final TaskStatus status = statuses.get(idx);
final TaskStatus updated = new TaskStatus(
status.info(),
r.nextFloat(),
generateTaskStatus().items()
);
statuses.set(idx, updated);
listeners.forEach(l -> l.taskStatusChanged(updated));
} else if (chance > 85 && !statuses.isEmpty()) {
final int idx = r.nextInt(statuses.size());
final TaskStatus status = statuses.remove(idx);
listeners.forEach(l -> l.taskRemoved(status.info().id()));
}
}

private TaskStatus generateTaskStatus() {
final TaskStatus.TaskInfo taskInfo = new TaskStatus.TaskInfo(
new TaskId(UUID.randomUUID()),
ItemResource.ofItemStack(new ItemStack(ITEM_SET[r.nextInt(ITEM_SET.length)])),
5 + r.nextLong(32),
System.currentTimeMillis()
);
final float pct = r.nextFloat();
final List<TaskStatus.Item> items = new ArrayList<>();
for (int i = 0; i < 3 + r.nextInt(30); i++) {
final int typeIdx = r.nextInt(TaskStatus.ItemType.values().length);
final TaskStatus.ItemType type = TaskStatus.ItemType.values()[typeIdx];
final int idx = r.nextInt(5);
final int amount = 2 + r.nextInt(20);
items.add(new TaskStatus.Item(
type,
ItemResource.ofItemStack(new ItemStack(ITEM_SET[r.nextInt(ITEM_SET.length)])),
idx == 0 ? amount : 0,
idx == 1 ? amount : 0,
idx == 2 ? amount : 0,
idx == 3 ? amount : 0,
idx == 4 ? amount : 0
));
}
return new TaskStatus(taskInfo, pct, items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,4 @@ public void cancelAll() {
);
});
}

@Override
public void testUpdate() {
getAutocrafting().ifPresent(AutocraftingNetworkComponent::testUpdate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ public void cancelAll() {
taskStatusProvider.cancelAll();
}

@Override
public void testUpdate() {
taskStatusProvider.testUpdate();
}

private class ParentContainerImpl implements ParentContainer {
@Override
public void add(final Pattern pattern, final int priority) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void taskAdded(final TaskStatus status) {
sut.getStatuses();
sut.cancel(new TaskId(UUID.randomUUID()));
sut.cancelAll();
sut.testUpdate();
}

@Test
Expand Down

0 comments on commit fe2b28f

Please sign in to comment.