Skip to content

Commit

Permalink
feat: security card energy usage
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Apr 2, 2024
1 parent 8f18bd5 commit 0278b41
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface SecurityPolicyContainerItem {
* @return the policy, if present
*/
Optional<SecurityPolicy> getPolicy(ItemStack stack);

long getEnergyUsage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface Config {
boolean isSmoothScrolling();

int getMaxRowsStretch();

GridEntry getGrid();

CraftingGridEntry getCraftingGrid();
Expand Down Expand Up @@ -60,6 +60,10 @@ public interface Config {

PortableGridEntry getPortableGrid();

SimpleEnergyUsageEntry getSecurityCard();

SimpleEnergyUsageEntry getFallbackSecurityCard();

SimpleEnergyUsageEntry getSecurityManager();

interface SimpleEnergyUsageEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public final class DefaultEnergyUsage {
public static final long RANGE_UPGRADE = 8;
public static final long CREATIVE_RANGE_UPGRADE = 0;
public static final int RANGE_UPGRADE_RANGE = 8;
public static final long SECURITY_CARD = 2;
public static final long FALLBACK_SECURITY_CARD = 4;

public static final long WIRELESS_GRID_CAPACITY = 1000;
public static final long WIRELESS_GRID_OPEN = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverKey.getDimensionName;
import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation;

// TODO: energy usage per card in the security manager.
public class NetworkCardItem extends Item {
private static final MutableComponent UNBOUND_HELP = createTranslation("item", "network_card.unbound_help");
private static final MutableComponent BOUND_HELP = createTranslation("item", "network_card.bound_help");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission;
import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference;
import com.refinedmods.refinedstorage2.platform.common.Platform;

import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -40,4 +41,9 @@ public Optional<TooltipComponent> getTooltipImage(final ItemStack stack) {
public Optional<SecurityActor> getActor(final ItemStack stack) {
return Optional.empty();
}

@Override
public long getEnergyUsage() {
return Platform.INSTANCE.getConfig().getFallbackSecurityCard().getEnergyUsage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission;
import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference;
import com.refinedmods.refinedstorage2.platform.common.Platform;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -101,6 +102,11 @@ public Optional<SecurityActor> getActor(final ItemStack stack) {
return Optional.of(new PlayerSecurityActor(playerId));
}

@Override
public long getEnergyUsage() {
return Platform.INSTANCE.getConfig().getSecurityCard().getEnergyUsage();
}

@Nullable
UUID getBoundPlayerId(final ItemStack stack) {
return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_ID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,27 @@ public SecurityManagerBlockEntity(final BlockPos pos, final BlockState state) {
state,
new SimpleNetworkNode(Platform.INSTANCE.getConfig().getSecurityManager().getEnergyUsage())
);
securityCards.addListener(c -> setChanged());
fallbackSecurityCard.addListener(c -> setChanged());
securityCards.addListener(c -> invalidate());
fallbackSecurityCard.addListener(c -> invalidate());
}

private void invalidate() {
if (level != null) {
setChanged();
}
long energyUsage = Platform.INSTANCE.getConfig().getSecurityManager().getEnergyUsage();
for (int i = 0; i < securityCards.getContainerSize(); ++i) {
final ItemStack securityCard = securityCards.getItem(i);
if (!(securityCard.getItem() instanceof SecurityPolicyContainerItem securityPolicyContainerItem)) {
continue;
}
energyUsage += securityPolicyContainerItem.getEnergyUsage();
}
final ItemStack fallbackSecurityCardStack = fallbackSecurityCard.getItem(0);
if (fallbackSecurityCardStack.getItem() instanceof SecurityPolicyContainerItem securityPolicyContainerItem) {
energyUsage += securityPolicyContainerItem.getEnergyUsage();
}
getNode().setEnergyUsage(energyUsage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@
"text.autoconfig.refinedstorage2.option.portableGrid.openEnergyUsage": "Open energy usage",
"text.autoconfig.refinedstorage2.option.portableGrid.insertEnergyUsage": "Insert energy usage",
"text.autoconfig.refinedstorage2.option.portableGrid.extractEnergyUsage": "Extract energy usage",
"text.autoconfig.refinedstorage2.option.securityCard": "Security Card",
"text.autoconfig.refinedstorage2.option.securityCard.energyUsage": "Energy usage",
"text.autoconfig.refinedstorage2.option.fallbackSecurityCard": "Fallback Security Card",
"text.autoconfig.refinedstorage2.option.fallbackSecurityCard.energyUsage": "Energy usage",
"text.autoconfig.refinedstorage2.option.securityManager": "Security Manager",
"text.autoconfig.refinedstorage2.option.securityManager.energyUsage": "Energy usage",
"advancements.refinedstorage2.root.description": "Use one or multiple Controllers in a storage network to provide your network with energy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage2.p

@ConfigEntry.BoundedDiscrete(min = 3L, max = 256)
private int maxRowsStretch = 256;

@ConfigEntry.Gui.CollapsibleObject
private GridEntryImpl grid = new GridEntryImpl();

Expand Down Expand Up @@ -95,6 +95,14 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage2.p
@ConfigEntry.Gui.CollapsibleObject
private PortableGridEntryImpl portableGrid = new PortableGridEntryImpl();

@ConfigEntry.Gui.CollapsibleObject
private SimpleEnergyUsageEntryImpl securityCard = new SimpleEnergyUsageEntryImpl(DefaultEnergyUsage.SECURITY_CARD);

@ConfigEntry.Gui.CollapsibleObject
private SimpleEnergyUsageEntryImpl fallbackSecurityCard = new SimpleEnergyUsageEntryImpl(
DefaultEnergyUsage.FALLBACK_SECURITY_CARD
);

@ConfigEntry.Gui.CollapsibleObject
private SimpleEnergyUsageEntryImpl securityManager = new SimpleEnergyUsageEntryImpl(
DefaultEnergyUsage.SECURITY_MANAGER
Expand Down Expand Up @@ -230,6 +238,16 @@ public PortableGridEntry getPortableGrid() {
return portableGrid;
}

@Override
public SimpleEnergyUsageEntry getSecurityCard() {
return securityCard;
}

@Override
public SimpleEnergyUsageEntry getFallbackSecurityCard() {
return fallbackSecurityCard;
}

@Override
public SimpleEnergyUsageEntry getSecurityManager() {
return securityManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ConfigImpl implements Config {
private final SimpleEnergyUsageEntry networkReceiver;
private final SimpleEnergyUsageEntry networkTransmitter;
private final PortableGridEntry portableGrid;
private final SimpleEnergyUsageEntry securityCard;
private final SimpleEnergyUsageEntry fallbackSecurityCard;
private final SimpleEnergyUsageEntry securityManager;

public ConfigImpl() {
Expand Down Expand Up @@ -92,6 +94,16 @@ public ConfigImpl() {
DefaultEnergyUsage.NETWORK_TRANSMITTER
);
portableGrid = new PortableGridEntryImpl();
securityCard = new SimpleEnergyUsageEntryImpl(
"securityCard",
"Security Card",
DefaultEnergyUsage.SECURITY_CARD
);
fallbackSecurityCard = new SimpleEnergyUsageEntryImpl(
"fallbackSecurityCard",
"Fallback Security Card",
DefaultEnergyUsage.FALLBACK_SECURITY_CARD
);
securityManager = new SimpleEnergyUsageEntryImpl(
"securityManager",
"Security Manager",
Expand Down Expand Up @@ -229,6 +241,16 @@ public PortableGridEntry getPortableGrid() {
return portableGrid;
}

@Override
public SimpleEnergyUsageEntry getSecurityCard() {
return securityCard;
}

@Override
public SimpleEnergyUsageEntry getFallbackSecurityCard() {
return fallbackSecurityCard;
}

@Override
public SimpleEnergyUsageEntry getSecurityManager() {
return securityManager;
Expand Down

0 comments on commit 0278b41

Please sign in to comment.