Skip to content

Commit

Permalink
feat: add transmitting icon for wireless transmitter and network tran…
Browse files Browse the repository at this point in the history
…smitter

The wireless transmitter can now also display "inactive".
  • Loading branch information
raoulvdberge committed Aug 10, 2024
1 parent 71d332b commit 8e3b1f2
Show file tree
Hide file tree
Showing 38 changed files with 195 additions and 68 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Changed

- Updated to Minecraft 1.21.1.
- The Network Transmitter and Wireless Transmitter GUI now has an inactive and active GUI animation.
- The Wireless Transmitter now shows whether it's inactive in GUI instead of always showing the range.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.refinedmods.refinedstorage.common.importer.ImporterScreen;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterScreen;
import com.refinedmods.refinedstorage.common.networking.RelayScreen;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterScreen;
import com.refinedmods.refinedstorage.common.security.FallbackSecurityCardScreen;
import com.refinedmods.refinedstorage.common.security.SecurityCardScreen;
import com.refinedmods.refinedstorage.common.security.SecurityManagerScreen;
Expand All @@ -36,7 +37,6 @@
import com.refinedmods.refinedstorage.common.support.resource.ItemResource;
import com.refinedmods.refinedstorage.common.support.resource.ItemResourceRendering;
import com.refinedmods.refinedstorage.common.upgrade.RegulatorUpgradeScreen;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterScreen;

import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@
import com.refinedmods.refinedstorage.common.importer.ImporterContainerMenu;
import com.refinedmods.refinedstorage.common.misc.ProcessorItem;
import com.refinedmods.refinedstorage.common.misc.WrenchItem;
import com.refinedmods.refinedstorage.common.networking.BaseWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.networking.CreativeRangeUpgradeWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.networking.NetworkCardItem;
import com.refinedmods.refinedstorage.common.networking.NetworkReceiverBlockEntity;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterBlockEntity;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterContainerMenu;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterData;
import com.refinedmods.refinedstorage.common.networking.RangeUpgradeWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.networking.RelayBlockEntity;
import com.refinedmods.refinedstorage.common.networking.RelayContainerMenu;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterBlockEntity;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterContainerMenu;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterData;
import com.refinedmods.refinedstorage.common.security.BuiltinPermission;
import com.refinedmods.refinedstorage.common.security.FallbackSecurityCardContainerMenu;
import com.refinedmods.refinedstorage.common.security.PlatformSecurityNetworkComponentImpl;
Expand Down Expand Up @@ -141,12 +147,6 @@
import com.refinedmods.refinedstorage.common.upgrade.SimpleUpgradeItem;
import com.refinedmods.refinedstorage.common.upgrade.UpgradeDestinations;
import com.refinedmods.refinedstorage.common.upgrade.UpgradeWithEnchantedBookRecipeSerializer;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.BaseWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.CreativeRangeUpgradeWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.RangeUpgradeWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterBlockEntity;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterContainerMenu;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterData;

import java.util.Optional;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.refinedmods.refinedstorage.common.grid.strategy.CompositeGridExtractionStrategy;
import com.refinedmods.refinedstorage.common.grid.strategy.CompositeGridInsertionStrategy;
import com.refinedmods.refinedstorage.common.grid.strategy.CompositeGridScrollingStrategy;
import com.refinedmods.refinedstorage.common.networking.CompositeWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.storage.ClientStorageRepository;
import com.refinedmods.refinedstorage.common.storage.StorageContainerItemHelperImpl;
import com.refinedmods.refinedstorage.common.storage.StorageRepositoryImpl;
Expand All @@ -80,7 +81,6 @@
import com.refinedmods.refinedstorage.common.upgrade.UpgradeRegistryImpl;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;
import com.refinedmods.refinedstorage.common.util.ServerEventQueue;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.CompositeWirelessTransmitterRangeModifier;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.refinedmods.refinedstorage.common.networking.NetworkReceiverBlockEntity;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterBlockEntity;
import com.refinedmods.refinedstorage.common.networking.RelayBlockEntity;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterBlockEntity;
import com.refinedmods.refinedstorage.common.security.SecurityManagerBlockEntity;
import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant;
Expand All @@ -25,7 +26,6 @@
import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockBlockEntity;
import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorBlockEntity;
import com.refinedmods.refinedstorage.common.support.network.BaseNetworkNodeContainerBlockEntity;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterBlockEntity;

