Skip to content

Commit

Permalink
Add Bundle Preview
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Nov 2, 2024
1 parent 6b72908 commit 5e07d0c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static class Generic
public static final ConfigOptionList BLOCK_TYPE_BREAK_RESTRICTION_WARN = new ConfigOptionList ("blockTypeBreakRestrictionWarn", MessageOutputType.MESSAGE).apply(GENERIC_KEY);
public static final ConfigInteger BREAKING_GRID_SIZE = new ConfigInteger ("breakingGridSize", 3, 1, 1000).apply(GENERIC_KEY);
public static final ConfigOptionList BREAKING_RESTRICTION_MODE = new ConfigOptionList ("breakingRestrictionMode", PlacementRestrictionMode.LINE).apply(GENERIC_KEY);
public static final ConfigBoolean BUNDLE_DISPLAY_BACKGROUND_COLOR = new ConfigBoolean ("bundleDisplayBgColor", true).apply(GENERIC_KEY);
public static final ConfigBoolean BUNDLE_DISPLAY_REQUIRE_SHIFT = new ConfigBoolean ("bundleDisplayRequireShift", true).apply(GENERIC_KEY);
public static final ConfigColor CHAT_BACKGROUND_COLOR = new ConfigColor ("chatBackgroundColor", "#80000000").apply(GENERIC_KEY);
public static final ConfigString CHAT_TIME_FORMAT = new ConfigString ("chatTimeFormat", "[HH:mm:ss]").apply(GENERIC_KEY);
public static final ConfigBoolean CLIENT_PLACEMENT_ROTATION = new ConfigBoolean ("clientPlacementRotation", true).apply(GENERIC_KEY);
Expand Down Expand Up @@ -133,6 +135,8 @@ public static class Generic
public static final ImmutableList<IConfigBase> OPTIONS = ImmutableList.of(
ACCURATE_PLACEMENT_PROTOCOL_MODE,
ACCURATE_PLACEMENT_PROTOCOL,
BUNDLE_DISPLAY_BACKGROUND_COLOR,
BUNDLE_DISPLAY_REQUIRE_SHIFT,
CLIENT_PLACEMENT_ROTATION,
DEBUG_LOGGING,
FAST_LEFT_CLICK_ALLOW_TOOLS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum FeatureToggle implements IHotkeyTogglable, IConfigNotifiable<IConfig
TWEAK_BLOCK_TYPE_BREAK_RESTRICTION("tweakBlockTypeBreakRestriction", false, ""),
TWEAK_BREAKING_GRID ("tweakBreakingGrid", false, "", KeybindSettings.INGAME_BOTH),
TWEAK_BREAKING_RESTRICTION ("tweakBreakingRestriction", false, ""),
TWEAK_BUNDLE_DISPLAY ("tweakBundleDisplay", false, ""),
TWEAK_CHAT_BACKGROUND_COLOR ("tweakChatBackgroundColor", false, ""),
TWEAK_CHAT_PERSISTENT_TEXT ("tweakChatPersistentText", false, ""),
TWEAK_CHAT_TIMESTAMP ("tweakChatTimestamp", false, ""),
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ else if (stack.getComponents().contains(DataComponentTypes.CONTAINER) && Invento
fi.dy.masa.malilib.render.RenderUtils.renderShulkerBoxPreview(stack, x, y, Configs.Generic.SHULKER_DISPLAY_BACKGROUND_COLOR.getBooleanValue(), drawContext);
}
}
else if (stack.getComponents().contains(DataComponentTypes.BUNDLE_CONTENTS) && InventoryUtils.bundleHasItems(stack))
{
if (FeatureToggle.TWEAK_BUNDLE_DISPLAY.getBooleanValue() &&
(Configs.Generic.BUNDLE_DISPLAY_REQUIRE_SHIFT.getBooleanValue() == false || GuiBase.isShiftDown()))
{
fi.dy.masa.malilib.render.RenderUtils.renderBundlePreview(stack, x, y, Configs.Generic.BUNDLE_DISPLAY_BACKGROUND_COLOR.getBooleanValue(), drawContext);
}
}
}

@Override
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBundleItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fi.dy.masa.tweakeroo.mixin;

import java.util.Optional;

import net.minecraft.item.BundleItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import fi.dy.masa.malilib.gui.GuiBase;
import fi.dy.masa.tweakeroo.config.Configs;
import fi.dy.masa.tweakeroo.config.FeatureToggle;

