Skip to content

Commit

Permalink
Add TemperatureGoogleRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
yuesha-yc committed Jan 2, 2025
1 parent 70333a1 commit 2487153
Show file tree
Hide file tree
Showing 16 changed files with 549 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/teammoeg/frostedheart/FHMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.teammoeg.frostedheart.content.world.FHBiomeModifiers;
import com.teammoeg.frostedheart.content.world.FHBiomes;
import com.teammoeg.frostedheart.content.world.FHFeatures;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameRules.IntegerValue;
Expand Down Expand Up @@ -119,7 +120,7 @@ public class FHMain {
REGISTRATE.setTooltipModifierFactory(item -> {
return new ItemDescription.Modifier(item, TooltipHelper.Palette.STANDARD_CREATE)
.andThen(new FoodTempStats(item))
.andThen(new FoodNutritionStats(item))
.andThen(TooltipModifier.mapNull(FoodNutritionStats.create(item)))
.andThen(TooltipModifier.mapNull(PlantTempStats.create(item)))
.andThen(TooltipModifier.mapNull(BlockTempStats.create(item)))
.andThen(TooltipModifier.mapNull(EquipmentTempStats.create(item)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.simibubi.create.foundation.utility.Components;
import com.teammoeg.frostedheart.bootstrap.client.FHKeyMappings;
import com.teammoeg.frostedheart.util.lang.Lang;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

Expand All @@ -18,25 +17,39 @@ public class KeyControlledDesc {
List<Component> lines;
List<Component> linesOnS;
List<Component> linesOnCtrl;
int key1;
int key2;
String key1Desc;
String key2Desc;
String key1Translation;
String key2Translation;

// initialize with empty lines
public KeyControlledDesc(List<Component> shiftLines, List<Component> ctrlLines) {
public KeyControlledDesc(List<Component> shiftLines, List<Component> ctrlLines, int key1, int key2,
String key1Desc, String key2Desc,
String key1Translation, String key2Translation) {
this.lines = new ArrayList<>();
this.linesOnS = shiftLines;
this.linesOnCtrl = ctrlLines;
this.key1 = key1;
this.key2 = key2;
this.key1Desc = key1Desc;
this.key2Desc = key2Desc;
this.key1Translation = key1Translation;
this.key2Translation = key2Translation;

boolean hasDescription = !this.linesOnS.isEmpty();
boolean hasControls = !this.linesOnCtrl.isEmpty();

if (hasDescription || hasControls) {
String[] holdDesc = Lang.translateTooltip("holdForTemperature", "$")
String[] holdDesc = Lang.translateTooltip(this.key1Translation, "$")
.getString()
.split("\\$");
String[] holdCtrl = Lang.translateTooltip("holdForControls", "$")
String[] holdCtrl = Lang.translateTooltip(this.key2Translation, "$")
.getString()
.split("\\$");
MutableComponent keyShift = Lang.translateTooltip("keyS");
MutableComponent keyCtrl = Lang.translateTooltip("keyCtrl");
MutableComponent keyShiftTooltip = Lang.text(this.key1Desc).component();
MutableComponent keyCtrlTooltip = Lang.text(this.key2Desc).component();

for (List<Component> list : Arrays.asList(lines, this.linesOnS, this.linesOnCtrl)) {
boolean shift = list == this.linesOnS;
Expand All @@ -49,7 +62,7 @@ public KeyControlledDesc(List<Component> shiftLines, List<Component> ctrlLines)
if (hasControls) {
MutableComponent tabBuilder = Components.empty();
tabBuilder.append(Components.literal(holdCtrl[0]).withStyle(DARK_GRAY));
tabBuilder.append(keyCtrl.plainCopy()
tabBuilder.append(keyCtrlTooltip.plainCopy()
.withStyle(ctrl ? WHITE : GRAY));
tabBuilder.append(Components.literal(holdCtrl[1]).withStyle(DARK_GRAY));
list.add(0, tabBuilder);
Expand All @@ -58,7 +71,7 @@ public KeyControlledDesc(List<Component> shiftLines, List<Component> ctrlLines)
if (hasDescription) {
MutableComponent tabBuilder = Components.empty();
tabBuilder.append(Components.literal(holdDesc[0]).withStyle(DARK_GRAY));
tabBuilder.append(keyShift.plainCopy()
tabBuilder.append(keyShiftTooltip.plainCopy()
.withStyle(shift ? WHITE : GRAY));
tabBuilder.append(Components.literal(holdDesc[1]).withStyle(DARK_GRAY));
list.add(0, tabBuilder);
Expand All @@ -81,9 +94,9 @@ public KeyControlledDesc(List<Component> shiftLines, List<Component> ctrlLines)
}

public List<Component> getCurrentLines() {
if (FHKeyMappings.hasSDown()) {
if (FHKeyMappings.isDown(key1)) {
return linesOnS;
} else if (Screen.hasControlDown()) {
} else if (FHKeyMappings.isDown(key2)) {
return linesOnCtrl;
} else {
return lines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public static void init() {
public static boolean hasSDown() {
return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_S);
}

public static boolean isDown(int key) {
return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), key);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teammoeg.frostedheart.content.climate.event;

import com.teammoeg.frostedheart.content.climate.render.TemperatureGoogleRenderer;
import com.teammoeg.frostedheart.infrastructure.config.FHConfig;
import com.teammoeg.frostedheart.FHMain;
import com.teammoeg.frostedheart.bootstrap.reference.FHParticleTypes;
Expand All @@ -12,6 +13,8 @@
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand Down Expand Up @@ -80,9 +83,17 @@ public static void playFrostedSound(TickEvent.PlayerTickEvent event) {
}
}
@SubscribeEvent
public void onWorldLoad(LevelEvent.Load event) {
public static void onWorldLoad(LevelEvent.Load event) {
forstedSoundCd=0;
}

@Mod.EventBusSubscriber(modid = FHMain.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public static class ModBusEvents {
@SubscribeEvent
public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) {
event.registerAboveAll("temperature_google_info", TemperatureGoogleRenderer.OVERLAY);
}
}


}
Loading

0 comments on commit 2487153

Please sign in to comment.