VisualOverhaul 5.1.0 - Code overhaul!

- Update to 1.20.4
- Switch Forge version to NeoForge
- Update resourcepacks & add round relic disc (thanks to @SuperNoobYT)
- Furnaces will now show results when finished (closes #61)
- Fix crash related to sound events (closes #60, #52)
- Fix crash related to button icons (closes #59, #55, #54, likely #49)
- Fix log spam when mod is only present on server (closes #33)
- Fix jukeboxes staying powered after playback has finished (closes #53)
This commit is contained in:
Martin Prokoph
2024-02-23 20:43:30 +01:00
parent ca9b7a0357
commit 680d2a3a8b
46 changed files with 464 additions and 339 deletions

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id "architectury-plugin" version "3.4-SNAPSHOT" id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
} }
architectury { architectury {
@@ -46,6 +47,21 @@ allprojects {
options.encoding = "UTF-8" options.encoding = "UTF-8"
options.release = 17 options.release = 17
} }
ext {
releaseChangelog = {
def changes = new StringBuilder()
changes << "## VisualOverhaul v$project.version for $project.minecraft_version\n[View the changelog](https://www.github.com/TeamMidnightDust/VisualOverhaul/commits/)"
def proc = "git log --max-count=1 --pretty=format:%s".execute()
proc.in.eachLine { line ->
def processedLine = line.toString()
if (!processedLine.contains("New translations") && !processedLine.contains("Merge") && !processedLine.contains("branch")) {
changes << "\n- ${processedLine.capitalize()}"
}
}
proc.waitFor()
return changes.toString()
}
}
java { java {
withSourcesJar() withSourcesJar()

View File

@@ -17,17 +17,3 @@ dependencies {
// Remove the next line if you don't want to depend on the API // Remove the next line if you don't want to depend on the API
//modApi "dev.architectury:architectury:${rootProject.architectury_version}" //modApi "dev.architectury:architectury:${rootProject.architectury_version}"
} }
publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
}

View File

@@ -23,13 +23,12 @@ public class IconicButtons {
private String buttonId; private String buttonId;
private Text prevText; private Text prevText;
private Identifier iconId; private Identifier iconId;
public IconicButtons(ClickableWidget widget) { public IconicButtons() {}
init(widget);
}
public void init(ClickableWidget widget) { public void init(ClickableWidget widget) {
if (widget == null || widget.getMessage() == null || widget.getMessage().getContent() == null) return;
prevText = widget.getMessage(); prevText = widget.getMessage();
buttonId = (widget.getMessage().getContent() instanceof TranslatableTextContent translatableTextContent) ? translatableTextContent.getKey().toLowerCase() : ""; buttonId = (widget.getMessage().getContent() instanceof TranslatableTextContent translatableTextContent) ? translatableTextContent.getKey().toLowerCase() : "";
if (VOConfig.buttonIcons && !buttonId.equals("")) { if (VOConfig.buttonIcons && !buttonId.isEmpty()) {
if (VOConfig.debug) System.out.println(buttonId); if (VOConfig.debug) System.out.println(buttonId);
iconId = Identifier.tryParse("iconic:textures/gui/icons/" + buttonId.toLowerCase()+".png"); iconId = Identifier.tryParse("iconic:textures/gui/icons/" + buttonId.toLowerCase()+".png");
if (buttonId.endsWith(".midnightconfig.title")) if (buttonId.endsWith(".midnightconfig.title"))
@@ -55,7 +54,7 @@ public class IconicButtons {
} }
} }
public void renderIcons(DrawContext context, ClickableWidget widget, float alpha) { public void renderIcons(DrawContext context, ClickableWidget widget, float alpha) {
if (widget.getMessage() == null) return; if (widget.getMessage() == null || widget.getWidth() <= 20) return;
if (prevText != widget.getMessage()) init(widget); if (prevText != widget.getMessage()) init(widget);
if (VOConfig.buttonIcons && !buttonId.equals("") && iconId != null) { if (VOConfig.buttonIcons && !buttonId.equals("") && iconId != null) {
int scaledWidth = client.getWindow().getScaledWidth(); int scaledWidth = client.getWindow().getScaledWidth();

View File

@@ -1,10 +1,21 @@
package eu.midnightdust.visualoverhaul; package eu.midnightdust.visualoverhaul;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.compress.utils.Lists;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class VisualOverhaul { public class VisualOverhaul {
public static final String MOD_ID = "visualoverhaul"; public static final String MOD_ID = "visualoverhaul";
public static final List<UUID> playersWithMod = Lists.newArrayList();
public static final Map<BlockPos, ItemStack> jukeboxItems = new HashMap<>();
public static final Identifier HELLO_PACKET = new Identifier(MOD_ID, "hello");
public static final Identifier UPDATE_POTION_BOTTLES = new Identifier(MOD_ID, "brewingstand"); public static final Identifier UPDATE_POTION_BOTTLES = new Identifier(MOD_ID, "brewingstand");
public static final Identifier UPDATE_RECORD = new Identifier(MOD_ID, "record"); public static final Identifier UPDATE_RECORD = new Identifier(MOD_ID, "record");
public static final Identifier UPDATE_FURNACE_ITEMS = new Identifier(MOD_ID, "furnace"); public static final Identifier UPDATE_FURNACE_ITEMS = new Identifier(MOD_ID, "furnace");

View File

@@ -38,11 +38,12 @@ public class FurnaceBlockEntityRenderer<E extends AbstractFurnaceBlockEntity> im
if (VOConfig.furnace && blockEntity != null) { if (VOConfig.furnace && blockEntity != null) {
BlockState blockState = blockEntity.getCachedState(); BlockState blockState = blockEntity.getCachedState();
int lightAtBlock = WorldRenderer.getLightmapCoordinates(Objects.requireNonNull(blockEntity.getWorld()), blockEntity.getPos().offset(blockState.get(AbstractFurnaceBlock.FACING))); int lightAtBlock = WorldRenderer.getLightmapCoordinates(Objects.requireNonNull(blockEntity.getWorld()), blockEntity.getPos().offset(blockState.get(AbstractFurnaceBlock.FACING)));
ItemStack item1 = blockEntity.getStack(0); ItemStack input = blockEntity.getStack(0);
ItemStack item2 = blockEntity.getStack(1); ItemStack fuel = blockEntity.getStack(1);
ItemStack output = blockEntity.getStack(2);
float angle = (blockState.get(AbstractFurnaceBlock.FACING)).asRotation(); float angle = (blockState.get(AbstractFurnaceBlock.FACING)).asRotation();
if(!item1.isEmpty()) { if(!input.isEmpty() || !output.isEmpty()) {
matrices.push(); matrices.push();
matrices.translate(0.5f, 0.58f, 0.5f); matrices.translate(0.5f, 0.58f, 0.5f);
@@ -52,12 +53,12 @@ public class FurnaceBlockEntityRenderer<E extends AbstractFurnaceBlockEntity> im
matrices.multiply(new Quaternionf(new AxisAngle4f(Math.toRadians(angle * 3 + 180), 0, 1, 0))); matrices.multiply(new Quaternionf(new AxisAngle4f(Math.toRadians(angle * 3 + 180), 0, 1, 0)));
matrices.translate(0.0f, 0.0f, -0.4f); matrices.translate(0.0f, 0.0f, -0.4f);
matrices.multiply(degrees90x); matrices.multiply(degrees90x);
MinecraftClient.getInstance().getItemRenderer().renderItem(item1, ModelTransformationMode.GROUND, lightAtBlock, overlay, matrices, vertexConsumers, blockEntity.getWorld(), 0); MinecraftClient.getInstance().getItemRenderer().renderItem(input.isEmpty() ? output : input, ModelTransformationMode.GROUND, lightAtBlock, overlay, matrices, vertexConsumers, blockEntity.getWorld(), 0);
matrices.pop(); matrices.pop();
} }
if (!item2.isEmpty() && !item2.isIn(ItemTags.LOGS_THAT_BURN) && !item2.isIn(ItemTags.PLANKS)) { if (!fuel.isEmpty() && !fuel.isIn(ItemTags.LOGS_THAT_BURN) && !fuel.isIn(ItemTags.PLANKS)) {
matrices.push(); matrices.push();
matrices.translate(0.5f, 0.08f, 0.5f); matrices.translate(0.5f, 0.08f, 0.5f);
@@ -67,13 +68,13 @@ public class FurnaceBlockEntityRenderer<E extends AbstractFurnaceBlockEntity> im
matrices.multiply(new Quaternionf(new AxisAngle4f(Math.toRadians(angle * 3 + 180), 0, 1, 0))); matrices.multiply(new Quaternionf(new AxisAngle4f(Math.toRadians(angle * 3 + 180), 0, 1, 0)));
matrices.translate(0.0f, 0.0f, -0.4f); matrices.translate(0.0f, 0.0f, -0.4f);
matrices.multiply(degrees90x); matrices.multiply(degrees90x);
MinecraftClient.getInstance().getItemRenderer().renderItem(item2, ModelTransformationMode.GROUND, lightAtBlock, overlay, matrices, vertexConsumers, blockEntity.getWorld(), 0); MinecraftClient.getInstance().getItemRenderer().renderItem(fuel, ModelTransformationMode.GROUND, lightAtBlock, overlay, matrices, vertexConsumers, blockEntity.getWorld(), 0);
matrices.pop(); matrices.pop();
} }
else if (!item2.isEmpty()) { else if (!fuel.isEmpty()) {
matrices.push(); matrices.push();
BlockState state = Block.getBlockFromItem(item2.getItem()).getDefaultState(); BlockState state = Block.getBlockFromItem(fuel.getItem()).getDefaultState();
Sprite texture = MinecraftClient.getInstance().getBlockRenderManager().getModel(state).getParticleSprite(); Sprite texture = MinecraftClient.getInstance().getBlockRenderManager().getModel(state).getParticleSprite();
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCull(spriteToTexture(texture))); VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCull(spriteToTexture(texture)));

View File

@@ -29,6 +29,8 @@ import org.joml.Quaternionf;
import java.util.Objects; import java.util.Objects;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.jukeboxItems;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBlockEntity> { public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBlockEntity> {
private ItemStack record; private ItemStack record;
@@ -43,8 +45,8 @@ public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBl
int lightAbove = WorldRenderer.getLightmapCoordinates(Objects.requireNonNull(blockEntity.getWorld()), blockEntity.getPos().up()); int lightAbove = WorldRenderer.getLightmapCoordinates(Objects.requireNonNull(blockEntity.getWorld()), blockEntity.getPos().up());
// Tries to get the disc using the serverside method // Tries to get the disc using the serverside method
if (blockEntity.getStack() != ItemStack.EMPTY) { if (jukeboxItems.containsKey(blockEntity.getPos()) && !jukeboxItems.get(blockEntity.getPos()).isEmpty()) {
record = blockEntity.getStack().copy(); record = jukeboxItems.get(blockEntity.getPos()).copy();
} }
// Else gets the record sound played at the position of the jukebox // // Else gets the record sound played at the position of the jukebox //
else if (SoundTest.getSound(blockEntity.getPos()) != null) { else if (SoundTest.getSound(blockEntity.getPos()) != null) {

View File

@@ -1,14 +0,0 @@
package eu.midnightdust.visualoverhaul.mixin;
import net.minecraft.block.entity.JukeboxBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(JukeboxBlockEntity.class)
public interface JukeboxBlockEntityAccessor {
@Accessor @Final
DefaultedList<ItemStack> getInventory();
}

View File

@@ -13,17 +13,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PressableWidget.class) @Mixin(PressableWidget.class)
public abstract class MixinPressableWidget extends ClickableWidget { public abstract class MixinPressableWidget extends ClickableWidget {
@Unique IconicButtons iconicButtons; @Unique IconicButtons visualoverhaul$iconicButtons;
public MixinPressableWidget(int x, int y, int width, int height, Text message) { public MixinPressableWidget(int x, int y, int width, int height, Text message) {
super(x, y, width, height, message); super(x, y, width, height, message);
} }
@Inject(at = @At("TAIL"), method = "<init>") @Inject(at = @At("TAIL"), method = "<init>")
private void iconic$onInitButton(int i, int j, int k, int l, Text text, CallbackInfo ci) { private void iconic$onInitButton(int i, int j, int k, int l, Text text, CallbackInfo ci) {
iconicButtons = new IconicButtons(this); visualoverhaul$iconicButtons = new IconicButtons();
visualoverhaul$iconicButtons.init(this);
} }
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/PressableWidget;drawMessage(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/client/font/TextRenderer;I)V", shift = At.Shift.BEFORE), method = "renderButton") @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/PressableWidget;drawMessage(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/client/font/TextRenderer;I)V", shift = At.Shift.BEFORE), method = "renderWidget")
private void iconic$onRenderButton(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { private void iconic$onRenderButton(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
iconicButtons.renderIcons(context, this, this.alpha); visualoverhaul$iconicButtons.renderIcons(context, this, this.alpha);
} }
} }

View File

@@ -13,17 +13,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SliderWidget.class) @Mixin(SliderWidget.class)
public abstract class MixinSliderWidget extends ClickableWidget { public abstract class MixinSliderWidget extends ClickableWidget {
@Unique IconicButtons iconicButtons; @Unique IconicButtons visualoverhaul$iconicButtons;
public MixinSliderWidget(int x, int y, int width, int height, Text message) { public MixinSliderWidget(int x, int y, int width, int height, Text message) {
super(x, y, width, height, message); super(x, y, width, height, message);
} }
@Inject(at = @At("TAIL"), method = "<init>") @Inject(at = @At("TAIL"), method = "<init>")
private void iconic$onInitButton(int x, int y, int width, int height, Text text, double value, CallbackInfo ci) { private void iconic$onInitButton(int x, int y, int width, int height, Text text, double value, CallbackInfo ci) {
iconicButtons = new IconicButtons(this); visualoverhaul$iconicButtons = new IconicButtons();
visualoverhaul$iconicButtons.init(this);
} }
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/SliderWidget;drawScrollableText(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/client/font/TextRenderer;II)V", shift = At.Shift.BEFORE), method = "renderButton") @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/SliderWidget;drawScrollableText(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/client/font/TextRenderer;II)V", shift = At.Shift.BEFORE), method = "renderWidget")
private void iconic$onRenderButton(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { private void iconic$onRenderButton(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
iconicButtons.renderIcons(context, this, this.alpha); visualoverhaul$iconicButtons.renderIcons(context, this, this.alpha);
} }
} }

View File

@@ -7,6 +7,7 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -16,13 +17,16 @@ public abstract class MixinSoundSystem {
@Shadow private boolean started; @Shadow private boolean started;
private BlockPos jukeboxPos; @Unique
private BlockPos visualoverhaul$jukeboxPos;
@Inject(at = @At("TAIL"),method = "play(Lnet/minecraft/client/sound/SoundInstance;)V") @Inject(at = @At("TAIL"),method = "play(Lnet/minecraft/client/sound/SoundInstance;)V")
public void vo$onPlayRecordSound(SoundInstance soundInstance, CallbackInfo ci) { public void vo$onPlayRecordSound(SoundInstance soundInstance, CallbackInfo ci) {
if (soundInstance.getCategory().equals(SoundCategory.RECORDS) && this.started) { if (soundInstance != null) {
jukeboxPos = BlockPos.ofFloored(Math.floor(soundInstance.getX()), Math.floor(soundInstance.getY()), Math.floor(soundInstance.getZ())); if (soundInstance.getCategory().equals(SoundCategory.RECORDS) && this.started) {
SoundTest.soundPos.put(jukeboxPos, soundInstance.getId()); visualoverhaul$jukeboxPos = BlockPos.ofFloored(Math.floor(soundInstance.getX()), Math.floor(soundInstance.getY()), Math.floor(soundInstance.getZ()));
SoundTest.soundPos.put(visualoverhaul$jukeboxPos, soundInstance.getId());
}
} }
} }
@@ -30,9 +34,9 @@ public abstract class MixinSoundSystem {
public void vo$onStopRecordSound(SoundInstance soundInstance, CallbackInfo ci) { public void vo$onStopRecordSound(SoundInstance soundInstance, CallbackInfo ci) {
if (soundInstance != null) { if (soundInstance != null) {
if (soundInstance.getCategory().equals(SoundCategory.RECORDS)) { if (soundInstance.getCategory().equals(SoundCategory.RECORDS)) {
jukeboxPos = BlockPos.ofFloored(Math.floor(soundInstance.getX()), Math.floor(soundInstance.getY()), Math.floor(soundInstance.getZ())); visualoverhaul$jukeboxPos = BlockPos.ofFloored(Math.floor(soundInstance.getX()), Math.floor(soundInstance.getY()), Math.floor(soundInstance.getZ()));
if (SoundTest.soundPos.containsKey(jukeboxPos)) { if (SoundTest.soundPos.containsKey(visualoverhaul$jukeboxPos)) {
SoundTest.soundPos.remove(jukeboxPos, soundInstance.getId()); SoundTest.soundPos.remove(visualoverhaul$jukeboxPos, soundInstance.getId());
} }
} }
} }

View File

@@ -1,6 +1,7 @@
{ {
"pack": { "pack": {
"pack_format": 15, "pack_format": 15,
"supported_formats": [15, 99],
"description": "§2Makes the water bucket respect biome colors" "description": "§2Makes the water bucket respect biome colors"
} }
} }

View File

@@ -1,6 +1,7 @@
{ {
"pack": { "pack": {
"pack_format": 15, "pack_format": 15,
"supported_formats": [15, 99],
"description": "§2Changes the model of the furnace to be 3D" "description": "§2Changes the model of the furnace to be 3D"
} }
} }

View File

@@ -1,6 +1,7 @@
{ {
"pack": { "pack": {
"pack_format": 15, "pack_format": 15,
"supported_formats": [15, 99],
"description": "§2Removes the bottles from the brewing stand" "description": "§2Removes the bottles from the brewing stand"
} }
} }

View File

@@ -1,6 +1,7 @@
{ {
"pack": { "pack": {
"pack_format": 15, "pack_format": 15,
"supported_formats": [15, 99],
"description": "§2Makes the spinning discs on Jukeboxes round" "description": "§2Makes the spinning discs on Jukeboxes round"
} }
} }

View File

@@ -12,8 +12,7 @@
"MixinBlastFurnaceBlock", "MixinBlastFurnaceBlock",
"MixinPressableWidget", "MixinPressableWidget",
"MixinSliderWidget", "MixinSliderWidget",
"TextureManagerAccessor", "TextureManagerAccessor"
"JukeboxBlockEntityAccessor"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View File

@@ -1,5 +1,6 @@
plugins { plugins {
id "com.github.johnrengelman.shadow" version "7.1.2" id "com.github.johnrengelman.shadow" version "7.1.2"
id "me.shedaniel.unified-publishing"
} }
architectury { architectury {
@@ -44,21 +45,18 @@ processResources {
} }
} }
shadowJar { shadowJar {
exclude "architectury.common.json" exclude "architectury.common.json"
configurations = [project.configurations.shadowCommon] configurations = [project.configurations.shadowCommon]
classifier "dev-shadow" archiveClassifier = "dev-shadow"
} }
remapJar { remapJar {
injectAccessWidener = true
input.set shadowJar.archiveFile input.set shadowJar.archiveFile
dependsOn shadowJar dependsOn shadowJar
classifier null
}
jar {
classifier "dev"
} }
sourcesJar { sourcesJar {
@@ -73,16 +71,42 @@ components.java {
} }
} }
publishing { unifiedPublishing {
publications { project {
mavenFabric(MavenPublication) { displayName = "VisualOverhaul v$project.version - Fabric $project.minecraft_version"
artifactId = rootProject.archives_base_name + "-" + project.name releaseType = "$project.release_type"
from components.java changelog = releaseChangelog()
gameVersions = []
gameLoaders = ["fabric","quilt"]
mainPublication remapJar
relations {
depends {
curseforge = "fabric-api"
modrinth = "fabric-api"
}
includes {
curseforge = "midnightlib"
modrinth = "midnightlib"
}
}
var CURSEFORGE_TOKEN = project.findProperty("CURSEFORGE_TOKEN") ?: System.getenv("CURSEFORGE_TOKEN")
if (CURSEFORGE_TOKEN != null) {
curseforge {
token = CURSEFORGE_TOKEN
id = rootProject.curseforge_id
gameVersions.addAll "Java 17", project.minecraft_version
}
}
var MODRINTH_TOKEN = project.findProperty("MODRINTH_TOKEN") ?: System.getenv("MODRINTH_TOKEN")
if (MODRINTH_TOKEN != null) {
modrinth {
token = MODRINTH_TOKEN
id = rootProject.modrinth_id
version = "$project.version-$project.name"
gameVersions.addAll project.minecraft_version
}
} }
} }
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
}

View File

@@ -8,10 +8,11 @@ import eu.midnightdust.visualoverhaul.block.renderer.BrewingStandBlockEntityRend
import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer; import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer; import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.config.VOConfig; import eu.midnightdust.visualoverhaul.config.VOConfig;
import eu.midnightdust.visualoverhaul.mixin.JukeboxBlockEntityAccessor; import io.netty.buffer.Unpooled;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
@@ -23,16 +24,14 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.BrewingStandBlockEntity; import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.block.entity.JukeboxBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors; import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories; import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.texture.*;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.item.MusicDiscItem; import net.minecraft.item.MusicDiscItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.potion.PotionUtil; import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions; import net.minecraft.potion.Potions;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
@@ -42,10 +41,6 @@ import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.apache.logging.log4j.LogManager;
import java.io.InputStream;
import java.util.Properties;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*; import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.JukeBoxTop; import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.JukeBoxTop;
@@ -87,16 +82,14 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
(client, handler, attachedData, packetSender) -> { (client, handler, attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos(); BlockPos pos = attachedData.readBlockPos();
DefaultedList<ItemStack> inv = DefaultedList.ofSize(5, ItemStack.EMPTY); DefaultedList<ItemStack> inv = DefaultedList.ofSize(5, ItemStack.EMPTY);
for (int i = 0; i < 4; i++) { for (int i = 0; i <= 4; i++) {
inv.set(i, attachedData.readItemStack()); inv.set(i, attachedData.readItemStack());
} }
client.execute(() -> { client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity blockEntity) { if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity blockEntity) {
blockEntity.setStack(0, inv.get(0)); for (int i = 0; i <= 4; i++) {
blockEntity.setStack(1, inv.get(1)); blockEntity.setStack(i, inv.get(i));
blockEntity.setStack(2, inv.get(2)); }
blockEntity.setStack(3, inv.get(3));
blockEntity.setStack(4, inv.get(4));
} }
}); });
}); });
@@ -105,23 +98,21 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
BlockPos pos = attachedData.readBlockPos(); BlockPos pos = attachedData.readBlockPos();
ItemStack record = attachedData.readItemStack(); ItemStack record = attachedData.readItemStack();
client.execute(() -> { client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof JukeboxBlockEntity blockEntity) { jukeboxItems.put(pos, record);
((JukeboxBlockEntityAccessor)blockEntity).getInventory().set(0, record);
}
}); });
}); });
ClientPlayNetworking.registerGlobalReceiver(UPDATE_FURNACE_ITEMS, ClientPlayNetworking.registerGlobalReceiver(UPDATE_FURNACE_ITEMS,
(client, handler, attachedData, packetSender) -> { (client, handler, attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos(); BlockPos pos = attachedData.readBlockPos();
DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY); DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY);
for (int i = 0; i < 2; i++) { for (int i = 0; i <= 2; i++) {
inv.set(i, attachedData.readItemStack()); inv.set(i, attachedData.readItemStack());
} }
client.execute(() -> { client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof AbstractFurnaceBlockEntity blockEntity) { if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof AbstractFurnaceBlockEntity blockEntity) {
blockEntity.setStack(0, inv.get(0)); for (int i = 0; i <= 2; i++) {
blockEntity.setStack(1, inv.get(1)); blockEntity.setStack(i, inv.get(i));
blockEntity.setStack(2, inv.get(2)); }
} }
}); });
}); });
@@ -133,6 +124,13 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"coloredwaterbucket"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED); ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"coloredwaterbucket"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"rounddiscs"), modContainer, ResourcePackActivationType.ALWAYS_ENABLED); ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"rounddiscs"), modContainer, ResourcePackActivationType.ALWAYS_ENABLED);
}); });
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
if (client.player != null) {
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeUuid(client.player.getUuid());
sender.sendPacket(HELLO_PACKET, passedData);
}
});
// Biome-colored Items // Biome-colored Items
@@ -158,7 +156,7 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.TROPICAL_FISH_BUCKET); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.TROPICAL_FISH_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.SALMON_BUCKET); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.SALMON_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.SHORT_GRASS);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.TALL_GRASS); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.TALL_GRASS);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.FERN); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.FERN);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.LARGE_FERN); ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.LARGE_FERN);

