diff --git a/src/generated/resources/assets/mxtune/lang/en_us.json b/src/generated/resources/assets/mxtune/lang/en_us.json index cea394c7b..c1f7c92a4 100644 --- a/src/generated/resources/assets/mxtune/lang/en_us.json +++ b/src/generated/resources/assets/mxtune/lang/en_us.json @@ -13,7 +13,7 @@ "config.mxtune.client.double_click_time_ms": "Double-click time in milliseconds for GUI widgets", "config.mxtune.client.mml_Link": "MML Site Link", "config.mxtune.server.listener_range": "Listener Range", - "config.mxtune.server.sheet_music_life_in_days": "Sheet Music Life in Days", + "config.mxtune.server.sheet_music_life_in_days": "Sheet Music Life in Days.", "container.mxtune.block_music.more": "%s More", "entity.mxtune.music_source": "[MusicSource]", "entity.mxtune.music_venue_info": "Music Venue Info Panel", @@ -260,7 +260,6 @@ "tooltip.mxtune.music_venue_tool_item.shift_help_05": "Survival: Owners may remove their own Venues. OP/Creative players can remove any Venue.", "tooltip.mxtune.music_venue_tool_item.shift_help_06": "Venues are only visible when this tool is on the HotBar.", "tooltip.mxtune.sheet_music.days_left": "Days left: %s", - "tooltip.mxtune.sheet_music.days_left_error": "Days left: nn", "tooltip.mxtune.sheet_music.duration_error": "h:mm:ss", "tooltip.mxtune.sheet_music.empty": " - Empty - ", "tooltip.mxtune.sheet_music.n_of_m_instrument_name": "%s of %s %s" diff --git a/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java b/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java index bd273798c..0b7a52490 100644 --- a/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java +++ b/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java @@ -26,6 +26,7 @@ public class MXTuneConfig { + public static int SHEET_MUSIC_NO_EXPIRATION = 99999; private MXTuneConfig() { /* NOP */ } /** Client Configuration Settings */ @@ -70,9 +71,9 @@ public Server(final ForgeConfigSpec.Builder builder) .defineInRange("listenerRange",24,10, 64); sheetMusicLifeInDays = builder - .comment("Sheet Music Life in Days before it breaks") + .comment("Sheet Music Life in Days before it breaks. 99999 = no expiration.") .translation("config.mxtune.server.sheet_music_life_in_days") - .defineInRange("sheetMusicLifeInDays", 30, 2, Integer.MAX_VALUE); + .defineInRange("sheetMusicLifeInDays", SHEET_MUSIC_NO_EXPIRATION, 2, SHEET_MUSIC_NO_EXPIRATION); builder.pop(); } @@ -82,6 +83,8 @@ public Server(final ForgeConfigSpec.Builder builder) public static int getSheetMusicLifeInDays() { return SERVER.sheetMusicLifeInDays.get(); } + public static boolean doesSheetMusicExpire() { return SERVER.sheetMusicLifeInDays.get() == SHEET_MUSIC_NO_EXPIRATION;} + public static int getDoubleClickTimeMS() { return CLIENT.doubleClickTime.get(); } public static String getMmlLink() { return CLIENT.site.get(); } diff --git a/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java b/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java index d498f8ec8..4dbb4d551 100644 --- a/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java +++ b/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java @@ -70,7 +70,6 @@ private void addItems() addTooltip("music_score.n_part_score", "%s Part Score"); addTooltip("music_score.parts_error", "No parts found"); addTooltip("sheet_music.days_left", "Days left: %s"); - addTooltip("sheet_music.days_left_error", "Days left: nn"); addTooltip("sheet_music.duration_error", "h:mm:ss"); addTooltip("sheet_music.empty", " - Empty - "); addTooltip("sheet_music.n_of_m_instrument_name", "%s of %s %s"); @@ -240,7 +239,7 @@ private void addConfigs() addConfig("client.double_click_time_ms", "Double-click time in milliseconds for GUI widgets"); addConfig("client.mml_Link", "MML Site Link"); addConfig("server.listener_range", "Listener Range"); - addConfig("server.sheet_music_life_in_days", "Sheet Music Life in Days"); + addConfig("server.sheet_music_life_in_days", "Sheet Music Life in Days."); } private void addEntities() diff --git a/src/main/java/aeronicamc/mods/mxtune/items/MultiInstItem.java b/src/main/java/aeronicamc/mods/mxtune/items/MultiInstItem.java index 0eb93585e..3120c548f 100644 --- a/src/main/java/aeronicamc/mods/mxtune/items/MultiInstItem.java +++ b/src/main/java/aeronicamc/mods/mxtune/items/MultiInstItem.java @@ -267,7 +267,9 @@ public void appendHoverText(ItemStack pStack, @Nullable World pLevel, List getFormattedMusicScoreParts(ItemStack musicSc public static ITextComponent getFormattedSheetMusicDaysLeft(ItemStack sheetMusicStack) { long daysLeft = getSheetMusicDaysLeft(sheetMusicStack); - if (daysLeft != 99999) + if (daysLeft != SHEET_MUSIC_NO_EXPIRATION) return new TranslationTextComponent(SHEET_MUSIC_DAYS_LEFT, getSheetMusicDaysLeft(sheetMusicStack)) .withStyle(TextFormatting.GRAY) .withStyle(TextFormatting.ITALIC); else - return SHEET_MUSIC_DAYS_LEFT_ERROR; + return StringTextComponent.EMPTY; } /** * Client or Server Side *

Get the sheet music days left as a {@link long}. * @param sheetMusicStack The sheet music stack. - * @return days left or 99999 if there was a parse or item stack error. + * @return days left or SHEET_MUSIC_NO_EXPIRATION(99999) if there was a parse or item stack error. */ - public static long getSheetMusicDaysLeft(ItemStack sheetMusicStack) + public static int getSheetMusicDaysLeft(ItemStack sheetMusicStack) { String keyDateTimeString = getMusicTextKey(sheetMusicStack); if (keyDateTimeString != null) @@ -265,13 +263,14 @@ public static long getSheetMusicDaysLeft(ItemStack sheetMusicStack) keyDateTime = LocalDateTime.parse(keyDateTimeString); } catch (DateTimeException e) { - return 99999; + LOGGER.warn("Failure to parse SheetMusic key: {}", keyDateTimeString); + return SHEET_MUSIC_NO_EXPIRATION; } LocalDateTime keyPlusDaysLeft = keyDateTime.plusDays(MXTuneConfig.getSheetMusicLifeInDays()); LocalDateTime now = LocalDateTime.now(ZoneId.of("GMT0")); - return Math.max(Duration.between(now, keyPlusDaysLeft).getSeconds() / 86400L, 0L); + return (int) Math.max(Duration.between(now, keyPlusDaysLeft).getSeconds() / 86400L, 0L); } - return 99999; + return SHEET_MUSIC_NO_EXPIRATION; } /** @@ -461,7 +460,7 @@ public static boolean writeIMusic(ItemStack itemStack, String musicTitle, byte[] */ public static void scrapSheetMusicIfExpired(ItemStack pStack, World pLevel, Entity pEntity, int pItemSlot, boolean pIsSelected) { - if (!pLevel.isClientSide() && !pStack.isEmpty() && (pEntity instanceof PlayerEntity) && !pIsSelected) + if (!pLevel.isClientSide() && !pStack.isEmpty() && (pEntity instanceof PlayerEntity) && !pIsSelected && !MXTuneConfig.doesSheetMusicExpire()) { String key = getMusicTextKey(((PlayerEntity) pEntity).inventory.getItem(pItemSlot)); boolean canReap = getSheetMusicDaysLeft(pStack) == 0L; @@ -516,7 +515,7 @@ public static void scrapSheetMusicIfExpired(ItemStack pStack, World pLevel, Enti */ public static void scrapSheetMusicInInstrumentIfExpired(@Nullable Slot slot, ItemStack pInstrumentStack, World pLevel, Entity pEntity, @Nullable BlockPos blockPos) { - if (!pLevel.isClientSide() && !pInstrumentStack.isEmpty() && (pEntity instanceof PlayerEntity) && !pEntity.isSpectator()) + if (!pLevel.isClientSide() && !pInstrumentStack.isEmpty() && (pEntity instanceof PlayerEntity) && !pEntity.isSpectator() && !MXTuneConfig.doesSheetMusicExpire()) { int multiplier = 0; ItemStack sheetMusic = removeSheetMusicFromIInstrument(pInstrumentStack);