Skip to content

Commit

Permalink
Fixed Fabric server crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed May 5, 2024
1 parent 5671f85 commit 59b012d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
32 changes: 32 additions & 0 deletions common/src/main/java/sereneseasons/init/ModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@
package sereneseasons.init;

import glitchcore.event.EventManager;
import glitchcore.event.client.ItemTooltipEvent;
import glitchcore.event.client.RegisterColorsEvent;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.FoliageColor;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import sereneseasons.api.SSItems;
import sereneseasons.api.season.ISeasonColorProvider;
import sereneseasons.api.season.ISeasonState;
Expand All @@ -35,6 +44,8 @@
import sereneseasons.util.SeasonColorUtil;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Locale;

public class ModClient
{
Expand All @@ -48,6 +59,27 @@ public static void addClientHandlers()
EventManager.addListener(SeasonHandlerClient::onClientTick);
EventManager.addListener(ModFertility::setupTooltips);
EventManager.addListener(ModClient::registerBlockColors);
EventManager.addListener(ModClient::onItemTooltip);
}

public static void onItemTooltip(ItemTooltipEvent event)
{
List<Component> tooltip = event.getTooltip();
Player player = event.getPlayer();

if (player != null && ModConfig.seasons.isDimensionWhitelisted(player.level().dimension()))
{
int seasonCycleTicks = SeasonHelper.getSeasonState(player.level()).getSeasonCycleTicks();
SeasonTime time = new SeasonTime(seasonCycleTicks);
int subSeasonDuration = ModConfig.seasons.subSeasonDuration;

tooltip.add(Component.translatable("desc.sereneseasons." + time.getSubSeason().toString().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.GRAY).append(Component.literal(" (").withStyle(ChatFormatting.DARK_GRAY)).append(Component.translatable("desc.sereneseasons." + time.getTropicalSeason().toString().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.DARK_GRAY)).append(Component.literal(")").withStyle(ChatFormatting.DARK_GRAY)));
tooltip.add(Component.translatable("desc.sereneseasons.day_counter", (time.getDay() % subSeasonDuration) + 1, subSeasonDuration).withStyle(ChatFormatting.GRAY).append(Component.translatable("desc.sereneseasons.tropical_day_counter", (((time.getDay() + subSeasonDuration) % (subSeasonDuration * 2)) + 1), subSeasonDuration * 2).withStyle(ChatFormatting.DARK_GRAY)));
}
else
{
tooltip.add(Component.literal("???").withStyle(ChatFormatting.GRAY));
}
}

public static void registerItemProperties()
Expand Down
30 changes: 3 additions & 27 deletions common/src/main/java/sereneseasons/item/CalendarItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import net.minecraft.client.Minecraft;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import sereneseasons.api.season.SeasonHelper;
import sereneseasons.core.SereneSeasons;
import sereneseasons.init.ModConfig;
import sereneseasons.season.SeasonTime;

Expand All @@ -23,31 +26,4 @@ public CalendarItem(Properties p_41383_)
{
super(p_41383_);
}

@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltip, TooltipFlag flag)
{
Level level = Minecraft.getInstance().level;

if (level != null)
{
if (ModConfig.seasons.isDimensionWhitelisted(level.dimension()))
{
int seasonCycleTicks = SeasonHelper.getSeasonState(level).getSeasonCycleTicks();
SeasonTime time = new SeasonTime(seasonCycleTicks);
int subSeasonDuration = ModConfig.seasons.subSeasonDuration;

tooltip.add(Component.translatable("desc.sereneseasons." + time.getSubSeason().toString().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.GRAY).append(Component.literal(" (").withStyle(ChatFormatting.DARK_GRAY)).append(Component.translatable("desc.sereneseasons." + time.getTropicalSeason().toString().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.DARK_GRAY)).append(Component.literal(")").withStyle(ChatFormatting.DARK_GRAY)));
tooltip.add(Component.translatable("desc.sereneseasons.day_counter", (time.getDay() % subSeasonDuration) + 1, subSeasonDuration).withStyle(ChatFormatting.GRAY).append(Component.translatable("desc.sereneseasons.tropical_day_counter", (((time.getDay() + subSeasonDuration) % (subSeasonDuration * 2)) + 1), subSeasonDuration * 2).withStyle(ChatFormatting.DARK_GRAY)));
}
else
{
tooltip.add(Component.literal("???").withStyle(ChatFormatting.GRAY));
}
}
else
{
tooltip.add(Component.literal("???").withStyle(ChatFormatting.GRAY));
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ org.gradle.daemon=false

# Dependencies
nightconfig_version=3.6.7
glitchcore_version=1.1.0.3
glitchcore_version=1.1.0.5

0 comments on commit 59b012d

Please sign in to comment.