View File

@@ -0,0 +1,17 @@
package eu.midnightdust.visualoverhaul.fabric;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.*;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.HELLO_PACKET;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.playersWithMod;
public class VisualOverhaulFabric implements ModInitializer {
@Override
public void onInitialize() {
ServerPlayNetworking.registerGlobalReceiver(HELLO_PACKET, (server, player, handler, buf, responseSender) -> playersWithMod.add(player.getUuid()));
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> playersWithMod.remove(handler.getPlayer().getUuid()));
};
}

View File

@@ -14,6 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -24,8 +25,10 @@ import java.util.stream.Stream;
@Mixin(AbstractFurnaceBlockEntity.class) @Mixin(AbstractFurnaceBlockEntity.class)
public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity { public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity {
private static boolean invUpdate = true; @Unique
private static int playerUpdate = -1; private static boolean visualoverhaul$invUpdate = true;
@Unique
private static int visualoverhaul$playerUpdate = -1;
protected MixinAbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { protected MixinAbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
@@ -35,7 +38,7 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
@Inject(at = @At("TAIL"), method = "tick") @Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) { private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
if (world.getBlockState(pos).hasBlockEntity()) { if (world.getBlockState(pos).hasBlockEntity()) {
if (!world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) { if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream(); Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos); passedData.writeBlockPos(pos);
@@ -43,15 +46,19 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
passedData.writeItemStack(blockEntity.getStack(1)); passedData.writeItemStack(blockEntity.getStack(1));
passedData.writeItemStack(blockEntity.getStack(2)); passedData.writeItemStack(blockEntity.getStack(2));
watchingPlayers.forEach(player -> ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData)); watchingPlayers.forEach(player -> {
invUpdate = false; if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData);
}
});
visualoverhaul$invUpdate = false;
} }
playerUpdate = world.getPlayers().size(); visualoverhaul$playerUpdate = world.getPlayers().size();
} }
} }
@Inject(at = @At("RETURN"), method = "getStack") @Inject(at = @At("RETURN"), method = "getStack")
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) { public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
invUpdate = true; visualoverhaul$invUpdate = true;
} }
} }

