Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic NFC Modem functionality for Pocket Computer #1689

Open
wants to merge 6 commits into
base: mc-1.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dan200.computercraft.shared.network.client.PocketComputerDeletedClientMessage;
import dan200.computercraft.shared.network.server.ServerNetworking;
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
import dan200.computercraft.shared.pocket.peripherals.PocketNFCPeripheral;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -33,6 +34,7 @@

public class PocketServerComputer extends ServerComputer implements IPocketAccess {
private @Nullable IPocketUpgrade upgrade;
private final PocketNFCPeripheral nfc = new PocketNFCPeripheral(this);
private @Nullable Entity entity;
private ItemStack stack = ItemStack.EMPTY;

Expand Down Expand Up @@ -142,6 +144,9 @@ public synchronized void updateValues(@Nullable Entity entity, ItemStack stack,
this.entity = entity;
this.stack = stack;

if (getPeripheral(ComputerSide.TOP) != nfc) setPeripheral(ComputerSide.TOP, nfc);
nfc.update(this);

if (this.upgrade != upgrade) {
this.upgrade = upgrade;
invalidatePeripheral();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dan200.computercraft.shared.pocket.peripherals;

import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.pocket.IPocketAccess;

import javax.annotation.Nullable;

public class PocketNFCPeripheral extends PocketModemPeripheral {

public PocketNFCPeripheral(IPocketAccess access) {
super(false, access);
}

public void update(IPocketAccess access) {
setLocation(access);

var state = getModemState();
if (state.pollChanged()) access.setLight(state.isOpen() ? 0xf39d20 : -1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traditionally only main peripherals set light status. This might look odd if this one and back peripheral will both try to set different colours.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, not sure how to address it though. Color blending? Blinking between the two colors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5c67b6c is my attempt at addressing this, the light slowly cycles between the two active colors

}

@Override
public double getRange() {
return 0;
}

@Override
public boolean equals(@Nullable IPeripheral other) {
return other instanceof PocketNFCPeripheral;
}
}
Loading