Skip to content

Commit

Permalink
v1.3-Pre4
Browse files Browse the repository at this point in the history
This is a pretty big change.

Changes:
- Additional code clean-up and documentation
- New icon for the backup button (a floppy disk)
- Toast notifications now use custom textures (with icons for backups and hotbar files)
- Added a keybind for backups: by default it's not set to anything so you'll need to bind it yourself
  • Loading branch information
VideoGameSmash12 committed Jun 25, 2021
1 parent 90fb053 commit 207c017
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 62 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.5
yarn_mappings=1.16.5+build.5
loader_version=0.11.2
# Mod Properties
mod_version=1.3-Pre3
mod_version=1.3-Pre4
maven_group=me.videogamesm12
archives_base_name=Hotbars+
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ public class MultiHotbarClient implements ClientModInitializer
public static final CommandManager commandManager = new CommandManager();
public static final ConfigurationManager configManager = new ConfigurationManager();
//
public static KeyBinding backup_binding;
public static KeyBinding next_binding;
public static KeyBinding previous_binding;

@Override
public void onInitializeClient()
{
backup_binding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.multihotbar.backup",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_UNKNOWN,
"category.multihotbar.navigation"
));

next_binding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.multihotbar.next",
InputUtil.Type.KEYSYM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ public int run(CommandContext<FabricClientCommandSource> context) throws Command
// This fixes the NPE caused when trying to make a backup of a file that does not exist.
if (!Util.hotbarFileExists())
{
context.getSource().sendFeedback(new TranslatableText("command.multihotbars.cant_backup_empty_hotbar_pages").formatted(Formatting.RED));
context.getSource().sendError(new TranslatableText("command.multihotbars.cant_backup_empty_hotbar_pages"));
return 2;
}