View File

@@ -14,6 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -24,8 +25,10 @@ import java.util.stream.Stream;
@Mixin(BrewingStandBlockEntity.class) @Mixin(BrewingStandBlockEntity.class)
public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity { public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity {
private static boolean invUpdate = true; @Unique
private static int playerUpdate = -1; private static boolean visualoverhaul$invUpdate = true;
@Unique
private static int visualoverhaul$playerUpdate = -1;
protected MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { protected MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState); super(blockEntityType, blockPos, blockState);
@@ -33,7 +36,7 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
@Inject(at = @At("TAIL"), method = "tick") @Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, BrewingStandBlockEntity blockEntity, CallbackInfo ci) { private static void tick(World world, BlockPos pos, BlockState state, BrewingStandBlockEntity blockEntity, CallbackInfo ci) {
if (!world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) { if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream(); Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos); passedData.writeBlockPos(pos);
@@ -43,14 +46,18 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
passedData.writeItemStack(blockEntity.getStack(3)); passedData.writeItemStack(blockEntity.getStack(3));
passedData.writeItemStack(blockEntity.getStack(4)); passedData.writeItemStack(blockEntity.getStack(4));
watchingPlayers.forEach(player -> ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData)); watchingPlayers.forEach(player -> {
invUpdate = false; if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData);
}
});
visualoverhaul$invUpdate = false;
} }
playerUpdate = world.getPlayers().size(); visualoverhaul$playerUpdate = world.getPlayers().size();
} }
@Inject(at = @At("RETURN"), method = "getStack") @Inject(at = @At("RETURN"), method = "getStack")
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) { public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
invUpdate = true; visualoverhaul$invUpdate = true;
} }
} }

