Skip to content
18 changes: 9 additions & 9 deletions src/main/java/twilightforest/client/BakedMultiPartRenderers.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package twilightforest.client;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.NoopRenderer;
import net.minecraft.resources.Identifier;
import net.minecraft.util.LazyLoadedValue;
import twilightforest.client.model.TFModelLayers;
import twilightforest.client.model.entity.HydraHeadModel;
import twilightforest.client.model.entity.HydraNeckModel;
Expand All @@ -19,19 +20,18 @@
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("deprecation")
public class BakedMultiPartRenderers {
private static final Map<Identifier, LazyLoadedValue<EntityRenderer<?>>> renderers = new HashMap<>();
private static final Map<Identifier, Supplier<EntityRenderer<?, ?>>> renderers = new HashMap<>();

public static void bakeMultiPartRenderers(EntityRendererProvider.Context context) {
renderers.put(TFPart.RENDERER, new LazyLoadedValue<>(() -> new NoopRenderer<>(context)));
renderers.put(HydraHead.RENDERER, new LazyLoadedValue<>(() -> new HydraHeadRenderer<>(context, new HydraHeadModel<>(context.bakeLayer(TFModelLayers.HYDRA_HEAD)))));
renderers.put(HydraNeck.RENDERER, new LazyLoadedValue<>(() -> new HydraNeckRenderer<>(context, new HydraNeckModel(context.bakeLayer(TFModelLayers.HYDRA_NECK)))));
renderers.put(SnowQueenIceShield.RENDERER, new LazyLoadedValue<>(() -> new SnowQueenIceShieldRenderer<>(context)));
renderers.put(NagaSegment.RENDERER, new LazyLoadedValue<>(() -> new NagaSegmentRenderer<>(context, new NagaModel<>(context.bakeLayer(TFModelLayers.NAGA_BODY)))));
renderers.put(TFPart.RENDERER, Suppliers.memoize(() -> new NoopRenderer<>(context)));
renderers.put(HydraHead.RENDERER, Suppliers.memoize(() -> new HydraHeadRenderer(context, new HydraHeadModel(context.bakeLayer(TFModelLayers.HYDRA_HEAD)))));
renderers.put(HydraNeck.RENDERER, Suppliers.memoize(() -> new HydraNeckRenderer(context, new HydraNeckModel(context.bakeLayer(TFModelLayers.HYDRA_NECK)))));
renderers.put(SnowQueenIceShield.RENDERER, Suppliers.memoize(() -> new SnowQueenIceShieldRenderer(context)));
renderers.put(NagaSegment.RENDERER, Suppliers.memoize(() -> new NagaSegmentRenderer(context, new NagaModel<>(context.bakeLayer(TFModelLayers.NAGA_BODY)))));
}

public static EntityRenderer<?> lookup(Identifier location) {
public static EntityRenderer<?, ?> lookup(Identifier location) {
return renderers.get(location).get();
}
}
10 changes: 3 additions & 7 deletions src/main/java/twilightforest/client/FoliageColorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.google.common.collect.MapMaker;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.event.entity.EntityLeaveLevelEvent;
import org.jetbrains.annotations.NotNull;
import tamaized.beanification.Autowired;
import tamaized.beanification.Component;
import tamaized.beanification.PostConstruct;
Expand All @@ -23,7 +23,7 @@ public final class FoliageColorHandler {
@Autowired
private BiomeColorAlgorithms biomeColorAlgorithms;

private final Map<ResourceKey<Biome>, Handler> REGISTRY = new HashMap<>() {{
private final Map<ResourceKey<@NotNull Biome>, Handler> REGISTRY = new HashMap<>() {{
put(TFBiomes.SPOOKY_FOREST, (o, x, z) -> biomeColorAlgorithms.spookyFoliage(x, z));
put(TFBiomes.ENCHANTED_FOREST, (o, x, z) -> biomeColorAlgorithms.enchanted(o, (int) x, (int) z));
put(TFBiomes.DARK_FOREST_CENTER, (o, x, z) -> biomeColorAlgorithms.darkForestCenterFoliage(x, z));
Expand All @@ -47,17 +47,13 @@ public int get(int o, Biome biome, double x, double z) {
if (handler == null) {
handler = REGISTRY.getOrDefault(
Minecraft.getInstance().level == null ? null :
Minecraft.getInstance().level.registryAccess().registryOrThrow(Registries.BIOME).getResourceKey(biome).orElse(null),
Minecraft.getInstance().level.registryAccess().lookupOrThrow(Registries.BIOME).getResourceKey(biome).orElse(null),
Handler.DEFAULT);
HANDLES.put(biome, handler);
}
return handler.apply(o, x, z);
}

public static int getTintColorAtPosition(BlockPos pos) {

}

@FunctionalInterface
private interface Handler {
Handler DEFAULT = (o, x, z) -> o;
Expand Down
43 changes: 33 additions & 10 deletions src/main/java/twilightforest/client/LockedBiomeToast.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
package twilightforest.client;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.client.gui.components.toasts.ToastManager;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;

public record LockedBiomeToast(ItemStack item) implements Toast {

public class LockedBiomeToast implements Toast {
private static final Component TITLE = Component.translatable("misc.twilightforest.biome_locked");
private static final Component DESCRIPTION = Component.translatable("misc.twilightforest.biome_locked_2");
private static final Identifier BACKGROUND_SPRITE = Identifier.withDefaultNamespace("toast/advancement");

private final ItemStack item;
private Toast.Visibility wantedVisibility = Toast.Visibility.SHOW;

public LockedBiomeToast(ItemStack item) {
this.item = item;
}

public ItemStack item() {
return this.item;
}

@Override
public Toast.Visibility getWantedVisibility() {
return this.wantedVisibility;
}

@Override
public void update(ToastManager toastManager, long timer) {
if (timer >= 10000L) {
this.wantedVisibility = Toast.Visibility.HIDE;
Comment thread
Tamaized marked this conversation as resolved.
}
}

@Override
public Visibility render(GuiGraphics graphics, ToastComponent component, long timer) {
graphics.blitSprite(BACKGROUND_SPRITE, 0, 0, this.width(), this.height());
graphics.renderFakeItem(this.item(), 6, 8);
graphics.drawString(component.getMinecraft().font, TITLE, 25, 7, -256, false);
graphics.drawString(component.getMinecraft().font, DESCRIPTION, 25, 18, 16777215, false);
public void extractRenderState(GuiGraphicsExtractor graphics, Font font, long timer) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_SPRITE, 0, 0, this.width(), this.height());

return timer >= 10000L ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
graphics.fakeItem(this.item(), 6, 8);
graphics.text(font, TITLE, 25, 7, -256, false);
graphics.text(font, DESCRIPTION, 25, 18, 16777215, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class MagicPaintingAtlasInfo {
public final static String MAGIC_PAINTING_PATH = "magic_paintings";
public static final Identifier ATLAS_LOCATION = TwilightForestMod.prefix("textures/atlas/magic_paintings.png");
public static final Identifier ATLAS_INFO_LOCATION = Identifier.withDefaultNamespace(MAGIC_PAINTING_PATH);
public static final Identifier ATLAS_LOCATION = TwilightForestMod.prefix(MAGIC_PAINTING_PATH);
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
public static final Identifier ATLAS_INFO_LOCATION = TwilightForestMod.prefix(MAGIC_PAINTING_PATH);
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
public static final Identifier BACK_SPRITE_LOCATION = TwilightForestMod.prefix(MAGIC_PAINTING_PATH + "/back");
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package twilightforest.client;

import com.mojang.blaze3d.pipeline.RenderPipeline;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.client.gui.components.toasts.ToastManager;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemStackTemplate;
import twilightforest.init.TFBlocks;

public class MissingAdvancementToast implements Toast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public MovingCicadaSoundInstance(LivingEntity entity) {

@Override
public void tick() {
if (!this.wearer.isRemoved() && (this.wearer.getItemBySlot(EquipmentSlot.HEAD).is(TFBlocks.CICADA.asItem()) || this.isWearingCicadaCurio())) {
this.x = (float) this.wearer.getX();
this.y = (float) this.wearer.getY();
this.z = (float) this.wearer.getZ();
} else {
Comment thread
albazavr-alba marked this conversation as resolved.
this.stop();
}
if (!this.wearer.isRemoved() && (this.wearer.getItemBySlot(EquipmentSlot.HEAD).is(TFBlocks.CICADA.asItem()) || this.isWearingCicadaCurio())) {
if (!this.wearer.isRemoved() && (this.wearer.getItemBySlot(EquipmentSlot.HEAD).is(TFBlocks.CICADA.asItem()))) {
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
this.x = (float) this.wearer.getX();
this.y = (float) this.wearer.getY();
this.z = (float) this.wearer.getZ();
} else {
this.stop();
}
}
}

private boolean isWearingCicadaCurio() {
Expand Down
36 changes: 20 additions & 16 deletions src/main/java/twilightforest/client/OptifineWarningScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.TextAlignment;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.network.chat.*;
import org.jetbrains.annotations.Nullable;

public class OptifineWarningScreen extends Screen {
import java.net.URI;

public class OptifineWarningScreen extends Screen {
private final Screen lastScreen;
private int ticksUntilEnable = 20 * 10;
private MultiLineLabel message = MultiLineLabel.EMPTY;
private MultiLineLabel suggestions = MultiLineLabel.EMPTY;
private static final Component text = Component.translatable("gui.twilightforest.optifine.message");
private static final MutableComponent url = Component.translatable("gui.twilightforest.optifine.suggestions").withStyle(style -> style.withColor(ChatFormatting.GREEN).applyFormat(ChatFormatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/NordicGamerFE/usefulmods")));
private static final MutableComponent url = Component.translatable("gui.twilightforest.optifine.suggestions").withStyle(style -> style.withColor(ChatFormatting.GREEN).applyFormat(ChatFormatting.UNDERLINE).withClickEvent(new ClickEvent.OpenUrl(URI.create("https://github.com/NordicGamerFE/usefulmods"))));
private Button exitButton;

public OptifineWarningScreen(Screen screen) {
Expand All @@ -32,22 +35,22 @@ public Component getNarrationMessage() {
@Override
protected void init() {
super.init();
this.exitButton = this.addRenderableWidget(Button.builder(CommonComponents.GUI_PROCEED, (pressed) -> Minecraft.getInstance().setScreen(this.lastScreen)).bounds(this.width / 2 - 75, this.height * 3 / 4, 150, 20).build());
this.exitButton = this.addRenderableWidget(Button.builder(CommonComponents.GUI_PROCEED, (_) -> Minecraft.getInstance().setScreen(this.lastScreen)).bounds(this.width / 2 - 75, this.height * 3 / 4, 150, 20).build());
this.exitButton.active = false;

this.message = MultiLineLabel.create(this.font, text, this.width - 50);
this.suggestions = MultiLineLabel.create(this.font, url, this.width - 50);
}

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(graphics, mouseX, mouseY, partialTicks);
graphics.drawCenteredString(this.font, this.title, this.width / 2, 30, 16777215);
this.message.renderCentered(graphics, this.width / 2, 70);
this.suggestions.renderCentered(graphics, this.width / 2, 160);
super.render(graphics, mouseX, mouseY, partialTicks);
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTicks) {
this.extractBackground(graphics, mouseX, mouseY, partialTicks);
graphics.centeredText(this.font, this.title, this.width / 2, 30, 16777215);
this.message.visitLines(TextAlignment.CENTER, this.width / 2, 70, this.font.lineHeight, graphics.textRenderer());
this.suggestions.visitLines(TextAlignment.CENTER, this.width / 2, 160, this.font.lineHeight, graphics.textRenderer());
super.extractRenderState(graphics, mouseX, mouseY, partialTicks);

this.exitButton.render(graphics, mouseX, mouseY, partialTicks);
this.exitButton.extractRenderState(graphics, mouseX, mouseY, partialTicks);
}

@Override
Expand All @@ -69,23 +72,24 @@ public void onClose() {
}

@Override
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) {
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
double pMouseX = event.x();
double pMouseY = event.y();
if (pMouseY > 160 && pMouseY < 170) {
Style style = this.getClickedComponentStyleAt((int) pMouseX);
if (style != null && style.getClickEvent() != null && style.getClickEvent().getAction() == ClickEvent.Action.OPEN_URL) {
this.handleComponentClicked(style);
if (style != null && style.getClickEvent() != null && style.getClickEvent().action() == ClickEvent.Action.OPEN_URL) {
return false;
}
}

return super.mouseClicked(pMouseX, pMouseY, pButton);
return super.mouseClicked(event, doubleClick);
}

@Nullable
private Style getClickedComponentStyleAt(int xPos) {
int wid = Minecraft.getInstance().font.width(url);
int left = this.width / 2 - wid / 2;
int right = this.width / 2 + wid / 2;
return xPos >= left && xPos <= right ? Minecraft.getInstance().font.getSplitter().componentStyleAtWidth(url, xPos - left) : null;
return xPos >= left && xPos <= right ? url.getStyle() : null;
}
}
Loading
Loading