import java.util.EnumMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.refinedmods.refinedstorage.common.networking.NetworkReceiverBlock;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterBlock;
import com.refinedmods.refinedstorage.common.networking.RelayBlock;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterBlock;
import com.refinedmods.refinedstorage.common.security.SecurityManagerBlock;
import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant;
Expand All @@ -32,7 +33,6 @@
import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorBlock;
import com.refinedmods.refinedstorage.common.support.BaseBlockItem;
import com.refinedmods.refinedstorage.common.support.SimpleBlock;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterBlock;

import java.util.EnumMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.refinedmods.refinedstorage.common.importer.ImporterContainerMenu;
import com.refinedmods.refinedstorage.common.networking.NetworkTransmitterContainerMenu;
import com.refinedmods.refinedstorage.common.networking.RelayContainerMenu;
import com.refinedmods.refinedstorage.common.networking.WirelessTransmitterContainerMenu;
import com.refinedmods.refinedstorage.common.security.FallbackSecurityCardContainerMenu;
import com.refinedmods.refinedstorage.common.security.SecurityCardContainerMenu;
import com.refinedmods.refinedstorage.common.security.SecurityManagerContainerMenu;
Expand All @@ -25,7 +26,6 @@
import com.refinedmods.refinedstorage.common.storage.storageblock.ItemStorageBlockContainerMenu;
import com.refinedmods.refinedstorage.common.storagemonitor.StorageMonitorContainerMenu;
import com.refinedmods.refinedstorage.common.upgrade.RegulatorUpgradeContainerMenu;
import com.refinedmods.refinedstorage.common.wirelesstransmitter.WirelessTransmitterContainerMenu;

import java.util.function.Supplier;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeState;
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeState;
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class NetworkTransmitterBlockEntity
private static final Logger LOGGER = LoggerFactory.getLogger(NetworkTransmitterBlockEntity.class);