View File

@@ -37,17 +37,21 @@ public abstract class MixinJukeboxBlock extends BlockWithEntity {
@Nullable @Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient() ? null : checkType(type, BlockEntityType.JUKEBOX, MixinJukeboxBlock::tick); return world.isClient() ? null : validateTicker(type, BlockEntityType.JUKEBOX, MixinJukeboxBlock::visualoverhaul$tick);
} }
@Unique @Unique
private static void tick(World world, BlockPos pos, BlockState state, JukeboxBlockEntity blockEntity) { private static void visualoverhaul$tick(World world, BlockPos pos, BlockState state, JukeboxBlockEntity blockEntity) {
if (!world.isClient && (JukeboxPacketUpdate.invUpdate || world.getPlayers().size() == JukeboxPacketUpdate.playerUpdate)) { if (!world.isClient && (JukeboxPacketUpdate.invUpdate || world.getPlayers().size() == JukeboxPacketUpdate.playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream(); Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos); passedData.writeBlockPos(pos);
passedData.writeItemStack(blockEntity.getStack()); passedData.writeItemStack(blockEntity.getStack());
watchingPlayers.forEach(player -> ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_RECORD, passedData)); watchingPlayers.forEach(player -> {
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_RECORD, passedData);
}
});
JukeboxPacketUpdate.invUpdate = false; JukeboxPacketUpdate.invUpdate = false;
} }
JukeboxPacketUpdate.playerUpdate = world.getPlayers().size(); JukeboxPacketUpdate.playerUpdate = world.getPlayers().size();

View File

@@ -22,6 +22,9 @@
"entrypoints": { "entrypoints": {
"client": [ "client": [
"eu.midnightdust.visualoverhaul.fabric.VisualOverhaulClientFabric" "eu.midnightdust.visualoverhaul.fabric.VisualOverhaulClientFabric"
],
"main": [
"eu.midnightdust.visualoverhaul.fabric.VisualOverhaulFabric"
] ]
}, },

View File

