Skip to content

Commit

Permalink
don't variable client
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Dec 7, 2024
1 parent 8c5b63d commit 58a49ba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.util.Identifier;

import java.util.HashMap;
import java.util.Objects;

public class GlobalCollection {
int totalPlayers;
Expand All @@ -31,8 +32,7 @@ public HashMap<Identifier, Integer> collectionTracker() {
);

public int getCount(Identifier shard) {
Integer count = collectionTracker.get(shard);
return count != null ? count : 0;
return Objects.requireNonNullElse(collectionTracker.get(shard), 0);
}

public void update(Identifier shard, int change, int playerCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ public static void triggerShardModificationToast(Identifier shardId, boolean suc
}

public static void openShardTablet() {
final MinecraftClient client = MinecraftClient.getInstance();
client.send(() -> {
MinecraftClient.getInstance().send(() -> {
final ShardLibrary library = ScatteredShardsAPI.getClientLibrary();
final ShardCollection collection = ScatteredShardsAPI.getClientCollection();

client.setScreen(new ShardTabletGuiDescription.Screen(collection, library));
client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.ITEM_BOOK_PAGE_TURN, 1.0f, 1.0f));
MinecraftClient.getInstance().setScreen(new ShardTabletGuiDescription.Screen(collection, library));
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.ITEM_BOOK_PAGE_TURN, 1.0f, 1.0f));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -51,7 +50,6 @@ public static int view(CommandContext<FabricClientCommandSource> context) throws
if (shardPackSet.isEmpty()) {
throw INVALID_SET_ID.create(id);
}
MinecraftClient client = context.getSource().getClient();
ShardCollection shardCollection = ScatteredShardsAPI.getClientCollection();
ShardLibrary fakeLibrary = new ShardLibraryImpl();
MiniRegistry<Shard> realShardRegistry = realLibrary.shards();
Expand All @@ -67,7 +65,7 @@ public static int view(CommandContext<FabricClientCommandSource> context) throws
}
realLibrary.shardTypes().forEach((fakeShardTypes::put));
fakeLibrary.shardDisplaySettings().copyFrom(realLibrary.shardDisplaySettings());
client.send(() -> client.setScreen(new ShardTabletGuiDescription.Screen(shardCollection, fakeLibrary)));
context.getSource().getClient().send(() -> context.getSource().getClient().setScreen(new ShardTabletGuiDescription.Screen(shardCollection, fakeLibrary)));
return Command.SINGLE_SUCCESS;
}

Expand All @@ -77,8 +75,7 @@ public static int creatorNew(CommandContext<FabricClientCommandSource> context)
ShardType shardType = ScatteredShardsAPI.getClientLibrary().shardTypes().get(shardTypeId)
.orElseThrow(() -> ShardCommand.INVALID_SHARD_TYPE.create(shardTypeId));

MinecraftClient client = context.getSource().getClient();
client.send(() -> client.setScreen(ShardCreatorGuiDescription.Screen.newShard(modId, shardType)));
context.getSource().getClient().send(() -> context.getSource().getClient().setScreen(ShardCreatorGuiDescription.Screen.newShard(modId, shardType)));
return Command.SINGLE_SUCCESS;
}

Expand All @@ -87,16 +84,14 @@ public static int creatorEdit(CommandContext<FabricClientCommandSource> context)
Shard shard = ScatteredShardsAPI.getClientLibrary().shards().get(shardId)
.orElseThrow(() -> INVALID_SHARD_ID.create(shardId));

MinecraftClient client = context.getSource().getClient();
client.send(() -> client.setScreen(ShardCreatorGuiDescription.Screen.editShard(shard)));
context.getSource().getClient().send(() -> context.getSource().getClient().setScreen(ShardCreatorGuiDescription.Screen.editShard(shard)));
return Command.SINGLE_SUCCESS;
}

public static int shards(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
MinecraftClient client = context.getSource().getClient();
ShardLibrary library = ScatteredShardsAPI.getClientLibrary();
ShardCollection collection = ScatteredShardsAPI.getClientCollection();
client.send(() -> client.setScreen(new ShardTabletGuiDescription.Screen(collection, library)));
context.getSource().getClient().send(() -> context.getSource().getClient().setScreen(new ShardTabletGuiDescription.Screen(collection, library)));
return Command.SINGLE_SUCCESS;
}

Expand Down Expand Up @@ -129,7 +124,7 @@ public static CompletableFuture<Suggestions> suggestModIds(CommandContext<Fabric
}

private static LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
return LiteralArgumentBuilder.<FabricClientCommandSource>literal(name);
return LiteralArgumentBuilder.literal(name);
}

private static RequiredArgumentBuilder<FabricClientCommandSource, Identifier> identifierArgument(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {

@Override
public void paintScaled(DrawContext context, int width, int height, int mouseX, int mouseY) {
MinecraftClient mc = MinecraftClient.getInstance();
TextRenderer renderer = mc.textRenderer;
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
int yOffset = switch (verticalAlignment) {
case CENTER -> height / 2 - renderer.fontHeight / 2;
case BOTTOM -> height - renderer.fontHeight;
case CENTER -> height / 2 - textRenderer.fontHeight / 2;
case BOTTOM -> height - textRenderer.fontHeight;
case TOP -> 0;
};

Expand All @@ -116,9 +115,8 @@ public void paintScaled(DrawContext context, int width, int height, int mouseX,
}

public static void drawScrollableString(DrawContext context, OrderedText text, HorizontalAlignment alignment, int x, int y, int width, int color, boolean shadow, boolean scroll) {
MinecraftClient mc = MinecraftClient.getInstance();
TextRenderer font = mc.textRenderer;
int textWidth = font.getWidth(text);
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
int textWidth = textRenderer.getWidth(text);
int xofs = 0;

if (textWidth > width && scroll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {

@Override
public void paintScaled(DrawContext context, int width, int height, int mouseX, int mouseY) {
MinecraftClient mc = MinecraftClient.getInstance();
TextRenderer renderer = mc.textRenderer;
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
int frameColor = color.getAsInt();
List<OrderedText> lines = renderer.wrapLines(text.get(), width);
List<OrderedText> lines = textRenderer.wrapLines(text.get(), width);

int totalHeight = renderer.fontHeight * lines.size();
int totalHeight = textRenderer.fontHeight * lines.size();

int yOffset = switch (verticalAlignment) {
case CENTER -> height / 2 - totalHeight / 2;
Expand All @@ -113,7 +112,7 @@ public void paintScaled(DrawContext context, int width, int height, int mouseX,
};

for (int i = 0; i < lines.size(); i++) {
int lineY = renderer.fontHeight * i;
int lineY = textRenderer.fontHeight * i;
if (shadow) {
ScreenDrawing.drawStringWithShadow(context, lines.get(i), horizontalAlignment, 0, yOffset + lineY, width, frameColor);
} else {
Expand Down

0 comments on commit 58a49ba

Please sign in to comment.