mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 05:55:09 +01:00
Port to 1.21
- Rewrite packet system to use vanilla payloads - Water bottles will now appear slightly transparent - One of the hardest 1.21 ports yet
This commit is contained in:
@@ -1,59 +1,67 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||
id 'com.github.johnrengelman.shadow'
|
||||
id "me.shedaniel.unified-publishing"
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://api.modrinth.com/maven" }
|
||||
maven {
|
||||
name = 'NeoForged'
|
||||
url = 'https://maven.neoforged.net/releases'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
architectury {
|
||||
injectInjectables = false
|
||||
platformSetupLoomIde()
|
||||
neoForge()
|
||||
}
|
||||
|
||||
loom {}
|
||||
repositories {
|
||||
maven { url "https://api.modrinth.com/maven" }
|
||||
maven {url "https://maven.neoforged.net/releases"}
|
||||
loom {
|
||||
accessWidenerPath = project(":common").loom.accessWidenerPath
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
common {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentForge.extendsFrom common
|
||||
developmentNeoForge.extendsFrom common
|
||||
|
||||
// Files in this configuration will be bundled into your mod using the Shadow plugin.
|
||||
// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
|
||||
shadowBundle {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
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"
|
||||
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
|
||||
modImplementation "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-neoforge"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false }
|
||||
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
|
||||
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property 'version', project.version
|
||||
|
||||
filesMatching("META-INF/mods.toml") {
|
||||
expand "version": project.version
|
||||
filesMatching('META-INF/neoforge.mods.toml') {
|
||||
expand version: project.version
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
exclude "fabric.mod.json"
|
||||
exclude "architectury.common.json"
|
||||
|
||||
configurations = [project.configurations.shadowCommon]
|
||||
archiveClassifier = "dev-shadow"
|
||||
configurations = [project.configurations.shadowBundle]
|
||||
archiveClassifier = 'dev-shadow'
|
||||
}
|
||||
|
||||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
@@ -91,7 +99,7 @@ unifiedPublishing {
|
||||
curseforge {
|
||||
token = CURSEFORGE_TOKEN
|
||||
id = rootProject.curseforge_id
|
||||
gameVersions.addAll "Java 17", project.minecraft_version
|
||||
gameVersions.addAll "Java 21", project.minecraft_version
|
||||
releaseType = "alpha"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,28 @@ import eu.midnightdust.visualoverhaul.block.model.FurnaceWoodenPlanksModel;
|
||||
import eu.midnightdust.visualoverhaul.block.renderer.BrewingStandBlockEntityRenderer;
|
||||
import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer;
|
||||
import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer;
|
||||
import eu.midnightdust.visualoverhaul.packet.HelloPacket;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.resource.*;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
|
||||
import net.neoforged.neoforge.event.AddPackFindersEvent;
|
||||
import net.neoforged.neoforgespi.locating.IModFile;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.MOD_ID;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.id;
|
||||
|
||||
@EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
public class VisualOverhaulClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinition(EntityRenderersEvent.RegisterLayerDefinitions event) {
|
||||
@@ -48,18 +54,19 @@ public class VisualOverhaulClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void addPackFinders(AddPackFindersEvent event) {
|
||||
if (event.getPackType() == ResourceType.CLIENT_RESOURCES) {
|
||||
registerResourcePack(event, new Identifier(MOD_ID,"nobrewingbottles"), false, true);
|
||||
registerResourcePack(event, new Identifier(MOD_ID,"fancyfurnace"), false, true);
|
||||
registerResourcePack(event, new Identifier(MOD_ID,"coloredwaterbucket"), false, true);
|
||||
registerResourcePack(event, new Identifier(MOD_ID,"rounddiscs"), true, false);
|
||||
registerResourcePack(event, id("nobrewingbottles"), false, true);
|
||||
registerResourcePack(event, id("fancyfurnace"), false, true);
|
||||
registerResourcePack(event, id("coloredwaterbucket"), false, true);
|
||||
registerResourcePack(event, id("rounddiscs"), true, false);
|
||||
}
|
||||
}
|
||||
private static void registerResourcePack(AddPackFindersEvent event, Identifier id, boolean alwaysEnabled, boolean defaultEnabled) {
|
||||
event.addRepositorySource(((profileAdder) -> {
|
||||
IModFile file = ModList.get().getModFileById(id.getNamespace()).getFile();
|
||||
try {
|
||||
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);
|
||||
ResourcePackProfile.PackFactory pack = new DirectoryResourcePack.DirectoryBackedFactory(file.findResource("resourcepacks/" + id.getPath()));
|
||||
ResourcePackInfo info = new ResourcePackInfo(id.toString(), Text.of(id.getNamespace()+"/"+id.getPath()), ResourcePackSource.BUILTIN, Optional.empty());
|
||||
ResourcePackProfile packProfile = ResourcePackProfile.create(info, pack, ResourceType.CLIENT_RESOURCES, new ResourcePackPosition(alwaysEnabled, ResourcePackProfile.InsertionPosition.TOP, false));
|
||||
if (packProfile != null) {
|
||||
profileAdder.accept(packProfile);
|
||||
if (defaultEnabled && !alwaysEnabled) VisualOverhaulClientForge.defaultEnabledPacks.add(packProfile);
|
||||
|
||||
@@ -1,51 +1,37 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge;
|
||||
|
||||
import dev.architectury.event.events.client.ClientPlayerEvent;
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
|
||||
import eu.midnightdust.visualoverhaul.block.JukeboxTop;
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import eu.midnightdust.visualoverhaul.util.VOColorUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.block.entity.BrewingStandBlockEntity;
|
||||
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.RenderLayers;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.MusicDiscItem;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.neoforged.fml.IExtensionPoint;
|
||||
import net.neoforged.fml.ModLoadingContext;
|
||||
import net.neoforged.neoforge.client.ConfigScreenHandler;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
|
||||
import static net.neoforged.fml.IExtensionPoint.DisplayTest.IGNORESERVERONLY;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.*;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.*;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class VisualOverhaulClientForge {
|
||||
public static List<ResourcePackProfile> defaultEnabledPacks = Lists.newArrayList();
|
||||
public static MinecraftClient client = MinecraftClient.getInstance();
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(Registries.BLOCK, MOD_ID);
|
||||
public static int waterColor = 4159204;
|
||||
public static int foliageColor = -8934609;
|
||||
public static int grassColor = -8934609;
|
||||
|
||||
public static void initClient() {
|
||||
VisualOverhaulClient.onInitializeClient();
|
||||
@@ -57,75 +43,30 @@ public class VisualOverhaulClientForge {
|
||||
});
|
||||
NeoForge.EVENT_BUS.addListener(VisualOverhaulClientForge::doClientTick);
|
||||
|
||||
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> IGNORESERVERONLY, (remote, server) -> true));
|
||||
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
|
||||
new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> MidnightConfig.getScreen(parent, MOD_ID)));
|
||||
Registries.ITEM.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")) {
|
||||
ModelPredicateProviderRegistry.register(item, new Identifier("round"), (stack, world, entity, seed) -> stack.getCount() == 2 ? 1.0F : 0.0F);
|
||||
}
|
||||
ModelPredicateProviderRegistry.register(item, Identifier.ofVanilla("round"), (stack, world, entity, seed) ->
|
||||
stack.getComponents().contains(DataComponentTypes.JUKEBOX_PLAYABLE) && stack.getComponents().contains(DataComponentTypes.CUSTOM_MODEL_DATA) &&
|
||||
stack.getComponents().get(DataComponentTypes.CUSTOM_MODEL_DATA).value() == 710 ? 1.0F : 0.0F);
|
||||
});
|
||||
|
||||
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,
|
||||
(attachedData, packetSender) -> {
|
||||
BlockPos pos = attachedData.readBlockPos();
|
||||
DefaultedList<ItemStack> inv = DefaultedList.ofSize(5, ItemStack.EMPTY);
|
||||
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) {
|
||||
for (int i = 0; i <= 4; i++) {
|
||||
blockEntity.setStack(i, inv.get(i));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_RECORD,
|
||||
(attachedData, packetSender) -> {
|
||||
BlockPos pos = attachedData.readBlockPos();
|
||||
ItemStack record = attachedData.readItemStack();
|
||||
client.execute(() -> {
|
||||
jukeboxItems.put(pos, record);
|
||||
});
|
||||
});
|
||||
NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_FURNACE_ITEMS,
|
||||
(attachedData, packetSender) -> {
|
||||
BlockPos pos = attachedData.readBlockPos();
|
||||
DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY);
|
||||
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) {
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
blockEntity.setStack(i, inv.get(i));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
RenderLayers.setRenderLayer(Blocks.JUKEBOX, RenderLayer.getCutout());
|
||||
RenderLayers.setRenderLayer(Blocks.FURNACE, RenderLayer.getCutout());
|
||||
RenderLayers.setRenderLayer(Blocks.SMOKER, RenderLayer.getCutout());
|
||||
RenderLayers.setRenderLayer(Blocks.BLAST_FURNACE, RenderLayer.getCutout());
|
||||
}
|
||||
public static void doClientTick(TickEvent.ClientTickEvent event) {
|
||||
if (VOConfig.coloredItems && event.phase == TickEvent.Phase.START) {
|
||||
public static void doClientTick(ClientTickEvent.Pre 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());
|
||||
waterColor = BiomeColors.getWaterColor(client.world, client.player.getBlockPos());
|
||||
foliageColor = BiomeColors.getFoliageColor(client.world, client.player.getBlockPos());
|
||||
grassColor = BiomeColors.getGrassColor(client.world, client.player.getBlockPos());
|
||||
potionColor = VOColorUtil.convertRgbToArgb(waterColor);
|
||||
} else {
|
||||
VisualOverhaulClientForge.waterColor = 4159204;
|
||||
VisualOverhaulClientForge.foliageColor = -8934609;
|
||||
VisualOverhaulClientForge.grassColor = -8934609;
|
||||
waterColor = 4159204;
|
||||
foliageColor = -8934609;
|
||||
grassColor = -8934609;
|
||||
potionColor = -13083194;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
|
||||
import eu.midnightdust.visualoverhaul.packet.HelloPacket;
|
||||
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.block.entity.BrewingStandBlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.*;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.UPDATE_TYPE_FURNACE_ITEMS;
|
||||
|
||||
@EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.MOD)
|
||||
public class VisualOverhaulEvents {
|
||||
@SubscribeEvent
|
||||
public static void registerPayloads(RegisterPayloadHandlersEvent event) {
|
||||
PayloadRegistrar registrar = event.registrar("1");
|
||||
registrar.commonToServer(HelloPacket.PACKET_ID, HelloPacket.codec, (payload, context) -> {
|
||||
VisualOverhaulCommon.playersWithMod.add(context.player().getUuid());
|
||||
});
|
||||
registrar.playToClient(UpdateItemsPacket.PACKET_ID, UpdateItemsPacket.codec, (payload, context) -> {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
client.execute(() -> {
|
||||
System.out.println(payload.blockTypeID().toString());
|
||||
if (payload.blockTypeID().equals(UPDATE_TYPE_RECORD))
|
||||
jukeboxItems.put(payload.pos(), payload.inv().getFirst());
|
||||
else if (client.world != null && client.world.getBlockEntity(payload.pos()) != null) {
|
||||
if (payload.blockTypeID().equals(UPDATE_TYPE_POTION_BOTTLES) && client.world.getBlockEntity(payload.pos()) instanceof BrewingStandBlockEntity brewingStand) {
|
||||
for (int i = 0; i <= 4; i++) {
|
||||
brewingStand.setStack(i, payload.inv().get(i));
|
||||
}
|
||||
} else if (payload.blockTypeID().equals(UPDATE_TYPE_FURNACE_ITEMS) && client.world.getBlockEntity(payload.pos()) instanceof AbstractFurnaceBlockEntity furnace) {
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
furnace.setStack(i, payload.inv().get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +1,15 @@
|
||||
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.*;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.*;
|
||||
|
||||
@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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.packet.HelloPacket;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.MOD_ID;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.playersWithMod;
|
||||
|
||||
@EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.GAME)
|
||||
public class VisualOverhaulGameEvents {
|
||||
@SubscribeEvent()
|
||||
public static void sendPacketOnLogin(ClientPlayerNetworkEvent.LoggingIn event) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
if (client.getNetworkHandler() != null)
|
||||
client.getNetworkHandler().send(new HelloPacket(event.getPlayer().getUuid()));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void removeOnLogout(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
playersWithMod.remove(event.getEntity().getUuid());
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
|
||||
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -40,26 +39,25 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
|
||||
private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
|
||||
if (world.getBlockState(pos).hasBlockEntity()) {
|
||||
if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
|
||||
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
|
||||
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
|
||||
passedData.writeBlockPos(pos);
|
||||
passedData.writeItemStack(blockEntity.getStack(0));
|
||||
passedData.writeItemStack(blockEntity.getStack(1));
|
||||
passedData.writeItemStack(blockEntity.getStack(2));
|
||||
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).chunkLoadingManager.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
|
||||
DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY);
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
inv.set(i, blockEntity.getStack(i));
|
||||
}
|
||||
|
||||
watchingPlayers.forEach(player -> {
|
||||
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
|
||||
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData);
|
||||
if (VisualOverhaulCommon.playersWithMod.contains(player.getUuid())) {
|
||||
player.networkHandler.send(new UpdateItemsPacket(VisualOverhaulCommon.UPDATE_TYPE_FURNACE_ITEMS, pos, inv));
|
||||
}
|
||||
});
|
||||
visualoverhaul$invUpdate = false;
|
||||
//visualoverhaul$invUpdate = false;
|
||||
}
|
||||
visualoverhaul$playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
@Inject(at = @At("RETURN"), method = "getHeldStacks")
|
||||
public void getStack(CallbackInfoReturnable<DefaultedList<ItemStack>> cir) {
|
||||
visualoverhaul$invUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
|
||||
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.BrewingStandBlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -38,18 +37,14 @@ 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 && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
|
||||
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
|
||||
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
|
||||
passedData.writeBlockPos(pos);
|
||||
passedData.writeItemStack(blockEntity.getStack(0));
|
||||
passedData.writeItemStack(blockEntity.getStack(1));
|
||||
passedData.writeItemStack(blockEntity.getStack(2));
|
||||
passedData.writeItemStack(blockEntity.getStack(3));
|
||||
passedData.writeItemStack(blockEntity.getStack(4));
|
||||
|
||||
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).chunkLoadingManager.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
|
||||
DefaultedList<ItemStack> inv = DefaultedList.ofSize(5, ItemStack.EMPTY);
|
||||
for (int i = 0; i <= 4; i++) {
|
||||
inv.set(i, blockEntity.getStack(i));
|
||||
}
|
||||
watchingPlayers.forEach(player -> {
|
||||
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
|
||||
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData);
|
||||
if (VisualOverhaulCommon.playersWithMod.contains(player.getUuid())) {
|
||||
player.networkHandler.send(new UpdateItemsPacket(VisualOverhaulCommon.UPDATE_TYPE_POTION_BOTTLES, pos, inv));
|
||||
}
|
||||
});
|
||||
visualoverhaul$invUpdate = false;
|
||||
@@ -57,8 +52,8 @@ public abstract class MixinBrewingStandBlockEntity extends LockableContainerBloc
|
||||
visualoverhaul$playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
@Inject(at = @At("RETURN"), method = "getHeldStacks")
|
||||
public void getStack(CallbackInfoReturnable<DefaultedList<ItemStack>> cir) {
|
||||
visualoverhaul$invUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,60 +3,37 @@ package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.potion.PotionUtil;
|
||||
import net.minecraft.potion.Potions;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge.grassColor;
|
||||
import static eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge.foliageColor;
|
||||
import static eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge.waterColor;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.*;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.potionColor;
|
||||
|
||||
@Mixin(ItemColors.class)
|
||||
public abstract class MixinItemColors {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Inject(method = "create", at = @At("RETURN"))
|
||||
private static void create(BlockColors blockMap, CallbackInfoReturnable<ItemColors> info) {
|
||||
if (VOConfig.coloredItems) {
|
||||
ItemColors itemColors = info.getReturnValue();
|
||||
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET);
|
||||
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.AXOLOTL_BUCKET);
|
||||
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.COD_BUCKET);
|
||||
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.PUFFERFISH_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) -> grassColor, Items.GRASS_BLOCK);
|
||||
itemColors.register((stack, tintIndex) -> grassColor, Items.SHORT_GRASS);
|
||||
itemColors.register((stack, tintIndex) -> grassColor, Items.TALL_GRASS);
|
||||
itemColors.register((stack, tintIndex) -> grassColor, Items.FERN);
|
||||
itemColors.register((stack, tintIndex) -> grassColor, Items.LARGE_FERN);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.ACACIA_LEAVES);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.DARK_OAK_LEAVES);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.JUNGLE_LEAVES);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.VINE);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.SUGAR_CANE);
|
||||
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET, Items.AXOLOTL_BUCKET, Items.COD_BUCKET, Items.PUFFERFISH_BUCKET, Items.TROPICAL_FISH_BUCKET, Items.SALMON_BUCKET);
|
||||
itemColors.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK, Items.SHORT_GRASS, Items.TALL_GRASS, Items.FERN, Items.LARGE_FERN);
|
||||
itemColors.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES, Items.JUNGLE_LEAVES, Items.DARK_OAK_LEAVES, Items.ACACIA_LEAVES, Items.VINE, Items.SUGAR_CANE);
|
||||
if (VOConfig.coloredLilypad) itemColors.register((stack, tintIndex) -> foliageColor, Items.LILY_PAD);
|
||||
itemColors.register((stack, tintIndex) -> {
|
||||
if ((PotionUtil.getPotion(stack) == Potions.WATER || PotionUtil.getPotion(stack) == Potions.MUNDANE || PotionUtil.getPotion(stack) == Potions.THICK || PotionUtil.getPotion(stack) == Potions.AWKWARD) && tintIndex == 0) {
|
||||
return waterColor;
|
||||
var contents = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
|
||||
if (contents == null || contents.potion().isEmpty()) return tintIndex > 0 ? -1 : potionColor;
|
||||
var potion = contents.potion().get();
|
||||
if ((potion == Potions.WATER || potion == Potions.MUNDANE || potion == Potions.THICK || potion == Potions.AWKWARD) && tintIndex == 0) {
|
||||
return potionColor;
|
||||
}
|
||||
return tintIndex > 0 ? -1 : PotionUtil.getColor(stack);
|
||||
}, Items.POTION);
|
||||
itemColors.register((stack, tintIndex) -> {
|
||||
if ((PotionUtil.getPotion(stack) == Potions.WATER || PotionUtil.getPotion(stack) == Potions.MUNDANE || PotionUtil.getPotion(stack) == Potions.THICK || PotionUtil.getPotion(stack) == Potions.AWKWARD) && tintIndex == 0) {
|
||||
return waterColor;
|
||||
}
|
||||
return tintIndex > 0 ? -1 : PotionUtil.getColor(stack);
|
||||
}, Items.SPLASH_POTION);
|
||||
itemColors.register((stack, tintIndex) -> {
|
||||
if ((PotionUtil.getPotion(stack) == Potions.WATER || PotionUtil.getPotion(stack) == Potions.MUNDANE || PotionUtil.getPotion(stack) == Potions.THICK || PotionUtil.getPotion(stack) == Potions.AWKWARD) && tintIndex == 0) {
|
||||
return waterColor;
|
||||
}
|
||||
return tintIndex > 0 ? -1 : PotionUtil.getColor(stack);
|
||||
}, Items.LINGERING_POTION);
|
||||
return tintIndex > 0 ? -1 : contents.getColor();
|
||||
}, Items.POTION, Items.SPLASH_POTION, Items.LINGERING_POTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
|
||||
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
|
||||
import eu.midnightdust.visualoverhaul.util.JukeboxPacketUpdate;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.BlockWithEntity;
|
||||
@@ -12,9 +11,9 @@ import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.JukeboxBlockEntity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -43,17 +42,13 @@ public abstract class MixinJukeboxBlock extends BlockWithEntity {
|
||||
@Unique
|
||||
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 = ((ServerChunkManager)world.getChunkManager()).threadedAnvilChunkStorage.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
|
||||
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
|
||||
passedData.writeBlockPos(pos);
|
||||
passedData.writeItemStack(blockEntity.getStack());
|
||||
|
||||
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).chunkLoadingManager.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();
|
||||
watchingPlayers.forEach(player -> {
|
||||
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
|
||||
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_RECORD, passedData);
|
||||
if (VisualOverhaulCommon.playersWithMod.contains(player.getUuid())) {
|
||||
player.networkHandler.send(new UpdateItemsPacket(VisualOverhaulCommon.UPDATE_TYPE_RECORD, pos, DefaultedList.ofSize(1, blockEntity.getStack())));
|
||||
}
|
||||
});
|
||||
JukeboxPacketUpdate.invUpdate = false;
|
||||
//JukeboxPacketUpdate.invUpdate = false;
|
||||
}
|
||||
JukeboxPacketUpdate.playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.MOD_ID;
|
||||
|
||||
@Mixin(ResourcePackManager.class)
|
||||
public abstract class MixinResourcePackManager {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[1,)"
|
||||
loaderVersion = "[2,)"
|
||||
#issueTrackerURL = ""
|
||||
license = "MIT License"
|
||||
|
||||
@@ -7,11 +7,12 @@ license = "MIT License"
|
||||
modId = "visualoverhaul"
|
||||
version = "${version}"
|
||||
displayName = "VisualOverhaul"
|
||||
logoFile = "icon.png"
|
||||
authors = "Motschen, TeamMidnightDust"
|
||||
description = '''
|
||||
Adds better visuals for certain Minecraft Vanilla Blocks.
|
||||
'''
|
||||
logoFile = "icon.png"
|
||||
|
||||
[[mixins]]
|
||||
config = "visualoverhaul.mixins.json"
|
||||
[[mixins]]
|
||||
@@ -19,28 +20,21 @@ config = "visualoverhaul-neoforge.mixins.json"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "neoforge"
|
||||
required = true
|
||||
versionRange = "[1,)"
|
||||
mandatory = true
|
||||
versionRange = "[21.0,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "minecraft"
|
||||
required = true
|
||||
versionRange = "[1.19.2,)"
|
||||
mandatory = true
|
||||
versionRange = "[1.21,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "midnightlib"
|
||||
required = true
|
||||
versionRange = "[1.0.0,)"
|
||||
ordering = "BEFORE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "architectury"
|
||||
required = true
|
||||
versionRange = "[6.0.0,)"
|
||||
ordering = "BEFORE"
|
||||
side = "BOTH"
|
||||
mandatory = true
|
||||
versionRange = "[1.0,)"
|
||||
ordering = "AFTER"
|
||||
side = "BOTH"
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "VisualOverhaul",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "eu.midnightdust.visualoverhaul.neoforge.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"MixinJukeboxBlock",
|
||||
"MixinAbstractFurnaceBlockEntity",
|
||||
|
||||
Reference in New Issue
Block a user