@@ -1,90 +0,0 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
}
architectury {
platformSetupLoomIde()
forge()
}
loom {
forge {
mixinConfig "visualoverhaul.mixins.json"
mixinConfig "visualoverhaul-forge.mixins.json"
}
}
repositories {
maven { url "https://api.modrinth.com/maven" }
}
configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
archivesBaseName = rootProject.archives_base_name + "-forge"
}
dependencies {
forge "net.minecraftforge:forge:${rootProject.forge_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"
modImplementation "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-forge"
//include "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-forge"
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
}
processResources {
inputs.property "version", project.version
filesMatching("META-INF/mods.toml") {
expand "version": project.version
}
}
shadowJar {
exclude "fabric.mod.json"
exclude "architectury.common.json"
configurations = [project.configurations.shadowCommon]
classifier "dev-shadow"
}
remapJar {
input.set shadowJar.archiveFile
dependsOn shadowJar
classifier null
}
jar {
classifier "dev"
}
sourcesJar {
def commonSources = project(":common").sourcesJar
dependsOn commonSources
from commonSources.archiveFile.map { zipTree(it) }
}
components.java {
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
}
publishing {
publications {
mavenForge(MavenPublication) {
artifactId = rootProject.archives_base_name + "-" + project.name
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
}

View File

@@ -1 +0,0 @@
loom.platform=forge

View File

@@ -1,15 +0,0 @@
package eu.midnightdust.visualoverhaul.forge;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
@Mod(MOD_ID)
public class VisualOverhaulForge {
public VisualOverhaulForge() {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> VisualOverhaulClientForge::initClient);
}
}

View File

@@ -1,21 +1,24 @@
org.gradle.jvmargs=-Xmx4096M org.gradle.jvmargs=-Xmx2048M
minecraft_version=1.20 minecraft_version=1.20.4
yarn_mappings=1.20+build.1 yarn_mappings=1.20.4+build.3
enabled_platforms=quilt,fabric,forge enabled_platforms=fabric,neoforge
archives_base_name=visualoverhaul archives_base_name=visualoverhaul
mod_version=5.0.1 mod_version=5.1.0
maven_group=eu.midnightdust maven_group=eu.midnightdust
release_type=release
curseforge_id=432008
modrinth_id=YQnwl5Vv
architectury_version=9.0.7 midnightlib_version=1.5.3
midnightlib_version=1.4.1
phonos_version=0.3.0+1.19.2 phonos_version=0.3.0+1.19.2
fabric_loader_version=0.14.21 fabric_loader_version=0.15.7
fabric_api_version=0.83.0+1.20 fabric_api_version=0.96.3+1.20.4
forge_version=1.20-46.0.13 neoforge_version=20.4.170
architectury_version=11.0.12
quilt_loader_version=0.19.0-beta.18 quilt_loader_version=0.19.0-beta.18
quilt_fabric_api_version=7.0.1+0.83.0-1.20 quilt_fabric_api_version=7.0.1+0.83.0-1.20

View File

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

109
neoforge/build.gradle Normal file
View File

@@ -0,0 +1,109 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "me.shedaniel.unified-publishing"
}
architectury {
injectInjectables = false
platformSetupLoomIde()
neoForge()
}
loom {}
repositories {
maven { url "https://api.modrinth.com/maven" }
maven {url "https://maven.neoforged.net/releases"}
}
configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
archivesBaseName = rootProject.archives_base_name + "-neoforge"
}
dependencies {
neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}"
modImplementation "maven.modrinth:midnightlib:1.5.2-neoforge"
//include "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-forge"
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false }
}
processResources {
inputs.property "version", project.version
filesMatching("META-INF/mods.toml") {
expand "version": project.version
}
}
shadowJar {
exclude "fabric.mod.json"
exclude "architectury.common.json"
configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"
}
remapJar {
input.set shadowJar.archiveFile
dependsOn shadowJar
}
sourcesJar {
def commonSources = project(":common").sourcesJar
dependsOn commonSources
from commonSources.archiveFile.map { zipTree(it) }
}
components.java {
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
}
unifiedPublishing {
project {
displayName = "VisualOverhaul v$project.version - NeoForge $project.minecraft_version"
releaseType = "$project.release_type"
changelog = releaseChangelog()
gameVersions = []
gameLoaders = ["neoforge"]
mainPublication remapJar
relations {
depends {
curseforge = "midnightlib"
modrinth = "midnightlib"
}
includes {}
}
var CURSEFORGE_TOKEN = project.findProperty("CURSEFORGE_TOKEN") ?: System.getenv("CURSEFORGE_TOKEN")
if (CURSEFORGE_TOKEN != null) {
curseforge {
token = CURSEFORGE_TOKEN
id = rootProject.curseforge_id
gameVersions.addAll "Java 17", project.minecraft_version
releaseType = "alpha"
}
}
var MODRINTH_TOKEN = project.findProperty("MODRINTH_TOKEN") ?: System.getenv("MODRINTH_TOKEN")
if (MODRINTH_TOKEN != null) {
modrinth {
token = MODRINTH_TOKEN
id = rootProject.modrinth_id
version = "$project.version-$project.name"
gameVersions.addAll project.minecraft_version
}
}
}
}

View File

@@ -0,0 +1 @@
loom.platform=neoforge

View File