// Checks if a backup is already in progress beforehand.
if (Util.backupInProgress)
{
context.getSource().sendError(new TranslatableText("command.multihotbars.backup_in_progress"));
return 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public int run(CommandContext<FabricClientCommandSource> context) throws Command
{
// This prevents the page from going any higher than 9,223,372,036,854,775,807.
// Prevents issues caused by the number looping back to –9,223,372,036,854,775,808.
if (Util.getPage() == 9223372036854775807L)
if (Util.getPage() == Long.MAX_VALUE)
{
context.getSource().sendFeedback(new TranslatableText("command.multihotbars.reached_maximum_number").formatted(Formatting.RED));
context.getSource().sendError(new TranslatableText("command.multihotbars.reached_maximum_number"));
return 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public int run(CommandContext<FabricClientCommandSource> context) throws Command
// to double the capacity.
if (page < 0)
{
context.getSource().sendFeedback(new TranslatableText("command.multihotbars.goto_invalid_number", page).formatted(Formatting.RED));
context.getSource().sendError(new TranslatableText("command.multihotbars.goto_invalid_number", page));
return 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public int run(CommandContext<FabricClientCommandSource> context) throws Command
{
if (Util.getPage() <= 0)
{
context.getSource().sendFeedback(new TranslatableText("command.multihotbars.previous_back").formatted(Formatting.RED));
context.getSource().sendError(new TranslatableText("command.multihotbars.previous_back"));
return 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,23 @@ public class ClientTickListener implements ClientTickEvents.EndTick
@Override
public void onEndTick(MinecraftClient client)
{
// Backups
if (MultiHotbarClient.backup_binding.wasPressed())
{
Util.backupCurrentHotbar();

// Prevents the binding from doing multiple backups at once when pressing the key. This is a stupid way to
// do it that probably doesn't even work, but I couldn't find anything that handles when a key has been held.
MultiHotbarClient.backup_binding.setPressed(false);
}

// Next page
while (MultiHotbarClient.next_binding.wasPressed())
{
Util.nextPage();
}

// Previous page
while (MultiHotbarClient.previous_binding.wasPressed())
{
Util.previousPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemGroup;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -48,6 +50,11 @@ public abstract class CreativeInventoryScreenInjector extends AbstractInventoryS
public ButtonWidget backupButton;
public ButtonWidget nextButton;
public ButtonWidget prevButton;
//
public Text backupLabel = new LiteralText("\uD83D\uDCBE").setStyle(Style.EMPTY.withFont(
new Identifier("multihotbar", "default")));
public Text nextLabel = new LiteralText("→");
public Text prevLabel = new LiteralText("←");

public CreativeInventoryScreenInjector(CreativeInventoryScreen.CreativeScreenHandler screenHandler, PlayerInventory playerInventory, Text text)
{
Expand All @@ -64,22 +71,21 @@ public void injectInit(CallbackInfo ci)
int x = this.getX() + 159;
int y = this.getY() + 4;
//
prevButton = new ButtonWidget(x - 16, y, 16, 12, new LiteralText("←"), (buttonWidget) ->
prevButton = new ButtonWidget(x - 16, y, 16, 12, prevLabel, (buttonWidget) ->
{
Util.previousPage();
invokeSetSelectedTab(ItemGroup.HOTBAR);
});
//
// TODO: Figure out how to get custom text fonts to display correctly and replace this button's icon with a
// floppy disk (namely, this one: 💾) so that the button icon is more accurate
backupButton = new ButtonWidget(x, y, 16, 12, new LiteralText("✍"), (buttonWidget) ->
backupButton = new ButtonWidget(x, y, 16, 12, backupLabel, (buttonWidget) ->
{
if (!Util.backupInProgress)
{
Util.backupCurrentHotbar();
}
});
nextButton = new ButtonWidget(x + 16, y, 16, 12, new LiteralText("→"), (buttonWidget) ->
//
nextButton = new ButtonWidget(x + 16, y, 16, 12, nextLabel, (buttonWidget) ->
{
Util.nextPage();
invokeSetSelectedTab(ItemGroup.HOTBAR);
Expand Down Expand Up @@ -109,7 +115,7 @@ public void injectRenderHead(MatrixStack matrices, int mouseX, int mouseY, float
{
prevButton.active = Util.getPage() > 0;
backupButton.active = Util.hotbarFileExists() && !Util.backupInProgress;
nextButton.active = Util.getPage() != 9223372036854775807L;
nextButton.active = Util.getPage() != Long.MAX_VALUE;
//
prevButton.visible = true;
backupButton.visible = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void injectFile(Args args)
* Loading Injection - Calls the HotbarLoadFailCallback if the client fails to load the hotbar file.
* @param ci CallbackInfo
*/
@Inject(method = "load", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;error(Ljava/lang/String;Ljava/lang/Throwable;)V", shift = At.Shift.AFTER))
@Inject(method = "load", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;error(Ljava/lang/String;Ljava/lang/Throwable;)V", shift = At.Shift.AFTER), remap = false)
public void injectLoad(CallbackInfo ci)
{
HotbarLoadFailCallback.EVENT.invoker().onHotbarLoadFail();
Expand All @@ -59,7 +59,7 @@ public void injectLoad(CallbackInfo ci)
* Saving Injection - Calls the HotbarSaveFailCallback if the client fails to save the hotbar file.
* @param ci CallbackInfo
*/
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;error(Ljava/lang/String;Ljava/lang/Throwable;)V", shift = At.Shift.AFTER))
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;error(Ljava/lang/String;Ljava/lang/Throwable;)V", shift = At.Shift.AFTER), remap = false)
public void injectSave(CallbackInfo ci)
{
HotbarSaveFailCallback.EVENT.invoker().onHotbarSaveFail();
Expand Down
96 changes: 79 additions & 17 deletions src/main/java/me/videogamesm12/multihotbar/util/HotbarToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import net.minecraft.client.toast.Toast;
import net.minecraft.client.toast.ToastManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

Expand All @@ -33,10 +35,10 @@
*/
public class HotbarToast implements Toast
{
final Identifier id = TEXTURE;
final Identifier id = new Identifier("multihotbar", "textures/gui/toast_background.png");
final TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
//
final Type type;
Type type;
//
Visibility toastVisibility;
long time;
Expand All @@ -55,11 +57,6 @@ public HotbarToast(Type type, Text title, Text description)
this.update = true;
}

public HotbarToast(Text title, Text description)
{
this(Type.MISC, title, description);
}

/**
* Hides the toast entirely.
*/
Expand All @@ -78,18 +75,60 @@ public Visibility draw(MatrixStack matrices, ToastManager manager, long startTim
update = false;
}

// Prepares the texture to be drawn
// Prepares the background texture to be drawn
textureManager.bindTexture(id);
RenderSystem.color3f(1.0F, 1.0F, 1.0F);

// Draws the textures
manager.drawTexture(matrices, 0, 0, 0, 64, this.getWidth(), this.getHeight());
// Draws the background
manager.drawTexture(matrices, 0, 0, 0, 0, this.getWidth(), this.getHeight());

// Gets the icon offset
// This is a terrible implementation, but it works.
int icon_offset_x;
int icon_offset_y = 0;
switch (type)
{
case SELECTION:
{
icon_offset_x = 0;
break;
}

case FAILED:
{
icon_offset_x = 1;
break;
}

case BACKUP:
{
icon_offset_x = 2;
break;
}

case BACKUP_FAILED:
{
icon_offset_x = 0;
icon_offset_y = 1;
break;
}

default:
{
icon_offset_x = 2;
icon_offset_y = 1;
break;
}
}

// Draws the icon
manager.drawTexture(matrices, 3, 3, 178 + (26 * icon_offset_x), 26 * icon_offset_y, 26, 26);

// Draws the text
if (description != null)
{
MinecraftClient.getInstance().textRenderer.draw(matrices, title, 18, 7, 0xFFFF00);
MinecraftClient.getInstance().textRenderer.draw(matrices, description, 18, 18, 0xFFFFFF);
MinecraftClient.getInstance().textRenderer.draw(matrices, title, 30, 7, 0xFFFF00);
MinecraftClient.getInstance().textRenderer.draw(matrices, description, 30, 18, 0xFFFFFF);
}
else
{
Expand All @@ -106,7 +145,7 @@ public Visibility draw(MatrixStack matrices, ToastManager manager, long startTim
}

/**
* Changes the text in the toast and updates it
* Changes the text in the toast and updates it.
* @param title Text
* @param description Text
*/
Expand All @@ -117,6 +156,19 @@ public void change(Text title, @Nullable Text description)
this.update = true;
}

/**
* Changes the text and type in the toast and updates it.
* @param title Text
* @param description Text
* @param type Type
*/
public void change(Text title, @Nullable Text description, Type type)
{
this.type = type;
//
change(title, description);
}

/**
* Gets the type of message the toast is for.
* @return Type
Expand All @@ -126,11 +178,21 @@ public Type getType()
return this.type;
}

/**
* Change the type of message the toast is for.
* @param type Type
*/
public void setType(Type type)
{
this.type = type;
this.update = true;
}

public enum Type
{
BACKUP, // Toasts used for backups
FAILED, // Toasts used for failures
MISC, // Toasts used for miscellaneous things
SELECTION // Toasts used for selections
BACKUP, // Toasts used for backups
BACKUP_FAILED, // Toasts used for backup failures
FAILED, // Toasts used for failures
SELECTION // Toasts used for selections
}
}
Loading

0 comments on commit 207c017

Please sign in to comment.