Skip to content

Commit

Permalink
Fix Sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Jul 24, 2022
1 parent cd55249 commit 5161975
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,48 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel<St
);
}

@Test
void shouldRespectAllowlistWithNormalizer(
@InjectNetworkStorageChannel final StorageChannel<String> storageChannel
) {
// Arrange
sut.setFilterMode(FilterMode.ALLOW);
sut.setFilterTemplates(Set.of("A"));
sut.setNormalizer(value -> value instanceof String str && str.startsWith("A") ? "A" : value);

storageChannel.addSource(new InMemoryStorageImpl<>());

final FakeImporterSource source = new FakeImporterSource("B", "A1", "A2")
.add("B", 10)
.add("A1", 1)
.add("A2", 1);

final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl<>(
source,
NetworkTestFixtures.STORAGE_CHANNEL_TYPE,
10
);
sut.setTransferStrategy(strategy);

// Act
sut.update();
// cooldown
sut.update();
sut.update();
sut.update();
// Act 2
sut.update();

// Assert
assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder(
new ResourceAmount<>("A1", 1),
new ResourceAmount<>("A2", 1)
);
assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly(
new ResourceAmount<>("B", 10)
);
}

@Test
void shouldRespectAllowlistWithoutAlternative(
@InjectNetworkStorageChannel final StorageChannel<String> storageChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public <T> ClientProperty<T> getProperty(final PropertyType<T> type) {
}

public void receivePropertyChangeFromClient(final ResourceLocation id, final int newValue) {
for (final PropertyType<?> type : propertyMap.keySet()) {
if (type.id().equals(id)) {
((ServerProperty<?>) propertyMap.get(type)).set(newValue);
for (final Map.Entry<PropertyType<?>, Property<?>> entry : propertyMap.entrySet()) {
final PropertyType<?> type = entry.getKey();
if (!type.id().equals(id)) {
continue;
}
final Property<?> property = entry.getValue();
((ServerProperty<?>) property).set(newValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class PropertyTypes {

public static final PropertyType<Boolean> EXACT_MODE = new PropertyType<>(
createIdentifier("exact_mode"),
value -> value ? 1 : 0,
value -> Boolean.TRUE.equals(value) ? 1 : 0,
value -> value == 1
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ protected AbstractStorageBlockContainerMenu(final MenuType<?> type,
this.stored = buf.readLong();
this.capacity = buf.readLong();

addSlots(player, new FilteredResourceFilterContainer(
PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, () -> {
}, resourceType));
addSlots(
player,
new FilteredResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, resourceType)
);

initializeResourceFilterSlots(buf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public DiskDriveContainerMenu(final int syncId, final Inventory playerInventory,
addSlots(
playerInventory.player,
new SimpleContainer(DiskDriveNetworkNode.DISK_COUNT),
new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, () -> {
})
new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9)
);

initializeResourceFilterSlots(buf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
public class FilteredResourceFilterContainer extends ResourceFilterContainer {
private final ResourceType allowedType;

public FilteredResourceFilterContainer(final OrderedRegistry<ResourceLocation, ResourceType> resourceTypeRegistry,
final int size,
final ResourceType allowedType) {
this(resourceTypeRegistry, size, () -> {
}, allowedType);
}

public FilteredResourceFilterContainer(final OrderedRegistry<ResourceLocation, ResourceType> resourceTypeRegistry,
final int size,
final Runnable listener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private List<Component> calculateTooltip(final boolean exactMode) {

@Override
protected int getXTexture() {
return property.getValue() ? 0 : 16;
return Boolean.TRUE.equals(property.getValue()) ? 0 : 16;
}

@Override
Expand All @@ -52,7 +52,7 @@ protected int getYTexture() {
public void onTooltip(final Button button, final PoseStack poseStack, final int mouseX, final int mouseY) {
tooltipRenderer.render(
poseStack,
property.getValue() ? tooltipWhenOn : tooltipWhenOff,
Boolean.TRUE.equals(property.getValue()) ? tooltipWhenOn : tooltipWhenOff,
mouseX,
mouseY
);
Expand Down

0 comments on commit 5161975

Please sign in to comment.