@@ -1,47 +1,27 @@
package eu.midnightdust.visualoverhaul.forge; package eu.midnightdust.visualoverhaul.neoforge;
import eu.midnightdust.visualoverhaul.IconicButtons; import eu.midnightdust.visualoverhaul.IconicButtons;
import eu.midnightdust.visualoverhaul.block.model.FurnaceWoodenPlanksModel; import eu.midnightdust.visualoverhaul.block.model.FurnaceWoodenPlanksModel;
import eu.midnightdust.visualoverhaul.block.renderer.BrewingStandBlockEntityRenderer; import eu.midnightdust.visualoverhaul.block.renderer.BrewingStandBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer; import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer; import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.resource.*; import net.minecraft.resource.*;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraftforge.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; import net.neoforged.fml.ModList;
import net.minecraftforge.event.AddPackFindersEvent; import net.neoforged.fml.common.Mod;
import net.minecraftforge.event.TickEvent; import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.fml.ModList; import net.neoforged.neoforge.event.AddPackFindersEvent;
import net.minecraftforge.fml.common.Mod; import net.neoforged.neoforgespi.locating.IModFile;
import net.minecraftforge.forgespi.locating.IModFile;
import net.minecraftforge.resource.PathPackResources;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID; import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class VisualOverhaulClientEvents { public class VisualOverhaulClientEvents {
@SubscribeEvent
public void registerClientTick(TickEvent.ClientTickEvent event) {
if (VOConfig.coloredItems) {
MinecraftClient client = VisualOverhaulClientForge.client;
if (client.world != null && client.player != null) {
VisualOverhaulClientForge.waterColor = BiomeColors.getWaterColor(client.world, client.player.getBlockPos());
VisualOverhaulClientForge.foliageColor = BiomeColors.getFoliageColor(client.world, client.player.getBlockPos());
VisualOverhaulClientForge.grassColor = BiomeColors.getGrassColor(client.world, client.player.getBlockPos());
} else {
VisualOverhaulClientForge.waterColor = 4159204;
VisualOverhaulClientForge.foliageColor = -8934609;
VisualOverhaulClientForge.grassColor = -8934609;
}
}
}
@SubscribeEvent @SubscribeEvent
public static void registerLayerDefinition(EntityRenderersEvent.RegisterLayerDefinitions event) { public static void registerLayerDefinition(EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(FurnaceWoodenPlanksModel.WOODEN_PLANKS_MODEL_LAYER, FurnaceWoodenPlanksModel::getTexturedModelData); event.registerLayerDefinition(FurnaceWoodenPlanksModel.WOODEN_PLANKS_MODEL_LAYER, FurnaceWoodenPlanksModel::getTexturedModelData);
@@ -77,13 +57,14 @@ public class VisualOverhaulClientEvents {
private static void registerResourcePack(AddPackFindersEvent event, Identifier id, boolean alwaysEnabled, boolean defaultEnabled) { private static void registerResourcePack(AddPackFindersEvent event, Identifier id, boolean alwaysEnabled, boolean defaultEnabled) {
event.addRepositorySource(((profileAdder) -> { event.addRepositorySource(((profileAdder) -> {
IModFile file = ModList.get().getModFileById(id.getNamespace()).getFile(); IModFile file = ModList.get().getModFileById(id.getNamespace()).getFile();
try (PathPackResources pack = new PathPackResources(id.toString(), true, file.findResource("resourcepacks/" +id.getPath()))) { try {
ResourcePackProfile packProfile = ResourcePackProfile.create(id.toString(), Text.of(id.getNamespace()+"/"+id.getPath()), alwaysEnabled, a -> pack, ResourceType.CLIENT_RESOURCES, ResourcePackProfile.InsertionPosition.TOP, ResourcePackSource.BUILTIN); ResourcePackProfile.PackFactory pack = new DirectoryResourcePack.DirectoryBackedFactory(file.findResource("resourcepacks/" + id.getPath()), true);
ResourcePackProfile packProfile = ResourcePackProfile.create(id.toString(), Text.of(id.getNamespace()+"/"+id.getPath()), alwaysEnabled, pack, ResourceType.CLIENT_RESOURCES, ResourcePackProfile.InsertionPosition.TOP, ResourcePackSource.BUILTIN);
if (packProfile != null) { if (packProfile != null) {
profileAdder.accept(packProfile); profileAdder.accept(packProfile);
if (defaultEnabled && !alwaysEnabled) VisualOverhaulClientForge.defaultEnabledPacks.add(packProfile); if (defaultEnabled && !alwaysEnabled) VisualOverhaulClientForge.defaultEnabledPacks.add(packProfile);
} }
} catch (NullPointerException e) {e.printStackTrace();} } catch (NullPointerException e) {e.fillInStackTrace();}
})); }));
} }
} }

View File

@@ -1,44 +1,48 @@
package eu.midnightdust.visualoverhaul.forge; package eu.midnightdust.visualoverhaul.neoforge;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.networking.NetworkManager; import dev.architectury.networking.NetworkManager;
import eu.midnightdust.lib.config.MidnightConfig; import eu.midnightdust.lib.config.MidnightConfig;
import eu.midnightdust.visualoverhaul.VisualOverhaulClient; import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
import eu.midnightdust.visualoverhaul.block.JukeboxTop; import eu.midnightdust.visualoverhaul.block.JukeboxTop;
import eu.midnightdust.visualoverhaul.mixin.JukeboxBlockEntityAccessor; import eu.midnightdust.visualoverhaul.config.VOConfig;
import io.netty.buffer.Unpooled;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BrewingStandBlockEntity; import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.block.entity.JukeboxBlockEntity;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers; import net.minecraft.client.render.RenderLayers;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.MusicDiscItem; import net.minecraft.item.MusicDiscItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.resource.ResourcePackProfile; import net.minecraft.resource.ResourcePackProfile;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.ConfigScreenHandler; import net.neoforged.fml.IExtensionPoint;
import net.minecraftforge.common.MinecraftForge; import net.neoforged.fml.ModLoadingContext;
import net.minecraftforge.fml.IExtensionPoint; import net.neoforged.neoforge.client.ConfigScreenHandler;
import net.minecraftforge.fml.ModLoadingContext; import net.neoforged.neoforge.common.NeoForge;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.neoforge.event.TickEvent;
import net.minecraftforge.network.NetworkConstants; import net.neoforged.neoforge.registries.DeferredRegister;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.commons.compress.utils.Lists; import org.apache.commons.compress.utils.Lists;
import java.util.List; import java.util.List;
import java.util.Objects;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*; import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
import static net.neoforged.fml.IExtensionPoint.DisplayTest.IGNORESERVERONLY;
//@SuppressWarnings("all") @SuppressWarnings("all")
public class VisualOverhaulClientForge { public class VisualOverhaulClientForge {
public static List<ResourcePackProfile> defaultEnabledPacks = Lists.newArrayList(); public static List<ResourcePackProfile> defaultEnabledPacks = Lists.newArrayList();
public static MinecraftClient client = MinecraftClient.getInstance(); public static MinecraftClient client = MinecraftClient.getInstance();
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MOD_ID); private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(Registries.BLOCK, MOD_ID);
public static int waterColor = 4159204; public static int waterColor = 4159204;
public static int foliageColor = -8934609; public static int foliageColor = -8934609;
public static int grassColor = -8934609; public static int grassColor = -8934609;
@@ -46,36 +50,40 @@ public class VisualOverhaulClientForge {
public static void initClient() { public static void initClient() {
VisualOverhaulClient.onInitializeClient(); VisualOverhaulClient.onInitializeClient();
// Block only registered on client, because it's just used for the renderer // // Block only registered on client, because it's just used for the renderer //
BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()); BLOCKS.register(Objects.requireNonNull(ModLoadingContext.get().getActiveContainer().getEventBus()));
BLOCKS.register("jukebox_top", () -> { BLOCKS.register("jukebox_top", () -> {
VisualOverhaulClient.JukeBoxTop = new JukeboxTop(); VisualOverhaulClient.JukeBoxTop = new JukeboxTop();
return VisualOverhaulClient.JukeBoxTop; return VisualOverhaulClient.JukeBoxTop;
}); });
NeoForge.EVENT_BUS.addListener(VisualOverhaulClientForge::doClientTick);
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (remote, server) -> true)); ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> IGNORESERVERONLY, (remote, server) -> true));
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> MidnightConfig.getScreen(parent, MOD_ID))); new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> MidnightConfig.getScreen(parent, MOD_ID)));
MinecraftForge.EVENT_BUS.register(new VisualOverhaulClientEvents()); Registries.ITEM.forEach((item) -> {
ForgeRegistries.ITEMS.forEach((item) -> {
if(item instanceof MusicDiscItem || item.getName().getString().toLowerCase().contains("music_disc") || item.getName().getString().toLowerCase().contains("record") || item.getName().getString().toLowerCase().contains("dynamic_disc")) { if(item instanceof MusicDiscItem || item.getName().getString().toLowerCase().contains("music_disc") || item.getName().getString().toLowerCase().contains("record") || item.getName().getString().toLowerCase().contains("dynamic_disc")) {
ModelPredicateProviderRegistry.register(item, new Identifier("round"), (stack, world, entity, seed) -> stack.getCount() == 2 ? 1.0F : 0.0F); ModelPredicateProviderRegistry.register(item, new Identifier("round"), (stack, world, entity, seed) -> stack.getCount() == 2 ? 1.0F : 0.0F);
} }
}); });
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(player -> {
if (player != null) {
NetworkManager.sendToServer(HELLO_PACKET, new PacketByteBuf(Unpooled.buffer()));
}
});
NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_POTION_BOTTLES, NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_POTION_BOTTLES,
(attachedData, packetSender) -> { (attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos(); BlockPos pos = attachedData.readBlockPos();
DefaultedList<ItemStack> inv = DefaultedList.ofSize(5, ItemStack.EMPTY); DefaultedList<ItemStack> inv = DefaultedList.ofSize(5, ItemStack.EMPTY);
for (int i = 0; i < 4; i++) { for (int i = 0; i <= 4; i++) {
inv.set(i, attachedData.readItemStack()); inv.set(i, attachedData.readItemStack());
} }
client.execute(() -> { client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity blockEntity) { if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity blockEntity) {
blockEntity.setStack(0, inv.get(0)); for (int i = 0; i <= 4; i++) {
blockEntity.setStack(1, inv.get(1)); blockEntity.setStack(i, inv.get(i));
blockEntity.setStack(2, inv.get(2)); }
blockEntity.setStack(3, inv.get(3));
blockEntity.setStack(4, inv.get(4));
} }
}); });
}); });
@@ -84,23 +92,21 @@ public class VisualOverhaulClientForge {
BlockPos pos = attachedData.readBlockPos(); BlockPos pos = attachedData.readBlockPos();
ItemStack record = attachedData.readItemStack(); ItemStack record = attachedData.readItemStack();
client.execute(() -> { client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof JukeboxBlockEntity blockEntity) { jukeboxItems.put(pos, record);
((JukeboxBlockEntityAccessor)blockEntity).getInventory().set(0, record);
}
}); });
}); });
NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_FURNACE_ITEMS, NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_FURNACE_ITEMS,
(attachedData, packetSender) -> { (attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos(); BlockPos pos = attachedData.readBlockPos();
DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY); DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY);
for (int i = 0; i < 2; i++) { for (int i = 0; i <= 2; i++) {
inv.set(i, attachedData.readItemStack()); inv.set(i, attachedData.readItemStack());
} }
client.execute(() -> { client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof AbstractFurnaceBlockEntity blockEntity) { if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof AbstractFurnaceBlockEntity blockEntity) {
blockEntity.setStack(0, inv.get(0)); for (int i = 0; i <= 2; i++) {
blockEntity.setStack(1, inv.get(1)); blockEntity.setStack(i, inv.get(i));
blockEntity.setStack(2, inv.get(2)); }
} }
}); });
}); });
@@ -109,4 +115,18 @@ public class VisualOverhaulClientForge {
RenderLayers.setRenderLayer(Blocks.SMOKER, RenderLayer.getCutout()); RenderLayers.setRenderLayer(Blocks.SMOKER, RenderLayer.getCutout());
RenderLayers.setRenderLayer(Blocks.BLAST_FURNACE, RenderLayer.getCutout()); RenderLayers.setRenderLayer(Blocks.BLAST_FURNACE, RenderLayer.getCutout());
} }
public static void doClientTick(TickEvent.ClientTickEvent event) {
if (VOConfig.coloredItems && event.phase == TickEvent.Phase.START) {
MinecraftClient client = VisualOverhaulClientForge.client;
if (client.world != null && client.player != null) {
VisualOverhaulClientForge.waterColor = BiomeColors.getWaterColor(client.world, client.player.getBlockPos());
VisualOverhaulClientForge.foliageColor = BiomeColors.getFoliageColor(client.world, client.player.getBlockPos());
VisualOverhaulClientForge.grassColor = BiomeColors.getGrassColor(client.world, client.player.getBlockPos());
} else {
VisualOverhaulClientForge.waterColor = 4159204;
VisualOverhaulClientForge.foliageColor = -8934609;
VisualOverhaulClientForge.grassColor = -8934609;
}
}
}
} }

