Skip to content

Commit

Permalink
fix: optimize indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Loqor committed Feb 23, 2025
1 parent 92f7b99 commit 0feeadb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 72 deletions.
12 changes: 0 additions & 12 deletions src/main/java/dev/amble/ait/client/boti/BOTI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import net.minecraft.client.render.*;
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.RotationAxis;
Expand Down Expand Up @@ -398,14 +396,4 @@ private static void copyDepth(Framebuffer src, Framebuffer dest) {
GlStateManager._glBindFramebuffer(GlConst.GL_DRAW_FRAMEBUFFER, dest.fbo);
GlStateManager._glBlitFrameBuffer(0, 0, src.textureWidth, src.textureHeight, 0, 0, dest.textureWidth, dest.textureHeight, GlConst.GL_DEPTH_BUFFER_BIT, GlConst.GL_NEAREST);
}

private static void sendNvidiaWarning() {
if (!warningSent) {
warningSent = true;

MinecraftClient.getInstance().player.sendMessage(Text.literal("An Nvidia Videocard is HIGHLY reccomended for the BOTI effect, the BOTI effect is very picky and sometimes will just not work with certain video cards.").formatted(Formatting.RED), false);
MinecraftClient.getInstance().player.sendMessage(Text.literal("If you have a videocard that is not Nvidia, please install the indium mod and disable I HATE GL in the ait config. This SHOULD fix BOTI being broken. ").formatted(Formatting.RED), false);
MinecraftClient.getInstance().player.sendMessage(Text.literal("MACS DO NOT WORK AS THEY DROPPED THAT SUPPORT IN FAVOR OF METAL").formatted(Formatting.RED), false);
}
}
}
20 changes: 6 additions & 14 deletions src/main/java/dev/amble/ait/client/screens/AstralMapScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,14 @@ public IdentifierSwitcher(List<Identifier> list, Consumer<Identifier> sync) {
}

private static IdentifierToName next(IdentifierToName id, List<Identifier> list) {
int index = list.indexOf(id.id()) + 1;

if (index >= list.size()) {
return new IdentifierToName(list.get(0));
}

return new IdentifierToName(list.get(index));
int idx = list.indexOf(id.id());
idx = (idx + 1) % list.size();
return new IdentifierToName(list.get(idx));
}
private static IdentifierToName prev(IdentifierToName id, List<Identifier> list) {
int index = list.indexOf(id.id()) - 1;

if (index < 0) {
return new IdentifierToName(list.get(list.size() - 1));
}

return new IdentifierToName(list.get(index));
int idx = list.indexOf(id.id());
idx = (idx - 1 + list.size()) % list.size();
return new IdentifierToName(list.get(idx));
}
}
}
20 changes: 8 additions & 12 deletions src/main/java/dev/amble/ait/client/screens/MonitorScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,16 @@ public ExteriorCategorySchema nextCategory() {
List<ExteriorCategorySchema> list = CategoryRegistry.getInstance().toList();

int idx = list.indexOf(getCategory());
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

public ExteriorCategorySchema previousCategory() {
List<ExteriorCategorySchema> list = CategoryRegistry.getInstance().toList();

int idx = list.indexOf(getCategory());
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1 + list.size()) % list.size();
return list.get(idx);
}

public void whichDirectionVariant(boolean direction) {
Expand All @@ -208,19 +206,17 @@ public ExteriorVariantSchema nextVariant() {
.stream().toList();

int idx = list.indexOf(getCurrentVariant().parent());
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

public ExteriorVariantSchema previousVariant() {
List<ExteriorVariantSchema> list = ExteriorVariantRegistry.withParent(getCurrentVariant().parent().category())
.stream().toList();

int idx = list.indexOf(getCurrentVariant().parent());
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1) % list.size();
return list.get(idx);
}

final int UV_BASE = 160;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,11 @@ protected void drawSonicScrewdriver(DrawContext context, int x, int y, float sca
}

public void getNextSelectedSonic() {
this.selectedSonic = this.selectedSonic + 1 >= SonicRegistry.getInstance().size() ? 0 : this.selectedSonic + 1;
this.selectedSonic = (this.selectedSonic + 1) % SonicRegistry.getInstance().size();
}

public void getLastSelectedSonic() {
this.selectedSonic = this.selectedSonic - 1 < 0
? SonicRegistry.getInstance().size() - 1
: this.selectedSonic - 1;
this.selectedSonic = (this.selectedSonic - 1 + SonicRegistry.getInstance().size()) % SonicRegistry.getInstance().size();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,8 @@ private static TardisDesktopSchema nextDesktop(TardisDesktopSchema current) {
List<TardisDesktopSchema> list = DesktopRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

private void nextDesktop() {
Expand All @@ -416,9 +415,8 @@ private static TardisDesktopSchema previousDesktop(TardisDesktopSchema current)
List<TardisDesktopSchema> list = DesktopRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1 + list.size()) % list.size();
return list.get(idx);
}

private void previousDesktop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,16 @@ private static Hum next(Hum current) {
List<Hum> list = HumRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

private static Hum previous(Hum current) {
List<Hum> list = HumRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1 + list.size()) % list.size();
return list.get(idx);
}

private static void sync(Hum current, ClientTardis tardis) {
Expand All @@ -96,18 +94,16 @@ private static VortexReference next(VortexReference current) {
List<VortexReference> list = VortexReferenceRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

private static VortexReference previous(VortexReference current) {
List<VortexReference> list = VortexReferenceRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1) % list.size();
return list.get(idx);
}

private static void sync(VortexReference current, ClientTardis tardis) {
Expand Down Expand Up @@ -140,9 +136,8 @@ private static TravelSound nextOfAnyState(TravelSound current) {
List<TravelSound> list = TravelSoundRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

private static TravelSound previous(TravelSound current, TravelHandlerBase.State target) {
Expand All @@ -158,9 +153,8 @@ private static TravelSound previousOfAnyState(TravelSound current) {
List<TravelSound> list = TravelSoundRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1) % list.size();
return list.get(idx);
}

private static void sync(TravelSound current, ClientTardis tardis) {
Expand All @@ -180,18 +174,16 @@ private static FlightSound next(FlightSound current) {
List<FlightSound> list = FlightSoundRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx < 0 || idx + 1 == list.size())
return list.get(0);
return list.get(idx + 1);
idx = (idx + 1) % list.size();
return list.get(idx);
}

private static FlightSound previous(FlightSound current) {
List<FlightSound> list = FlightSoundRegistry.getInstance().toList();

int idx = list.indexOf(current);
if (idx <= 0)
return list.get(list.size() - 1);
return list.get(idx - 1);
idx = (idx - 1) % list.size();
return list.get(idx);
}

private static void sync(FlightSound current, ClientTardis tardis) {
Expand Down

0 comments on commit 0feeadb

Please sign in to comment.