Skip to content

Commit

Permalink
Fixed an issue where the keyboard does not bound to the glasses when …
Browse files Browse the repository at this point in the history
…it was bound to different glasses before
  • Loading branch information
SirEndii committed Sep 26, 2024
1 parent b94b8be commit 9ba1214
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ public boolean isEnabled() {
@NotNull
@Override
public InteractionResult useOn(UseOnContext context) {
if (context.getPlayer() == null)
return InteractionResult.PASS;
if (context.getPlayer() == null) return InteractionResult.PASS;

if (SideHelper.isClientPlayer(context.getPlayer()))
return InteractionResult.PASS;
if (SideHelper.isClientPlayer(context.getPlayer())) return InteractionResult.PASS;

if (!context.getPlayer().isShiftKeyDown())
return InteractionResult.PASS;
if (!context.getPlayer().isShiftKeyDown()) return InteractionResult.PASS;

BlockEntity entity = context.getLevel().getBlockEntity(context.getClickedPos());
if (entity instanceof TileComputerBase) {
Expand All @@ -74,16 +71,21 @@ public InteractionResult useOn(UseOnContext context) {

@Override
public void inventoryTick(ItemStack itemStack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, @Nullable SmartGlassesAccess access, @Nullable IModule module) {
if (level.isClientSide())
return;
if (level.isClientSide()) return;

if (access == null) return;

CompoundTag data = itemStack.getOrCreateTag();
if (data.contains(BOUND_TYPE_TAG) && !data.getBoolean(BOUND_TYPE_TAG)) {
if (access != null) {
data.putBoolean(BOUND_TYPE_TAG, true);
data.putInt(GLASSES_BIND_TAG, access.getComputer().getInstanceID());
data.remove(BIND_TAG);
}
int instanceId = access.getComputer().getInstanceID();
int oldInstanceId = -1;

if (data.contains(GLASSES_BIND_TAG)) oldInstanceId = data.getInt(GLASSES_BIND_TAG);

if (!data.contains(BOUND_TYPE_TAG) || ((oldInstanceId != -1 && oldInstanceId != instanceId)) || !data.getBoolean(BOUND_TYPE_TAG)) {
data.putBoolean(BOUND_TYPE_TAG, true);
data.putInt(GLASSES_BIND_TAG, access.getComputer().getInstanceID());
data.remove(BIND_TAG);

}

if (KeybindUtil.isKeyPressed(KeyBindings.GLASSES_HOTKEY_KEYBINDING)) {
Expand Down

0 comments on commit 9ba1214

Please sign in to comment.