View File

@@ -0,0 +1,25 @@
package eu.midnightdust.visualoverhaul.neoforge;
import dev.architectury.event.events.common.PlayerEvent;
import dev.architectury.networking.NetworkManager;
import eu.midnightdust.visualoverhaul.VisualOverhaul;
import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLEnvironment;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
@Mod(MOD_ID)
public class VisualOverhaulForge {
public VisualOverhaulForge() {
if (FMLEnvironment.dist == Dist.CLIENT) VisualOverhaulClientForge.initClient();
NetworkManager.registerReceiver(NetworkManager.Side.C2S, HELLO_PACKET, (attachedData, packetSender) -> VisualOverhaul.playersWithMod.add(packetSender.getPlayer().getUuid()));
PlayerEvent.PLAYER_QUIT.register(player -> playersWithMod.remove(player.getUuid()));
}
}

View File

@@ -1,4 +1,4 @@
package eu.midnightdust.visualoverhaul.forge.mixin; package eu.midnightdust.visualoverhaul.neoforge.mixin;
import dev.architectury.networking.NetworkManager; import dev.architectury.networking.NetworkManager;
import eu.midnightdust.visualoverhaul.VisualOverhaul; import eu.midnightdust.visualoverhaul.VisualOverhaul;
@@ -15,6 +15,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -25,8 +26,10 @@ import java.util.stream.Stream;
@Mixin(AbstractFurnaceBlockEntity.class) @Mixin(AbstractFurnaceBlockEntity.class)
public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity { public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity {
private static boolean invUpdate = true; @Unique
private static int playerUpdate = -1; private static boolean visualoverhaul$invUpdate = true;
@Unique
private static int visualoverhaul$playerUpdate = -1;
protected MixinAbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { protected MixinAbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
@@ -36,7 +39,7 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
@Inject(at = @At("TAIL"), method = "tick") @Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) { private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
if (world.getBlockState(pos).hasBlockEntity()) { if (world.getBlockState(pos).hasBlockEntity()) {
if (!world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) { if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream(); Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos); passedData.writeBlockPos(pos);
@@ -44,15 +47,19 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
passedData.writeItemStack(blockEntity.getStack(1)); passedData.writeItemStack(blockEntity.getStack(1));
passedData.writeItemStack(blockEntity.getStack(2)); passedData.writeItemStack(blockEntity.getStack(2));
watchingPlayers.forEach(player -> NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData)); watchingPlayers.forEach(player -> {
invUpdate = false; if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData);
}
});
visualoverhaul$invUpdate = false;
} }
playerUpdate = world.getPlayers().size(); visualoverhaul$playerUpdate = world.getPlayers().size();
} }
} }
@Inject(at = @At("RETURN"), method = "getStack") @Inject(at = @At("RETURN"), method = "getStack")
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) { public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
invUpdate = true; visualoverhaul$invUpdate = true;
} }
} }

View File

@@ -1,4 +1,4 @@
package eu.midnightdust.visualoverhaul.forge.mixin; package eu.midnightdust.visualoverhaul.neoforge.mixin;
import eu.midnightdust.visualoverhaul.config.VOConfig; import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;

View File

@@ -1,4 +1,4 @@
package eu.midnightdust.visualoverhaul.forge.mixin; package eu.midnightdust.visualoverhaul.neoforge.mixin;
import dev.architectury.networking.NetworkManager; import dev.architectury.networking.NetworkManager;
import eu.midnightdust.visualoverhaul.VisualOverhaul; import eu.midnightdust.visualoverhaul.VisualOverhaul;
@@ -15,6 +15,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -25,8 +26,10 @@ import java.util.stream.Stream;
@Mixin(BrewingStandBlockEntity.class) @Mixin(BrewingStandBlockEntity.class)
public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity { public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity {
private static boolean invUpdate = true; @Unique
private static int playerUpdate = -1; private static boolean visualoverhaul$invUpdate = true;
@Unique
private static int visualoverhaul$playerUpdate = -1;
protected MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { protected MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState); super(blockEntityType, blockPos, blockState);
@@ -34,7 +37,7 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
@Inject(at = @At("TAIL"), method = "tick") @Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, BrewingStandBlockEntity blockEntity, CallbackInfo ci) { private static void tick(World world, BlockPos pos, BlockState state, BrewingStandBlockEntity blockEntity, CallbackInfo ci) {
if (!world.isClient && (invUpdate || world.getPlayers().size() == playerUpdate)) { if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream(); Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos); passedData.writeBlockPos(pos);
@@ -44,14 +47,18 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
passedData.writeItemStack(blockEntity.getStack(3)); passedData.writeItemStack(blockEntity.getStack(3));
passedData.writeItemStack(blockEntity.getStack(4)); passedData.writeItemStack(blockEntity.getStack(4));
watchingPlayers.forEach(player -> NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData)); watchingPlayers.forEach(player -> {
invUpdate = false; if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData);
}
});
visualoverhaul$invUpdate = false;
} }
playerUpdate = world.getPlayers().size(); visualoverhaul$playerUpdate = world.getPlayers().size();
} }
@Inject(at = @At("RETURN"), method = "getStack") @Inject(at = @At("RETURN"), method = "getStack")
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) { public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
invUpdate = true; visualoverhaul$invUpdate = true;
} }
} }

View File