private static final NetworkTransmitterData INACTIVE = NetworkTransmitterData.message(
false,
createTranslation("gui", "network_transmitter.status.inactive")
);
private static final NetworkTransmitterData MISSING_NETWORK_CARD = NetworkTransmitterData.error(
Expand Down Expand Up @@ -138,7 +139,7 @@ NetworkTransmitterData getStatus() {
"gui",
"network_transmitter.status.transmitting",
receiverKey.getDistance(worldPosition)) : receiverKey.getDimensionName();
return NetworkTransmitterData.message(message);
return NetworkTransmitterData.message(true, message);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void broadcastChanges() {
return;
}
final NetworkTransmitterData newStatus = blockEntity.getStatus();
if (newStatus.message().equals(status.message())) {
if (newStatus.equals(status)) {
return;
}
updateStatus(serverPlayer, newStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

public record NetworkTransmitterData(boolean error, Component message) {
public record NetworkTransmitterData(boolean error, boolean transmitting, Component message) {
public static final StreamCodec<RegistryFriendlyByteBuf, NetworkTransmitterData> STREAM_CODEC =
StreamCodec.composite(
ByteBufCodecs.BOOL, NetworkTransmitterData::error,
ByteBufCodecs.BOOL, NetworkTransmitterData::transmitting,
ComponentSerialization.STREAM_CODEC, NetworkTransmitterData::message,
NetworkTransmitterData::new
);

static NetworkTransmitterData error(final Component message) {
return new NetworkTransmitterData(true, message);
return new NetworkTransmitterData(true, false, message);
}

static NetworkTransmitterData message(final Component message) {
return new NetworkTransmitterData(false, message);
static NetworkTransmitterData message(final boolean transmitting, final Component message) {
return new NetworkTransmitterData(false, transmitting, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
public class NetworkTransmitterScreen extends AbstractBaseScreen<NetworkTransmitterContainerMenu> {
private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/network_transmitter.png");

private final TransmittingIcon icon;

public NetworkTransmitterScreen(final NetworkTransmitterContainerMenu menu,
final Inventory playerInventory,
final Component text) {
super(menu, playerInventory, text);
this.inventoryLabelY = 42;
this.imageWidth = 176;
this.imageHeight = 137;
this.icon = new TransmittingIcon(isIconActive());
}

@Override
Expand All @@ -31,15 +34,31 @@ protected void init() {
addSideButton(new RedstoneModeSideButtonWidget(getMenu().getProperty(PropertyTypes.REDSTONE_MODE)));
}

@Override
protected void containerTick() {
super.containerTick();
icon.tick(isIconActive());
}

private boolean isIconActive() {
return !getMenu().getStatus().error() && getMenu().getStatus().transmitting();
}

@Override
protected void renderBg(final GuiGraphics graphics, final float delta, final int mouseX, final int mouseY) {
super.renderBg(graphics, delta, mouseX, mouseY);
icon.render(graphics, leftPos + 29, topPos + 22);
}

@Override
protected void renderLabels(final GuiGraphics graphics, final int mouseX, final int mouseY) {
super.renderLabels(graphics, mouseX, mouseY);
final NetworkTransmitterData status = getMenu().getStatus();
final int displayTextX = 51;
final int x = 25 + 4 + icon.getWidth() + 4;
if (status.error()) {
graphics.blitSprite(WARNING, displayTextX, 23, WARNING_SIZE, WARNING_SIZE);
graphics.blitSprite(WARNING, x, 23, WARNING_SIZE, WARNING_SIZE);
}
graphics.drawString(font, status.message(), displayTextX + (status.error() ? (10 + 4) : 0), 25, 4210752, false);
graphics.drawString(font, status.message(), x + (status.error() ? (10 + 4) : 0), 25, 4210752, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeState;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.refinedmods.refinedstorage.common.networking;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;

import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier;

class TransmittingIcon {
private static final int WIDTH_0 = 11;
private static final int WIDTH_3 = 20;
private static final int TRANSMITTING_FRAMES = 20;
private static final ResourceLocation NOT_TRANSMITTING = createIdentifier("transmitting/0");
private static final ResourceLocation TRANSMITTING_1 = createIdentifier("transmitting/1");
private static final ResourceLocation TRANSMITTING_2 = createIdentifier("transmitting/2");
private static final ResourceLocation TRANSMITTING_3 = createIdentifier("transmitting/3");

private int frames;
private int cycle;
private boolean active;

TransmittingIcon(final boolean active) {
this.active = active;
}

void tick(final boolean newActive) {
this.active = newActive;
doTick();
}

private void doTick() {
if (!active) {
frames = 0;
cycle = 0;
return;
}
++frames;
if (frames == TRANSMITTING_FRAMES) {
frames = 0;
cycle++;
}
}

void render(final GuiGraphics graphics, final int x3, final int y3) {
if (!active) {
graphics.blitSprite(NOT_TRANSMITTING, x3, y3 + 4, WIDTH_0, 4);
return;
}
final int frame = cycle % 3;
switch (frame) {
case 0:
graphics.blitSprite(TRANSMITTING_1, x3, y3 + 3, 14, 6);
break;
case 1:
graphics.blitSprite(TRANSMITTING_2, x3, y3 + 1, 17, 10);
break;
case 2:
graphics.blitSprite(TRANSMITTING_3, x3, y3, WIDTH_3, 12);
break;
}
}

int getWidth() {
return active ? WIDTH_3 : WIDTH_0;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.content.BlockColorMap;
import com.refinedmods.refinedstorage.common.content.BlockConstants;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.api.network.impl.node.SimpleNetworkNode;
import com.refinedmods.refinedstorage.common.Platform;
Expand Down Expand Up @@ -95,7 +95,7 @@ public AbstractContainerMenu createMenu(final int syncId, final Inventory invent

@Override
public WirelessTransmitterData getMenuData() {
return new WirelessTransmitterData(getRange());
return new WirelessTransmitterData(getRange(), isActive());
}

@Override
Expand Down Expand Up @@ -127,4 +127,8 @@ protected boolean doesBlockStateChangeWarrantNetworkNodeUpdate(final BlockState
final BlockState newBlockState) {
return AbstractDirectionalBlock.doesBlockStateChangeWarrantNetworkNodeUpdate(oldBlockState, newBlockState);
}

boolean isActive() {
return mainNetworkNode.isActive();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.common.wirelesstransmitter;
package com.refinedmods.refinedstorage.common.networking;

import com.refinedmods.refinedstorage.common.api.support.network.ConnectionSink;
import com.refinedmods.refinedstorage.common.support.network.ColoredConnectionStrategy;
Expand Down
Loading

0 comments on commit 8e3b1f2

Please sign in to comment.