@Mixin(BundleItem.class)
public class MixinBundleItem
{
@Inject(method = "getTooltipData", at = @At("HEAD"), cancellable = true)
private void tweakeroo_getTooltipData(ItemStack stack, CallbackInfoReturnable<Optional<TooltipData>> cir)
{
if (FeatureToggle.TWEAK_BUNDLE_DISPLAY.getBooleanValue() &&
Configs.Generic.BUNDLE_DISPLAY_REQUIRE_SHIFT.getBooleanValue() &&
GuiBase.isShiftDown())
{
cir.setReturnValue(Optional.empty());
}
else if (FeatureToggle.TWEAK_BUNDLE_DISPLAY.getBooleanValue() &&
!Configs.Generic.BUNDLE_DISPLAY_REQUIRE_SHIFT.getBooleanValue())
{
cir.setReturnValue(Optional.empty());
}
}
}
7 changes: 7 additions & 0 deletions src/main/resources/assets/tweakeroo/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"tweakeroo.config.generic.name.blockTypeBreakRestrictionWarn": "blockTypeBreakRestrictionWarn",
"tweakeroo.config.generic.name.breakingGridSize": "breakingGridSize",
"tweakeroo.config.generic.name.breakingRestrictionMode": "breakingRestrictionMode",
"tweakeroo.config.generic.name.bundleDisplayBgColor": "bundleDisplayBgColor",
"tweakeroo.config.generic.name.bundleDisplayRequireShift": "bundleDisplayRequireShift",
"tweakeroo.config.generic.name.chatBackgroundColor": "chatBackgroundColor",
"tweakeroo.config.generic.name.chatTimeFormat": "chatTimeFormat",
"tweakeroo.config.generic.name.clientPlacementRotation": "clientPlacementRotation",
Expand Down Expand Up @@ -94,6 +96,8 @@
"tweakeroo.config.generic.comment.blockTypeBreakRestrictionWarn": "Selects which type of warning message to show (if any)\nwhen the Block Type Break Restriction feature prevents breaking a block",
"tweakeroo.config.generic.comment.breakingGridSize": "The grid interval size for the grid breaking mode.\nTo quickly adjust the value, scroll while\nholding down the tweak toggle keybind.",
"tweakeroo.config.generic.comment.breakingRestrictionMode": "The Breaking Restriction mode to use (hotkey-selectable)",
"tweakeroo.config.generic.comment.bundleDisplayBgColor": "Enables tinting/coloring the Bundle display\nbackground texture with the dye color of the bundle",
"tweakeroo.config.generic.comment.bundleDisplayRequireShift": "Whether or not holding shift is required for the Bundle preview\n§6NOTE: Disabling this causes the Vanilla Bundle tooltip to be fully disabled.",
"tweakeroo.config.generic.comment.chatBackgroundColor": "The background color for the chat messages,\nif 'tweakChatBackgroundColor' is enabled",
"tweakeroo.config.generic.comment.chatTimeFormat": "The time format for chat messages, if tweakChatTimestamp is enabled\nUses the Java SimpleDateFormat format specifiers.",
"tweakeroo.config.generic.comment.clientPlacementRotation": "Enable single player and client side placement rotations,\nsuch as Accurate Placement working in single player without Carpet mod",
Expand Down Expand Up @@ -442,6 +446,7 @@
"tweakeroo.config.feature_toggle.name.tweakBlockTypeBreakRestriction": "tweakBlockTypeBreakRestriction",
"tweakeroo.config.feature_toggle.name.tweakBreakingGrid": "tweakBreakingGrid",
"tweakeroo.config.feature_toggle.name.tweakBreakingRestriction": "tweakBreakingRestriction",
"tweakeroo.config.feature_toggle.name.tweakBundleDisplay": "tweakBundleDisplay",
"tweakeroo.config.feature_toggle.name.tweakChatBackgroundColor": "tweakChatBackgroundColor",
"tweakeroo.config.feature_toggle.name.tweakChatPersistentText": "tweakChatPersistentText",
"tweakeroo.config.feature_toggle.name.tweakChatTimestamp": "tweakChatTimestamp",
Expand Down Expand Up @@ -525,6 +530,7 @@
"tweakeroo.config.feature_toggle.prettyName.tweakBlockTypeBreakRestriction": "Block Type Break Restriction",
"tweakeroo.config.feature_toggle.prettyName.tweakBreakingGrid": "Breaking Grid",
"tweakeroo.config.feature_toggle.prettyName.tweakBreakingRestriction": "Breaking Restriction",
"tweakeroo.config.feature_toggle.prettyName.tweakBundleDisplay": "Bundle Display",
"tweakeroo.config.feature_toggle.prettyName.tweakChatBackgroundColor": "Chat Background Color",
"tweakeroo.config.feature_toggle.prettyName.tweakChatPersistentText": "Chat Persistent Text",
"tweakeroo.config.feature_toggle.prettyName.tweakChatTimestamp": "Chat Timestamp",
Expand Down Expand Up @@ -608,6 +614,7 @@
"tweakeroo.config.feature_toggle.comment.tweakBlockTypeBreakRestriction": "Restricts which blocks you are able to break (manually).\nSee the corresponding 'blockBreakRestriction*' configs in the Lists category.",
"tweakeroo.config.feature_toggle.comment.tweakBreakingGrid": "When enabled, you can only break blocks in\na grid pattern, with a configurable interval.\nTo quickly adjust the interval, scroll while\nholding down the tweak toggle keybind.",
"tweakeroo.config.feature_toggle.comment.tweakBreakingRestriction": "Enables the Breaking Restriction mode\n (Plane, Layer, Face, Column, Line, Diagonal).\nBasically only allows you to break blocks\nin those patterns, while holding down the attack key.",
"tweakeroo.config.feature_toggle.comment.tweakBundleDisplay": "Enables rendering a preview of the Bundle contents,\nwhen you hold shift while hovering over a Bundle item",
"tweakeroo.config.feature_toggle.comment.tweakChatBackgroundColor": "Overrides the default chat background color\nwith the one from Generics -> 'chatBackgroundColor'",
"tweakeroo.config.feature_toggle.comment.tweakChatPersistentText": "Stores the text from the chat input text field\nand restores it when the chat is opened again",
"tweakeroo.config.feature_toggle.comment.tweakChatTimestamp": "Adds timestamps to chat messages",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.tweakeroo.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"MixinBlockItem",
"MixinBossBarHud",
"MixinBuiltChunk",
"MixinBundleItem",
"MixinChatHud",
"MixinChatScreen",
"MixinChunkBuilder_BuiltChunk",
Expand Down

0 comments on commit 5e07d0c

Please sign in to comment.