@@ -1,4 +1,4 @@
package eu.midnightdust.visualoverhaul.forge.mixin; package eu.midnightdust.visualoverhaul.neoforge.mixin;
import eu.midnightdust.visualoverhaul.config.VOConfig; import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.block.BlockColors;
@@ -11,9 +11,9 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import static eu.midnightdust.visualoverhaul.forge.VisualOverhaulClientForge.grassColor; import static eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge.grassColor;
import static eu.midnightdust.visualoverhaul.forge.VisualOverhaulClientForge.foliageColor; import static eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge.foliageColor;
import static eu.midnightdust.visualoverhaul.forge.VisualOverhaulClientForge.waterColor; import static eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge.waterColor;
@Mixin(ItemColors.class) @Mixin(ItemColors.class)
public abstract class MixinItemColors { public abstract class MixinItemColors {
@@ -28,7 +28,7 @@ public abstract class MixinItemColors {
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.TROPICAL_FISH_BUCKET); itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.TROPICAL_FISH_BUCKET);
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.SALMON_BUCKET); itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.SALMON_BUCKET);
itemColors.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK); itemColors.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK);
itemColors.register((stack, tintIndex) -> grassColor, Items.GRASS); itemColors.register((stack, tintIndex) -> grassColor, Items.SHORT_GRASS);
itemColors.register((stack, tintIndex) -> grassColor, Items.TALL_GRASS); itemColors.register((stack, tintIndex) -> grassColor, Items.TALL_GRASS);
itemColors.register((stack, tintIndex) -> grassColor, Items.FERN); itemColors.register((stack, tintIndex) -> grassColor, Items.FERN);
itemColors.register((stack, tintIndex) -> grassColor, Items.LARGE_FERN); itemColors.register((stack, tintIndex) -> grassColor, Items.LARGE_FERN);

View File

@@ -1,4 +1,4 @@
package eu.midnightdust.visualoverhaul.forge.mixin; package eu.midnightdust.visualoverhaul.neoforge.mixin;
import dev.architectury.networking.NetworkManager; import dev.architectury.networking.NetworkManager;
import eu.midnightdust.visualoverhaul.VisualOverhaul; import eu.midnightdust.visualoverhaul.VisualOverhaul;
@@ -38,17 +38,21 @@ public abstract class MixinJukeboxBlock extends BlockWithEntity {
@Nullable @Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient() ? null : checkType(type, BlockEntityType.JUKEBOX, MixinJukeboxBlock::tick); return world.isClient() ? null : validateTicker(type, BlockEntityType.JUKEBOX, MixinJukeboxBlock::visualoverhaul$tick);
} }
@Unique @Unique
private static void tick(World world, BlockPos pos, BlockState state, JukeboxBlockEntity blockEntity) { private static void visualoverhaul$tick(World world, BlockPos pos, BlockState state, JukeboxBlockEntity blockEntity) {
if (!world.isClient && (JukeboxPacketUpdate.invUpdate || world.getPlayers().size() == JukeboxPacketUpdate.playerUpdate)) { if (!world.isClient && (JukeboxPacketUpdate.invUpdate || world.getPlayers().size() == JukeboxPacketUpdate.playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream(); Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos); passedData.writeBlockPos(pos);
passedData.writeItemStack(blockEntity.getStack()); passedData.writeItemStack(blockEntity.getStack());
watchingPlayers.forEach(player -> NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_RECORD, passedData)); watchingPlayers.forEach(player -> {
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_RECORD, passedData);
}
});
JukeboxPacketUpdate.invUpdate = false; JukeboxPacketUpdate.invUpdate = false;
} }
JukeboxPacketUpdate.playerUpdate = world.getPlayers().size(); JukeboxPacketUpdate.playerUpdate = world.getPlayers().size();

View File

@@ -1,7 +1,7 @@
package eu.midnightdust.visualoverhaul.forge.mixin; package eu.midnightdust.visualoverhaul.neoforge.mixin;
import eu.midnightdust.visualoverhaul.config.VOConfig; import eu.midnightdust.visualoverhaul.config.VOConfig;
import eu.midnightdust.visualoverhaul.forge.VisualOverhaulClientForge; import eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge;
import net.minecraft.resource.ResourcePackManager; import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackProfile; import net.minecraft.resource.ResourcePackProfile;
import org.apache.commons.compress.utils.Lists; import org.apache.commons.compress.utils.Lists;
@@ -19,7 +19,7 @@ import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
public abstract class MixinResourcePackManager { public abstract class MixinResourcePackManager {
@Shadow private List<ResourcePackProfile> enabled; @Shadow private List<ResourcePackProfile> enabled;
@Inject(method = "Lnet/minecraft/resource/ResourcePackManager;setEnabledProfiles(Ljava/util/Collection;)V", at = @At("TAIL")) @Inject(method = "setEnabledProfiles(Ljava/util/Collection;)V", at = @At("TAIL"))
private void setDefaultEnabledPacks(CallbackInfo info) { private void setDefaultEnabledPacks(CallbackInfo info) {
if (VOConfig.firstLaunch) { if (VOConfig.firstLaunch) {
List<ResourcePackProfile> enabledPacks = Lists.newArrayList(); List<ResourcePackProfile> enabledPacks = Lists.newArrayList();

View File

@@ -1,7 +1,7 @@
package eu.midnightdust.visualoverhaul.util.forge; package eu.midnightdust.visualoverhaul.util.neoforge;
import net.minecraftforge.fml.ModList; import net.neoforged.fml.ModList;
import net.minecraftforge.forgespi.language.IModInfo; import net.neoforged.neoforgespi.language.IModInfo;
import java.nio.file.Path; import java.nio.file.Path;

View File

@@ -1,5 +1,5 @@
modLoader = "javafml" modLoader = "javafml"
loaderVersion = "[43,)" loaderVersion = "[1,)"
#issueTrackerURL = "" #issueTrackerURL = ""
license = "MIT License" license = "MIT License"
@@ -12,31 +12,35 @@ description = '''
Adds better visuals for certain Minecraft Vanilla Blocks. Adds better visuals for certain Minecraft Vanilla Blocks.
''' '''
logoFile = "icon.png" logoFile = "icon.png"
[[mixins]]
config = "visualoverhaul.mixins.json"
[[mixins]]
config = "visualoverhaul-neoforge.mixins.json"
[[dependencies.visualoverhaul]] [[dependencies.visualoverhaul]]
modId = "forge" modId = "neoforge"
mandatory = true required = true
versionRange = "[43,)" versionRange = "[1,)"
ordering = "NONE" ordering = "NONE"
side = "CLIENT" side = "CLIENT"
[[dependencies.visualoverhaul]] [[dependencies.visualoverhaul]]
modId = "minecraft" modId = "minecraft"
mandatory = true required = true
versionRange = "[1.19.2,)" versionRange = "[1.19.2,)"
ordering = "NONE" ordering = "NONE"
side = "CLIENT" side = "CLIENT"
[[dependencies.visualoverhaul]] [[dependencies.visualoverhaul]]
modId = "midnightlib" modId = "midnightlib"
mandatory = true required = true
versionRange = "[1.0.0,)" versionRange = "[1.0.0,)"
ordering = "BEFORE" ordering = "BEFORE"
side = "CLIENT" side = "CLIENT"
[[dependencies.visualoverhaul]] [[dependencies.visualoverhaul]]
modId = "architectury" modId = "architectury"
mandatory = true required = true
versionRange = "[6.0.0,)" versionRange = "[6.0.0,)"
ordering = "BEFORE" ordering = "BEFORE"
side = "BOTH" side = "BOTH"

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@@ -1,6 +1,6 @@
{ {
"required": true, "required": true,
"package": "eu.midnightdust.visualoverhaul.forge.mixin", "package": "eu.midnightdust.visualoverhaul.neoforge.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"minVersion": "0.8", "minVersion": "0.8",
"mixins": [ "mixins": [

View File

@@ -2,14 +2,14 @@ pluginManagement {
repositories { repositories {
maven { url "https://maven.fabricmc.net/" } maven { url "https://maven.fabricmc.net/" }
maven { url "https://maven.architectury.dev/" } maven { url "https://maven.architectury.dev/" }
maven { url "https://maven.minecraftforge.net/" } maven { url "https://maven.neoforged.net/releases" }
gradlePluginPortal() gradlePluginPortal()
} }
} }
include("common") include("common")
include("fabric") include("fabric")
include("quilt") //include("quilt")
include("forge") include("neoforge")
rootProject.name = "visualoverhaul" rootProject.name = "visualoverhaul"