mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 14:05:08 +01:00
Port to Architectury
This commit is contained in:
91
forge/build.gradle
Normal file
91
forge/build.gradle
Normal file
@@ -0,0 +1,91 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||
}
|
||||
|
||||
architectury {
|
||||
injectInjectables = false
|
||||
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.
|
||||
}
|
||||
}
|
||||
1
forge/gradle.properties
Normal file
1
forge/gradle.properties
Normal file
@@ -0,0 +1 @@
|
||||
loom.platform=forge
|
||||
@@ -0,0 +1,78 @@
|
||||
package eu.midnightdust.visualoverhaul.forge;
|
||||
|
||||
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.config.VOConfig;
|
||||
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.metadata.PackResourceMetadata;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.event.AddPackFindersEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.forgespi.locating.IModFile;
|
||||
import net.minecraftforge.resource.PathPackResources;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
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 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
|
||||
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 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, factory) -> {
|
||||
IModFile file = ModList.get().getModFileById(id.getNamespace()).getFile();
|
||||
try (PathPackResources pack = new PathPackResources(id.toString(), file.findResource("resourcepacks/" +id.getPath()))) {
|
||||
ResourcePackProfile packProfile = new ResourcePackProfile(id.toString(), alwaysEnabled, () -> pack, Text.of(id.getNamespace()+"/"+id.getPath()), pack.parseMetadata(PackResourceMetadata.READER).getDescription().copy().append(" §7(built-in)"), ResourcePackCompatibility.COMPATIBLE, ResourcePackProfile.InsertionPosition.TOP, false, ResourcePackSource.PACK_SOURCE_BUILTIN, false);
|
||||
profileAdder.accept(packProfile);
|
||||
if (defaultEnabled && !alwaysEnabled) VisualOverhaulClientForge.defaultEnabledPacks.add(packProfile);
|
||||
} catch (IOException | NullPointerException e) {e.printStackTrace();}
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package eu.midnightdust.visualoverhaul.forge;
|
||||
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
|
||||
import eu.midnightdust.visualoverhaul.block.JukeboxTop;
|
||||
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.block.entity.JukeboxBlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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.resource.ResourcePackProfile;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.client.ConfigScreenHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.IExtensionPoint;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.network.NetworkConstants;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
|
||||
|
||||
//@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(ForgeRegistries.BLOCKS, 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(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
BLOCKS.register("jukebox_top", () -> {
|
||||
VisualOverhaulClient.JukeBoxTop = new JukeboxTop();
|
||||
return VisualOverhaulClient.JukeBoxTop;
|
||||
});
|
||||
|
||||
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (remote, server) -> true));
|
||||
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
|
||||
new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> MidnightConfig.getScreen(parent, MOD_ID)));
|
||||
MinecraftForge.EVENT_BUS.register(new VisualOverhaulClientEvents());
|
||||
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")) {
|
||||
ModelPredicateProviderRegistry.register(item, new Identifier("round"), (stack, world, entity, seed) -> stack.getCount() == 2 ? 1.0F : 0.0F);
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
});
|
||||
});
|
||||
NetworkManager.registerReceiver(NetworkManager.Side.S2C, UPDATE_RECORD,
|
||||
(attachedData, packetSender) -> {
|
||||
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) {
|
||||
blockEntity.setRecord(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) {
|
||||
blockEntity.setStack(0, inv.get(0));
|
||||
blockEntity.setStack(1, inv.get(1));
|
||||
blockEntity.setStack(2, inv.get(2));
|
||||
}
|
||||
});
|
||||
});
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package eu.midnightdust.visualoverhaul.forge.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.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 {
|
||||
|
||||
private static boolean invUpdate = true;
|
||||
private static int 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 && (invUpdate || world.getPlayers().size() == 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 -> NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData));
|
||||
invUpdate = false;
|
||||
}
|
||||
playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
invUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package eu.midnightdust.visualoverhaul.forge.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,57 @@
|
||||
package eu.midnightdust.visualoverhaul.forge.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.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 {
|
||||
|
||||
private static boolean invUpdate = true;
|
||||
private static int 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 && (invUpdate || world.getPlayers().size() == 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 -> NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData));
|
||||
invUpdate = false;
|
||||
}
|
||||
playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getStack")
|
||||
public void getStack(int slot, CallbackInfoReturnable<ItemStack> cir) {
|
||||
invUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package eu.midnightdust.visualoverhaul.forge.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.forge.VisualOverhaulClientForge.grassColor;
|
||||
import static eu.midnightdust.visualoverhaul.forge.VisualOverhaulClientForge.foliageColor;
|
||||
import static eu.midnightdust.visualoverhaul.forge.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.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,57 @@
|
||||
package eu.midnightdust.visualoverhaul.forge.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 : checkType(type, BlockEntityType.JUKEBOX, MixinJukeboxBlock::tick);
|
||||
}
|
||||
@Unique
|
||||
private static void 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.getRecord());
|
||||
|
||||
watchingPlayers.forEach(player -> NetworkManager.sendToPlayer(player, VisualOverhaul.UPDATE_RECORD, passedData));
|
||||
JukeboxPacketUpdate.invUpdate = false;
|
||||
}
|
||||
JukeboxPacketUpdate.playerUpdate = world.getPlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package eu.midnightdust.visualoverhaul.forge.mixin;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||
import eu.midnightdust.visualoverhaul.forge.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 = "Lnet/minecraft/resource/ResourcePackManager;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);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
forge/src/main/resources/META-INF/mods.toml
Normal file
42
forge/src/main/resources/META-INF/mods.toml
Normal file
@@ -0,0 +1,42 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[43,)"
|
||||
#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"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "forge"
|
||||
mandatory = true
|
||||
versionRange = "[43,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.19.2,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "midnightlib"
|
||||
mandatory = true
|
||||
versionRange = "[1.0.0,)"
|
||||
ordering = "BEFORE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
modId = "architectury"
|
||||
mandatory = true
|
||||
versionRange = "[6.0.0,)"
|
||||
ordering = "BEFORE"
|
||||
side = "BOTH"
|
||||
BIN
forge/src/main/resources/icon.png
Normal file
BIN
forge/src/main/resources/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
6
forge/src/main/resources/pack.mcmeta
Normal file
6
forge/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "CullLeaves",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
||||
19
forge/src/main/resources/visualoverhaul-forge.mixins.json
Normal file
19
forge/src/main/resources/visualoverhaul-forge.mixins.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "eu.midnightdust.visualoverhaul.forge.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