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,5 +1,6 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "me.shedaniel.unified-publishing"
}
architectury {
@@ -44,21 +45,18 @@ processResources {
}
}
shadowJar {
exclude "architectury.common.json"
configurations = [project.configurations.shadowCommon]
classifier "dev-shadow"
archiveClassifier = "dev-shadow"
}
remapJar {
injectAccessWidener = true
input.set shadowJar.archiveFile
dependsOn shadowJar
classifier null
}
jar {
classifier "dev"
}
sourcesJar {
@@ -73,16 +71,42 @@ components.java {
}
}
publishing {
publications {
mavenFabric(MavenPublication) {
artifactId = rootProject.archives_base_name + "-" + project.name
from components.java
unifiedPublishing {
project {
displayName = "VisualOverhaul v$project.version - Fabric $project.minecraft_version"
releaseType = "$project.release_type"
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.JukeboxBlockEntityRenderer;
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.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
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.rendering.v1.ColorProviderRegistry;
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.BlockEntityType;
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.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.texture.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.MusicDiscItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.registry.Registries;
@@ -42,10 +41,6 @@ import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
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.VisualOverhaulClient.JukeBoxTop;
@@ -87,16 +82,14 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
(client, handler, attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos();
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());
}
client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof BrewingStandBlockEntity blockEntity) {
blockEntity.setStack(0, inv.get(0));
blockEntity.setStack(1, inv.get(1));
blockEntity.setStack(2, inv.get(2));
blockEntity.setStack(3, inv.get(3));
blockEntity.setStack(4, inv.get(4));
for (int i = 0; i <= 4; i++) {
blockEntity.setStack(i, inv.get(i));
}
}
});
});
@@ -105,23 +98,21 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
BlockPos pos = attachedData.readBlockPos();
ItemStack record = attachedData.readItemStack();
client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof JukeboxBlockEntity blockEntity) {
((JukeboxBlockEntityAccessor)blockEntity).getInventory().set(0, record);
}
jukeboxItems.put(pos, record);
});
});
ClientPlayNetworking.registerGlobalReceiver(UPDATE_FURNACE_ITEMS,
(client, handler, attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos();
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());
}
client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof AbstractFurnaceBlockEntity blockEntity) {
blockEntity.setStack(0, inv.get(0));
blockEntity.setStack(1, inv.get(1));
blockEntity.setStack(2, inv.get(2));
for (int i = 0; i <= 2; i++) {
blockEntity.setStack(i, inv.get(i));
}
}
});
});
@@ -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,"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
@@ -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.SALMON_BUCKET);
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.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.world.World;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -24,8 +25,10 @@ import java.util.stream.Stream;
@Mixin(AbstractFurnaceBlockEntity.class)
public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity {
private static boolean invUpdate = true;
private static int playerUpdate = -1;
@Unique
private static boolean visualoverhaul$invUpdate = true;
@Unique
private static int visualoverhaul$playerUpdate = -1;
protected MixinAbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
@@ -35,7 +38,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) {
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();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos);
@@ -43,15 +46,19 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
passedData.writeItemStack(blockEntity.getStack(1));
passedData.writeItemStack(blockEntity.getStack(2));
watchingPlayers.forEach(player -> ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData));
invUpdate = false;
watchingPlayers.forEach(player -> {
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")
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.world.World;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -24,8 +25,10 @@ import java.util.stream.Stream;
@Mixin(BrewingStandBlockEntity.class)
public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity {
private static boolean invUpdate = true;
private static int playerUpdate = -1;
@Unique
private static boolean visualoverhaul$invUpdate = true;
@Unique
private static int visualoverhaul$playerUpdate = -1;
protected MixinBrewingStandBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState);
@@ -33,7 +36,7 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
@Inject(at = @At("TAIL"), method = "tick")
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();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos);
@@ -43,14 +46,18 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
passedData.writeItemStack(blockEntity.getStack(3));
passedData.writeItemStack(blockEntity.getStack(4));
watchingPlayers.forEach(player -> ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData));
invUpdate = false;
watchingPlayers.forEach(player -> {
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")
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
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
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)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos);
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.playerUpdate = world.getPlayers().size();

View File

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