mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 05:55:09 +01:00
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:
109
neoforge/build.gradle
Normal file
109
neoforge/build.gradle
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
neoforge/gradle.properties
Normal file
1
neoforge/gradle.properties
Normal file
@@ -0,0 +1 @@
|
||||
loom.platform=neoforge
|
||||
@@ -0,0 +1,70 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.IconicButtons;
|
||||
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 net.minecraft.block.entity.BlockEntityType;
|
||||
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.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;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
public class VisualOverhaulClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinition(EntityRenderersEvent.RegisterLayerDefinitions event) {
|
||||
event.registerLayerDefinition(FurnaceWoodenPlanksModel.WOODEN_PLANKS_MODEL_LAYER, FurnaceWoodenPlanksModel::getTexturedModelData);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlockEntityRenderers(EntityRenderersEvent.RegisterRenderers event) {
|
||||
event.registerBlockEntityRenderer(BlockEntityType.BREWING_STAND, BrewingStandBlockEntityRenderer::new);
|
||||
event.registerBlockEntityRenderer(BlockEntityType.JUKEBOX, JukeboxBlockEntityRenderer::new);
|
||||
event.registerBlockEntityRenderer(BlockEntityType.FURNACE, FurnaceBlockEntityRenderer::new);
|
||||
event.registerBlockEntityRenderer(BlockEntityType.SMOKER, FurnaceBlockEntityRenderer::new);
|
||||
event.registerBlockEntityRenderer(BlockEntityType.BLAST_FURNACE, FurnaceBlockEntityRenderer::new);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void addReloadListener(RegisterClientReloadListenersEvent event) {
|
||||
event.registerReloadListener(new IconReloadListener());
|
||||
}
|
||||
public static class IconReloadListener implements SynchronousResourceReloader {
|
||||
@Override
|
||||
public void reload(ResourceManager manager) {
|
||||
IconicButtons.reload(manager);
|
||||
}
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (packProfile != null) {
|
||||
profileAdder.accept(packProfile);
|
||||
if (defaultEnabled && !alwaysEnabled) VisualOverhaulClientForge.defaultEnabledPacks.add(packProfile);
|
||||
}
|
||||
} catch (NullPointerException e) {e.fillInStackTrace();}
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
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 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.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.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;
|
||||
|
||||
@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();
|
||||
// Block only registered on client, because it's just used for the renderer //
|
||||
BLOCKS.register(Objects.requireNonNull(ModLoadingContext.get().getActiveContainer().getEventBus()));
|
||||
BLOCKS.register("jukebox_top", () -> {
|
||||
VisualOverhaulClient.JukeBoxTop = new JukeboxTop();
|
||||
return VisualOverhaulClient.JukeBoxTop;
|
||||
});
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import io.netty.buffer.Unpooled;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Mixin(AbstractFurnaceBlockEntity.class)
|
||||
public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity {
|
||||
|
||||
@Unique
|
||||
private static boolean visualoverhaul$invUpdate = true;
|
||||
@Unique
|
||||
private static int visualoverhaul$playerUpdate = -1;
|
||||
|
||||
|
||||
protected MixinAbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
|
||||
super(blockEntityType, blockPos, blockState);
|
||||
}
|
||||
|
||||
@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 && (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));
|
||||
|
||||
watchingPlayers.forEach(player -> {
|
||||
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
|
||||
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData);
|
||||
}
|
||||
});
|
||||
visualoverhaul$invUpdate = false;
|
||||
}
|
||||
visualoverhaul$playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
visualoverhaul$invUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.world.BiomeColors;
|
||||
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;
|
||||
|
||||
@Mixin(BlockColors.class)
|
||||
public abstract class MixinBlockColors {
|
||||
@Inject(method = "create", at = @At("RETURN"))
|
||||
private static void create(CallbackInfoReturnable<BlockColors> info) {
|
||||
if (VOConfig.coloredItems) info.getReturnValue().registerColorProvider((state, world, pos, tintIndex) -> world != null ? world.getColor(pos, BiomeColors.FOLIAGE_COLOR) : 0, Blocks.LILY_PAD);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import io.netty.buffer.Unpooled;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Mixin(BrewingStandBlockEntity.class)
|
||||
public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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));
|
||||
|
||||
watchingPlayers.forEach(player -> {
|
||||
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
|
||||
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData);
|
||||
}
|
||||
});
|
||||
visualoverhaul$invUpdate = false;
|
||||
}
|
||||
visualoverhaul$playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
visualoverhaul$invUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
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.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;
|
||||
|
||||
@Mixin(ItemColors.class)
|
||||
public abstract class MixinItemColors {
|
||||
@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);
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
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;
|
||||
import net.minecraft.block.JukeboxBlock;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Mixin(JukeboxBlock.class)
|
||||
public abstract class MixinJukeboxBlock extends BlockWithEntity {
|
||||
|
||||
protected MixinJukeboxBlock(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
|
||||
return world.isClient() ? null : validateTicker(type, BlockEntityType.JUKEBOX, MixinJukeboxBlock::visualoverhaul$tick);
|
||||
}
|
||||
@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());
|
||||
|
||||
watchingPlayers.forEach(player -> {
|
||||
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
|
||||
NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_RECORD, passedData);
|
||||
}
|
||||
});
|
||||
JukeboxPacketUpdate.invUpdate = false;
|
||||
}
|
||||
JukeboxPacketUpdate.playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package eu.midnightdust.visualoverhaul.neoforge.mixin;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import eu.midnightdust.visualoverhaul.neoforge.VisualOverhaulClientForge;
|
||||
import net.minecraft.resource.ResourcePackManager;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
|
||||
|
||||
@Mixin(ResourcePackManager.class)
|
||||
public abstract class MixinResourcePackManager {
|
||||
@Shadow private List<ResourcePackProfile> enabled;
|
||||
|
||||
@Inject(method = "setEnabledProfiles(Ljava/util/Collection;)V", at = @At("TAIL"))
|
||||
private void setDefaultEnabledPacks(CallbackInfo info) {
|
||||
if (VOConfig.firstLaunch) {
|
||||
List<ResourcePackProfile> enabledPacks = Lists.newArrayList();
|
||||
enabledPacks.addAll(enabled);
|
||||
enabledPacks.addAll(VisualOverhaulClientForge.defaultEnabledPacks);
|
||||
this.enabled = enabledPacks;
|
||||
VOConfig.firstLaunch = false;
|
||||
VOConfig.write(MOD_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package eu.midnightdust.visualoverhaul.util.neoforge;
|
||||
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.neoforgespi.language.IModInfo;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ModIconUtilImpl {
|
||||
public static Path getPath(String modid) {
|
||||
IModInfo mod = ModList.get().getMods().stream().filter(modInfo -> modInfo.getModId().equals(modid)).findFirst().orElseThrow(() -> new RuntimeException("Cannot get ModContainer for Forge mod with id "));
|
||||
return mod.getOwningFile().getFile().findResource(mod.getLogoFile().orElseThrow());
|
||||
}
|
||||
}
|
||||
46
neoforge/src/main/resources/META-INF/mods.toml
Normal file
46
neoforge/src/main/resources/META-INF/mods.toml
Normal file
@@ -0,0 +1,46 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[1,)"
|
||||
#issueTrackerURL = ""
|
||||
license = "MIT License"
|
||||
|
||||
[[mods]]
|
||||
modId = "visualoverhaul"
|
||||
version = "${version}"
|
||||
displayName = "VisualOverhaul"
|
||||
authors = "Motschen, TeamMidnightDust"
|
||||
description = '''
|
||||
Adds better visuals for certain Minecraft Vanilla Blocks.
|
||||
'''
|
||||
logoFile = "icon.png"
|
||||
[[mixins]]
|
||||
config = "visualoverhaul.mixins.json"
|
||||
[[mixins]]
|
||||
config = "visualoverhaul-neoforge.mixins.json"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "neoforge"
|
||||
required = true
|
||||
versionRange = "[1,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "minecraft"
|
||||
required = true
|
||||
versionRange = "[1.19.2,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[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"
|
||||
BIN
neoforge/src/main/resources/icon.png
Normal file
BIN
neoforge/src/main/resources/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
6
neoforge/src/main/resources/pack.mcmeta
Normal file
6
neoforge/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "VisualOverhaul",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "eu.midnightdust.visualoverhaul.neoforge.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"mixins": [
|
||||
"MixinJukeboxBlock",
|
||||
"MixinAbstractFurnaceBlockEntity",
|
||||
"MixinBrewingStandBlockEntity"
|
||||
],
|
||||
"client": [
|
||||
"MixinResourcePackManager",
|
||||
"MixinItemColors",
|
||||
"MixinBlockColors"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user