port: 1.21.4

- Also substantially improve iconic buttons
This commit is contained in:
Martin Prokoph
2025-01-26 00:53:51 +01:00
parent 51c354c533
commit 16f558644c
11 changed files with 86 additions and 61 deletions

View File

@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
}

View File

@@ -7,7 +7,10 @@ import eu.midnightdust.visualoverhaul.util.ModIconUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.texture.*;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
@@ -15,13 +18,18 @@ import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class IconicButtons {
MinecraftClient client = MinecraftClient.getInstance();
TextureManager textureManager = client.getTextureManager();
private String buttonId;
private Text prevText;
private Identifier iconId;
private static final Map<Identifier, Identifier> ICONS = new HashMap<>();
public IconicButtons() {}
public void init(ClickableWidget widget) {
if (widget == null || widget.getMessage() == null || widget.getMessage().getContent() == null) return;
@@ -30,32 +38,36 @@ public class IconicButtons {
if (VOConfig.buttonIcons && !buttonId.isEmpty()) {
if (VOConfig.debug) System.out.println(buttonId);
iconId = Identifier.tryParse("iconic:textures/gui/icons/" + buttonId.toLowerCase()+".png");
if (buttonId.endsWith(".midnightconfig.title"))
{
// Show mod icons in MidnightConfig overview
if (buttonId.endsWith(".midnightconfig.title")) {
iconId = Identifier.of("modid", buttonId.replace(".midnightconfig.title", "") + "_icon");
NativeImageBackedTexture icon = new ModIconUtil(buttonId.replace(".midnightconfig.title", "")).createModIcon();
if (icon != null) {
client.getTextureManager().registerTexture(iconId, icon);
ICONS.put(iconId, iconId);
} else {
iconId = null;
}
}
if (iconId == null) return;
TextureManager textureManager = client.getTextureManager();
AbstractTexture abstractTexture = textureManager.getOrDefault(iconId, null);
if (abstractTexture == null) {
abstractTexture = new ResourceTexture(iconId);
try { abstractTexture.load(((TextureManagerAccessor)textureManager).getResourceContainer());
} catch (Exception e) {iconId = null; return;}
// Handle dynamic icons
else if (iconId != null && !ICONS.containsKey(iconId)) {
if (((TextureManagerAccessor)textureManager).getResourceContainer().getResource(iconId).isEmpty())
return; // If no icon is present, don't load it
ResourceTexture abstractTexture = new ResourceTexture(iconId);
if (VOConfig.debug) System.out.println("Loading dynamic icon: "+iconId);
try {
abstractTexture.loadContents(((TextureManagerAccessor)textureManager).getResourceContainer());
} catch (Exception e) {e.fillInStackTrace();}
textureManager.registerTexture(iconId, abstractTexture);
ICONS.put(iconId, iconId);
}
if (abstractTexture == MissingSprite.getMissingSpriteTexture()) iconId = null;
}
}
public void renderIcons(DrawContext context, ClickableWidget widget, float alpha) {
if (widget.getMessage() == null || widget.getWidth() <= 20) return;
if (prevText != widget.getMessage()) init(widget);
if (VOConfig.buttonIcons && !buttonId.equals("") && iconId != null) {
if (VOConfig.buttonIcons && !buttonId.isEmpty() && iconId != null && ICONS.containsKey(iconId)) {
int scaledWidth = client.getWindow().getScaledWidth();
boolean limitedSpace = client.textRenderer.getWidth(widget.getMessage()) > (widget.getWidth() * 0.75f);
@@ -70,17 +82,19 @@ public class IconicButtons {
if (VOConfig.zoomIconOnHover && widget.isSelected()) inset = 1;
int size = 20-inset*2;
Identifier textureId = ICONS.get(iconId);
if (VOConfig.buttonIconPosition.equals(VOConfig.IconPosition.LEFT) || showLeftWhenBoth || (VOConfig.buttonIconPosition.equals(VOConfig.IconPosition.LOCATION) && widget.getX() < scaledWidth/2))
context.drawTexture(iconId, widget.getX()+inset, widget.getY()+inset, 0, 0, size, size, size, size);
context.drawTexture(RenderLayer::getGuiTextured, textureId, widget.getX()+inset, widget.getY()+inset, 0, 0, size, size, size, size);
if (VOConfig.buttonIconPosition.equals(VOConfig.IconPosition.RIGHT) || showRightWhenBoth || (VOConfig.buttonIconPosition.equals(VOConfig.IconPosition.LOCATION) && widget.getX()+widget.getWidth() > scaledWidth/2))
context.drawTexture(iconId, widget.getX()+widget.getWidth()-20+inset, widget.getY()+inset, 0, 0, size, size, size, size);
context.drawTexture(RenderLayer::getGuiTextured, textureId, widget.getX()+widget.getWidth()-20+inset, widget.getY()+inset, 0, 0, size, size, size, size);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
}
public static void reload(ResourceManager manager) {
manager.findResources("textures", path -> path.getPath().contains(".properties")).forEach((id, resource) -> {
manager.findResources("textures", path -> path.getNamespace().equals("iconic") && path.getPath().contains(".properties")).forEach((id, resource) -> {
if (manager.getResource(id).isEmpty()) return;
try (InputStream stream = manager.getResource(id).get().getInputStream()) {
Identifier iconId = Identifier.of(id.getNamespace(), id.getPath().replace(".properties", ".png"));
@@ -102,16 +116,11 @@ public class IconicButtons {
}
if (properties.get("texture") != null) {
Identifier textureId = Identifier.of(properties.getProperty("texture"));
TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
AbstractTexture abstractTexture = textureManager.getOrDefault(iconId, null);
if (abstractTexture == null) {
abstractTexture = new ResourceTexture(textureId);
textureManager.registerTexture(iconId, abstractTexture);
}
Identifier textureId = Identifier.tryParse(properties.getProperty("texture"));
ICONS.put(iconId, textureId);
}
} catch (Exception e) {
LogManager.getLogger("Iconic").error("Error occurred while loading texture.properties " + id.toString(), e);
LogManager.getLogger("Iconic").error("Error occurred while loading texture.properties {}", id.toString(), e);
}
});
}

View File

@@ -4,15 +4,19 @@ import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.id;
public class JukeboxTop extends Block {
private static final BooleanProperty HAS_RECORD = Properties.HAS_RECORD;
public JukeboxTop() {
super(AbstractBlock.Settings.copy(Blocks.JUKEBOX));
super(AbstractBlock.Settings.copy(Blocks.JUKEBOX).registryKey(RegistryKey.of(RegistryKeys.BLOCK, id("jukebox_top"))));
this.setDefaultState(this.stateManager.getDefaultState().with(HAS_RECORD,false));
}
@Override

View File

@@ -13,7 +13,7 @@ public class FurnaceWoodenPlanksModel extends Model {
public static final EntityModelLayer WOODEN_PLANKS_MODEL_LAYER = new EntityModelLayer(id("wooden_planks"), "main");
public FurnaceWoodenPlanksModel(ModelPart root) {
super(RenderLayer::getEntitySolid);
super(root, RenderLayer::getEntitySolid);
bb_main = root;
bb_main.setPivot(0.0F, 24.0F, 0.0F);
}
@@ -34,7 +34,7 @@ public class FurnaceWoodenPlanksModel extends Model {
return modelData;
}
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
bb_main.render(matrices, vertices, light, overlay);
}
// public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
// bb_main.render(matrices, vertices, light, overlay);
// }
}

View File

@@ -9,9 +9,9 @@ import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ModelTransformationMode;
import org.joml.AxisAngle4f;
import org.joml.Math;
import org.joml.Quaternionf;

View File

@@ -13,10 +13,10 @@ import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ModelTransformationMode;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.util.Identifier;
import org.joml.AxisAngle4f;
@@ -41,7 +41,7 @@ public class FurnaceBlockEntityRenderer<E extends AbstractFurnaceBlockEntity> im
ItemStack input = blockEntity.getStack(0);
ItemStack fuel = blockEntity.getStack(1);
ItemStack output = blockEntity.getStack(2);
float angle = (blockState.get(AbstractFurnaceBlock.FACING)).asRotation();
float angle = (blockState.get(AbstractFurnaceBlock.FACING)).getRotationQuaternion().angle();
if(!input.isEmpty() || !output.isEmpty()) {
matrices.push();

View File

@@ -1,12 +1,19 @@
package eu.midnightdust.visualoverhaul.mixin;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(TextureManager.class)
public interface TextureManagerAccessor {
@Accessor
ResourceManager getResourceContainer();
@Accessor
Map<Identifier, AbstractTexture> getTextures();
}

View File

@@ -14,6 +14,7 @@ import eu.midnightdust.visualoverhaul.util.VOColorUtil;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
@@ -27,7 +28,10 @@ import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.data.ModelProvider;
import net.minecraft.client.data.Models;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.ModelData;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.component.DataComponentTypes;
@@ -70,11 +74,11 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
// PhonosCompatInit.init();
//}
Registries.ITEM.forEach((item) -> {
ModelPredicateProviderRegistry.register(item, Identifier.ofVanilla("round"), (stack, world, entity, seed) ->
stack.getComponents().contains(DataComponentTypes.JUKEBOX_PLAYABLE) && stack.getComponents().contains(DataComponentTypes.CUSTOM_MODEL_DATA) &&
stack.getComponents().get(DataComponentTypes.CUSTOM_MODEL_DATA).value() == 710 ? 1.0F : 0.0F);
});
// Registries.ITEM.forEach((item) -> {
// ModelPredicateProviderRegistry.register(item, Identifier.ofVanilla("round"), (stack, world, entity, seed) ->
// stack.getComponents().contains(DataComponentTypes.JUKEBOX_PLAYABLE) && stack.getComponents().contains(DataComponentTypes.CUSTOM_MODEL_DATA) &&
// stack.getComponents().get(DataComponentTypes.CUSTOM_MODEL_DATA).value() == 710 ? 1.0F : 0.0F);
// });
ClientPlayNetworking.registerGlobalReceiver(UpdateItemsPacket.PACKET_ID,
(payload, context) -> context.client().execute(() -> {
@@ -121,20 +125,20 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
}
});
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET, Items.AXOLOTL_BUCKET, Items.COD_BUCKET, Items.PUFFERFISH_BUCKET, Items.TROPICAL_FISH_BUCKET, Items.SALMON_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK, Items.SHORT_GRASS, Items.TALL_GRASS, Items.FERN, Items.LARGE_FERN);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES, Items.DARK_OAK_LEAVES, Items.JUNGLE_LEAVES, Items.ACACIA_LEAVES, Items.VINE, Items.SUGAR_CANE);
if (VOConfig.coloredLilypad) ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.LILY_PAD);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
var contents = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
if (contents == null || contents.potion().isEmpty()) return tintIndex > 0 ? -1 : potionColor;
var potion = contents.potion().get();
if ((potion == Potions.WATER || potion == Potions.MUNDANE || potion == Potions.THICK || potion == Potions.AWKWARD) && tintIndex == 0) {
return potionColor;
}
return tintIndex > 0 ? -1 : contents.getColor();
}, Items.POTION, Items.SPLASH_POTION, Items.LINGERING_POTION);
// ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET, Items.AXOLOTL_BUCKET, Items.COD_BUCKET, Items.PUFFERFISH_BUCKET, Items.TROPICAL_FISH_BUCKET, Items.SALMON_BUCKET);
// ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK, Items.SHORT_GRASS, Items.TALL_GRASS, Items.FERN, Items.LARGE_FERN);
// ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES, Items.DARK_OAK_LEAVES, Items.JUNGLE_LEAVES, Items.ACACIA_LEAVES, Items.VINE, Items.SUGAR_CANE);
// if (VOConfig.coloredLilypad) ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.LILY_PAD);
//
// ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
// var contents = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
// if (contents == null || contents.potion().isEmpty()) return tintIndex > 0 ? -1 : potionColor;
// var potion = contents.potion().get();
// if ((potion == Potions.WATER || potion == Potions.MUNDANE || potion == Potions.THICK || potion == Potions.AWKWARD) && tintIndex == 0) {
// return potionColor;
// }
// return tintIndex > 0 ? -1 : contents.getColor();
// }, Items.POTION, Items.SPLASH_POTION, Items.LINGERING_POTION);
}
if (VOConfig.coloredLilypad) {
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> world != null ? world.getColor(pos, BiomeColors.FOLIAGE_COLOR) : 0, Blocks.LILY_PAD);

View File

@@ -12,6 +12,7 @@ import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -43,7 +44,7 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
}
@Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
private static void tick(ServerWorld world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
if (world.getBlockState(pos).hasBlockEntity()) {
if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() != visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();

View File

@@ -1,23 +1,23 @@
org.gradle.jvmargs=-Xmx2048M
minecraft_version=1.21
yarn_mappings=1.21+build.2
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.1
enabled_platforms=fabric,neoforge
archives_base_name=visualoverhaul
mod_version=5.2.1
mod_version=5.3.0
maven_group=eu.midnightdust
release_type=release
curseforge_id=432008
modrinth_id=YQnwl5Vv
midnightlib_version=1.5.7
midnightlib_version=1.6.7
phonos_version=0.3.0+1.19.2
fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21
fabric_loader_version=0.16.9
fabric_api_version=0.111.0+1.21.4
neoforge_version=21.0.14-beta
neoforge_version=21.4.10-beta
yarn_mappings_patch_neoforge_version = 1.21+build.4
quilt_loader_version=0.19.0-beta.18

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists