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:
Martin Prokoph
2024-06-18 19:06:41 +02:00
parent f1d4e36ed9
commit cd9db8c8bc
43 changed files with 529 additions and 425 deletions

View File

@@ -1,7 +1,8 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
}
architectury {
@@ -22,10 +23,14 @@ subprojects {
// The following line declares the mojmap mappings, you may use other mappings as well
//mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
mappings loom.layered {
it.mappings("net.fabricmc:yarn:$rootProject.yarn_mappings:v2")
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:$rootProject.yarn_mappings_patch_neoforge_version")
}
}
}
allprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
@@ -45,7 +50,7 @@ allprojects {
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
options.release = 21
}
ext {
releaseChangelog = {

View File

@@ -8,7 +8,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.texture.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.resource.ResourceManager;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
@@ -33,7 +32,7 @@ public class IconicButtons {
iconId = Identifier.tryParse("iconic:textures/gui/icons/" + buttonId.toLowerCase()+".png");
if (buttonId.endsWith(".midnightconfig.title"))
{
iconId = new Identifier("modid", buttonId.replace(".midnightconfig.title", "") + "_icon");
iconId = Identifier.of("modid", buttonId.replace(".midnightconfig.title", "") + "_icon");
NativeImageBackedTexture icon = new ModIconUtil(buttonId.replace(".midnightconfig.title", "")).createModIcon();
if (icon != null) {
client.getTextureManager().registerTexture(iconId, icon);
@@ -84,13 +83,13 @@ public class IconicButtons {
manager.findResources("textures", path -> path.getPath().contains(".properties")).forEach((id, resource) -> {
if (manager.getResource(id).isEmpty()) return;
try (InputStream stream = manager.getResource(id).get().getInputStream()) {
Identifier iconId = new Identifier(id.getNamespace(), id.getPath().replace(".properties", ".png"));
Identifier iconId = Identifier.of(id.getNamespace(), id.getPath().replace(".properties", ".png"));
if (manager.getResource(iconId).isPresent()) return;
Properties properties = new Properties();
properties.load(stream);
while (properties.get("properties") != null) {
Identifier propertiesId = new Identifier(properties.getProperty("properties"));
Identifier propertiesId = Identifier.of(properties.getProperty("properties"));
String textureId = propertiesId.toString().replace(".properties", ".png");
properties.clear();
@@ -103,7 +102,7 @@ public class IconicButtons {
}
if (properties.get("texture") != null) {
Identifier textureId = new Identifier(properties.getProperty("texture"));
Identifier textureId = Identifier.of(properties.getProperty("texture"));
TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
AbstractTexture abstractTexture = textureManager.getOrDefault(iconId, null);
if (abstractTexture == null) {

View File

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

View File

@@ -3,9 +3,13 @@ package eu.midnightdust.visualoverhaul;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.minecraft.block.Block;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.MOD_ID;
public class VisualOverhaulClient {
public static int waterColor = 4159204;
public static int foliageColor = -8934609;
public static int grassColor = -8934609;
public static int potionColor = -13083194;
public static Block JukeBoxTop;

View File

@@ -0,0 +1,28 @@
package eu.midnightdust.visualoverhaul;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.compress.utils.Lists;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class VisualOverhaulCommon {
public static final String MOD_ID = "visualoverhaul";
public static final List<UUID> playersWithMod = Lists.newArrayList();
public static final Map<BlockPos, ItemStack> jukeboxItems = new HashMap<>();
public static final Identifier HELLO_PACKET = id("hello");
public static final Identifier UPDATE_ITEMS_PACKET = id("update_items");
public static final Identifier UPDATE_TYPE_POTION_BOTTLES = id("type_brewingstand");
public static final Identifier UPDATE_TYPE_RECORD = id("type_record");
public static final Identifier UPDATE_TYPE_FURNACE_ITEMS = id("type_furnace");
public static Identifier id(String path) {
return Identifier.of(MOD_ID, path);
}
}

View File

@@ -5,13 +5,12 @@ import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.MOD_ID;
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.id;
public class FurnaceWoodenPlanksModel extends Model {
private static ModelPart bb_main;
public static final EntityModelLayer WOODEN_PLANKS_MODEL_LAYER = new EntityModelLayer(new Identifier(MOD_ID, "wooden_planks"), "main");
public static final EntityModelLayer WOODEN_PLANKS_MODEL_LAYER = new EntityModelLayer(id("wooden_planks"), "main");
public FurnaceWoodenPlanksModel(ModelPart root) {
super(RenderLayer::getEntitySolid);
@@ -35,7 +34,7 @@ public class FurnaceWoodenPlanksModel extends Model {
return modelData;
}
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
bb_main.render(matrices, vertices, light, overlay, red, green, blue, alpha);
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
bb_main.render(matrices, vertices, light, overlay);
}
}

View File

@@ -93,6 +93,6 @@ public class FurnaceBlockEntityRenderer<E extends AbstractFurnaceBlockEntity> im
}
public static Identifier spriteToTexture(Sprite sprite) {
String texture = sprite.getContents().getId().getPath();
return new Identifier(sprite.getAtlasId().getNamespace(), "textures/" + texture + ".png");
return Identifier.of(sprite.getAtlasId().getNamespace(), "textures/" + texture + ".png");
}
}

View File

@@ -15,6 +15,9 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.state.property.Properties;
@@ -29,7 +32,7 @@ import org.joml.Quaternionf;
import java.util.Objects;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.jukeboxItems;
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.jukeboxItems;
@Environment(EnvType.CLIENT)
public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBlockEntity> {
@@ -51,7 +54,7 @@ public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBl
// Else gets the record sound played at the position of the jukebox //
else if (SoundTest.getSound(blockEntity.getPos()) != null) {
// Converts the Sound ID to the item ID of the appropriate disc (minecraft:music_disc.cat -> minecraft:music_disc_cat) //
discItem = new Identifier(String.valueOf(SoundTest.getSound(blockEntity.getPos())).replace(".", "_"));
discItem = Identifier.of(String.valueOf(SoundTest.getSound(blockEntity.getPos())).replace(".", "_"));
// Tries to get the disc item from the registry //
if (Registries.ITEM.getOrEmpty(discItem).isPresent()) {
@@ -70,7 +73,8 @@ public class JukeboxBlockEntityRenderer implements BlockEntityRenderer<JukeboxBl
}
if (!record.isEmpty()) {
record.setCount(2);
//record.setCount(2);
record.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(710)).build());
matrices.push();
matrices.translate(0.5f, 1.03f, 0.5f);

View File

@@ -9,12 +9,13 @@ public class VOConfig extends MidnightConfig {
@Client @Entry(category = blocks) public static boolean brewingstand = true;
@Client @Entry(category = blocks) public static boolean jukebox = true;
@Client @Entry(category = blocks) public static boolean jukebox_fake_block = true;
@Client @Entry(category = blocks) public static boolean jukebox_clientside = true;
@Client @Entry(category = blocks) public static boolean furnace = true;
@Client @Entry(category = blocks) public static boolean smoker_particles = true;
@Client @Entry(category = blocks) public static boolean blast_furnace_particles = true;
@Client @Entry(category = colors) public static boolean coloredItems = true;
@Client @Entry(category = colors) public static boolean coloredLilypad = true;
@Client @Entry(category = gui) public static boolean buttonIcons = true;
@Client @Entry(category = gui) public static boolean buttonIcons = false;
@Client @Entry(category = gui) public static IconPosition buttonIconPosition = IconPosition.LOCATION;
@Client @Entry(category = gui) public static boolean zoomIconOnHover = true;
@Client @Entry(category = gui, name = "Debug") public static boolean debug = false;

View File

@@ -3,12 +3,11 @@ package eu.midnightdust.visualoverhaul.mixin;
import eu.midnightdust.visualoverhaul.util.JukeboxPacketUpdate;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.*;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(JukeboxBlockEntity.class)
public abstract class MixinJukeboxBlockEntity extends BlockEntity {
@@ -17,8 +16,8 @@ public abstract class MixinJukeboxBlockEntity extends BlockEntity {
super(type, pos, state);
}
@Inject(at = @At("RETURN"), method = "getStack")
public void getRecord(CallbackInfoReturnable<ItemStack> cir) {
@Inject(at = @At("TAIL"), method = "onRecordStackChanged")
public void getRecord(CallbackInfo ci) {
JukeboxPacketUpdate.invUpdate = true;
}
}

View File

@@ -0,0 +1,27 @@
package eu.midnightdust.visualoverhaul.packet;
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import java.util.UUID;
public record HelloPacket(UUID uuid) implements CustomPayload {
public static final CustomPayload.Id<HelloPacket> PACKET_ID = new CustomPayload.Id<>(VisualOverhaulCommon.HELLO_PACKET);
public static final PacketCodec<PacketByteBuf, HelloPacket> codec = PacketCodec.of(HelloPacket::write, HelloPacket::read);
public static HelloPacket read(PacketByteBuf buf) {
return new HelloPacket(buf.readUuid());
}
public void write(PacketByteBuf buf) {
buf.writeUuid(uuid);
}
@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}

View File

@@ -0,0 +1,30 @@
package eu.midnightdust.visualoverhaul.packet;
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
public record UpdateItemsPacket(Identifier blockTypeID, BlockPos pos, DefaultedList<ItemStack> inv) implements CustomPayload {
public static final Id<UpdateItemsPacket> PACKET_ID = new Id<>(VisualOverhaulCommon.UPDATE_ITEMS_PACKET);
public static final PacketCodec<RegistryByteBuf, UpdateItemsPacket> codec = PacketCodec.of(UpdateItemsPacket::write, UpdateItemsPacket::read);
public static UpdateItemsPacket read(RegistryByteBuf buf) {
return new UpdateItemsPacket(buf.readIdentifier(), buf.readBlockPos(), (DefaultedList<ItemStack>) ItemStack.OPTIONAL_LIST_PACKET_CODEC.decode(buf));
}
public void write(RegistryByteBuf buf) {
buf.writeIdentifier(blockTypeID);
buf.writeBlockPos(pos);
ItemStack.OPTIONAL_LIST_PACKET_CODEC.encode(buf, this.inv);
}
@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}

View File

@@ -1,6 +1,7 @@
package eu.midnightdust.visualoverhaul.util;
import com.google.common.collect.Maps;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@@ -15,7 +16,7 @@ public class SoundTest {
* {@link eu.midnightdust.visualoverhaul.mixin.MixinSoundSystem}
*/
public static Identifier getSound(BlockPos pos) {
if (soundPos.containsKey(pos)) {
if (VOConfig.jukebox_clientside && soundPos.containsKey(pos)) {
return soundPos.get(pos);
}
return null;

View File

@@ -0,0 +1,12 @@
package eu.midnightdust.visualoverhaul.util;
public class VOColorUtil {
public static int convertRgbToArgb(int rgb) {
int red = 0xFF & (rgb >> 16);
int green = 0xFF & (rgb >> 8);
int blue = 0xFF & (rgb);
int alpha = 200; // Makes water bottles transparent, 255 would be opaque
return (alpha << 24) | (red << 16) | (green << 8) | blue;
}
}

View File

@@ -3,6 +3,8 @@
"visualoverhaul.midnightconfig.brewingstand":"Brewing Stand Enhancements",
"visualoverhaul.midnightconfig.jukebox":"Jukebox Enhancements",
"visualoverhaul.midnightconfig.jukebox_fake_block":"Fake block on jukebox top",
"visualoverhaul.midnightconfig.jukebox_clientside":"Client-side music disc detection",
"visualoverhaul.midnightconfig.jukebox_clientside.tooltip":"Might not be 100% accurate with custom music discs.",
"visualoverhaul.midnightconfig.furnace":"Furnace Enhancements",
"visualoverhaul.midnightconfig.smoker_particles":"Smoker Particles",
"visualoverhaul.midnightconfig.blast_furnace_particles":"Blast Furnace Particles",

View File

@@ -0,0 +1,15 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "minecraft:item/music_disc_creator"
},
"overrides": [
{
"predicate": {
"round": 1
},
"model": "minecraft:item/music_disc_creator_round"
}
]
}

View File

@@ -0,0 +1,15 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "minecraft:item/music_disc_creator_music_box"
},
"overrides": [
{
"predicate": {
"round": 1
},
"model": "minecraft:item/music_disc_creator_music_box_round"
}
]
}

View File

@@ -0,0 +1,6 @@
{
"parent": "visualoverhaul:item/round_disc",
"textures": {
"0": "minecraft:item/music_disc_creator_music_box"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "visualoverhaul:item/round_disc",
"textures": {
"0": "minecraft:item/music_disc_creator"
}
}

View File

@@ -0,0 +1,15 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "minecraft:item/music_disc_precipice"
},
"overrides": [
{
"predicate": {
"round": 1
},
"model": "minecraft:item/music_disc_precipice_round"
}
]
}

View File

@@ -0,0 +1,6 @@
{
"parent": "visualoverhaul:item/round_disc",
"textures": {
"0": "minecraft:item/music_disc_precipice"
}
}

View File

@@ -1,8 +1,8 @@
{
"credit": "made by Motschen",
"textures": {
"0": "item/music_disc_mellohi",
"particle": "#0"
"0": "item/music_disc_relic",
"particle": "item/music_disc_relic"
},
"elements": [
{
@@ -348,7 +348,7 @@
"faces": {
"north": {"uv": [12, 11, 13, 12], "texture": "#0"},
"west": {"uv": [11, 11, 12, 12], "texture": "#0"},
"up": {"uv": [12, 10, 13, 11], "rotation": 180, "texture": "#0"}
"up": {"uv": [1, 5, 2, 6], "rotation": 180, "texture": "#0"}
}
},
{
@@ -422,25 +422,46 @@
"translation": [0, 0, -8]
}
},
"groups": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
"groups": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
{
"name": "group",
"origin": [10, 8, 12],
"color": 0,
"children": [17, 18, 19, 20, 21, 22, 23, 24, 25]
},
{
"name": "group",
"origin": [10, 8, 12],
"color": 0,
"children": [26, 27, 28, 29, 30, 31, 32]
},
{
"name": "group",
"origin": [10, 8, 12],
"color": 0,
"children": [33, 34, 35, 36, 37, 38, 39]
},
{
"name": "group",
"origin": [10, 8, 12],
"color": 0,
"children": [40, 41, 42, 43]
}
]

View File

@@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow"
id "me.shedaniel.unified-publishing"
}
@@ -95,7 +95,7 @@ unifiedPublishing {
curseforge {
token = CURSEFORGE_TOKEN
id = rootProject.curseforge_id
gameVersions.addAll "Java 17", project.minecraft_version
gameVersions.addAll "Java 21", project.minecraft_version
}
}

View File

@@ -8,7 +8,9 @@ import eu.midnightdust.visualoverhaul.block.renderer.BrewingStandBlockEntityRend
import eu.midnightdust.visualoverhaul.block.renderer.FurnaceBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.block.renderer.JukeboxBlockEntityRenderer;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import io.netty.buffer.Unpooled;
import eu.midnightdust.visualoverhaul.packet.HelloPacket;
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
import eu.midnightdust.visualoverhaul.util.VOColorUtil;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@@ -28,30 +30,26 @@ import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.item.ItemStack;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Items;
import net.minecraft.item.MusicDiscItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.*;
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.JukeBoxTop;
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.*;
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.*;
public class VisualOverhaulClientFabric implements ClientModInitializer {
@Override
public void onInitializeClient() {
VisualOverhaulClient.onInitializeClient();
JukeBoxTop = new JukeboxTop();
// Block only registered on client, because it's just used for the renderer //
Registry.register(Registries.BLOCK, new Identifier(MOD_ID,"jukebox_top"), JukeBoxTop);
Registry.register(Registries.BLOCK, id("jukebox_top"), JukeBoxTop);
EntityModelLayerRegistry.registerModelLayer(FurnaceWoodenPlanksModel.WOODEN_PLANKS_MODEL_LAYER, FurnaceWoodenPlanksModel::getTexturedModelData);
@@ -73,119 +71,71 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
//}
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);
});
ClientPlayNetworking.registerGlobalReceiver(UPDATE_POTION_BOTTLES,
(client, handler, 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) {
ClientPlayNetworking.registerGlobalReceiver(UpdateItemsPacket.PACKET_ID,
(payload, context) -> context.client().execute(() -> {
System.out.println(payload.blockTypeID().toString());
if (payload.blockTypeID().equals(UPDATE_TYPE_RECORD)) jukeboxItems.put(payload.pos(), payload.inv().getFirst());
else if (context.client().world != null && context.client().world.getBlockEntity(payload.pos()) != null) {
if (payload.blockTypeID().equals(UPDATE_TYPE_POTION_BOTTLES) && context.client().world.getBlockEntity(payload.pos()) instanceof BrewingStandBlockEntity brewingStand) {
for (int i = 0; i <= 4; i++) {
blockEntity.setStack(i, inv.get(i));
brewingStand.setStack(i, payload.inv().get(i));
}
}
});
});
ClientPlayNetworking.registerGlobalReceiver(UPDATE_RECORD,
(client, handler, attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos();
ItemStack record = attachedData.readItemStack();
client.execute(() -> {
jukeboxItems.put(pos, record);
});
});
ClientPlayNetworking.registerGlobalReceiver(UPDATE_FURNACE_ITEMS,
(client, handler, attachedData, packetSender) -> {
BlockPos pos = attachedData.readBlockPos();
DefaultedList<ItemStack> inv = DefaultedList.ofSize(3, ItemStack.EMPTY);
for (int i = 0; i <= 2; i++) {
inv.set(i, attachedData.readItemStack());
}
client.execute(() -> {
if (client.world != null && client.world.getBlockEntity(pos) != null && client.world.getBlockEntity(pos) instanceof AbstractFurnaceBlockEntity blockEntity) {
} else if (payload.blockTypeID().equals(UPDATE_TYPE_FURNACE_ITEMS) && context.client().world.getBlockEntity(payload.pos()) instanceof AbstractFurnaceBlockEntity furnace) {
for (int i = 0; i <= 2; i++) {
blockEntity.setStack(i, inv.get(i));
furnace.setStack(i, payload.inv().get(i));
}
}
});
});
}
}));
// Register builtin resourcepacks
FabricLoader.getInstance().getModContainer("visualoverhaul").ifPresent(modContainer -> {
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"nobrewingbottles"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"fancyfurnace"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"coloredwaterbucket"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(MOD_ID,"rounddiscs"), modContainer, ResourcePackActivationType.ALWAYS_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(id("nobrewingbottles"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(id("fancyfurnace"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(id("coloredwaterbucket"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
ResourceManagerHelper.registerBuiltinResourcePack(id("rounddiscs"), modContainer, ResourcePackActivationType.ALWAYS_ENABLED);
});
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
if (client.player != null) {
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeUuid(client.player.getUuid());
sender.sendPacket(HELLO_PACKET, passedData);
sender.sendPacket(new HelloPacket(client.player.getUuid()));
}
});
// Biome-colored Items
if (VOConfig.coloredItems) {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
int waterColor;
int foliageColor;
int grassColor;
if (client.world != null && client.player != null) {
waterColor = BiomeColors.getWaterColor(client.world, client.player.getBlockPos());
foliageColor = BiomeColors.getFoliageColor(client.world, client.player.getBlockPos());
grassColor = BiomeColors.getGrassColor(client.world, client.player.getBlockPos());
}
else {
potionColor = VOColorUtil.convertRgbToArgb(waterColor);
} else {
waterColor = 4159204;
foliageColor = -8934609;
grassColor = -8934609;
potionColor = -13083194;
}
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.AXOLOTL_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.COD_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.PUFFERFISH_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.TROPICAL_FISH_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.SALMON_BUCKET);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.SHORT_GRASS);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.TALL_GRASS);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.FERN);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.LARGE_FERN);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.ACACIA_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.DARK_OAK_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.JUNGLE_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.VINE);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.SUGAR_CANE);
if (VOConfig.coloredLilypad) ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.LILY_PAD);
ColorProviderRegistry.ITEM.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);
ColorProviderRegistry.ITEM.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);
ColorProviderRegistry.ITEM.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);
});
ColorProviderRegistry.ITEM.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);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK, Items.SHORT_GRASS, Items.TALL_GRASS, Items.FERN, Items.LARGE_FERN);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES, Items.DARK_OAK_LEAVES, Items.JUNGLE_LEAVES, Items.ACACIA_LEAVES, Items.VINE, Items.SUGAR_CANE);
if (VOConfig.coloredLilypad) ColorProviderRegistry.ITEM.register((stack, tintIndex) -> foliageColor, Items.LILY_PAD);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
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 : contents.getColor();
}, Items.POTION, Items.SPLASH_POTION, Items.LINGERING_POTION);
}
if (VOConfig.coloredLilypad) {
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> world != null ? world.getColor(pos, BiomeColors.FOLIAGE_COLOR) : 0, Blocks.LILY_PAD);
@@ -194,7 +144,7 @@ public class VisualOverhaulClientFabric implements ClientModInitializer {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("iconic", "button_icons");
return Identifier.of("iconic", "button_icons");
}
@Override

View File

@@ -1,16 +1,20 @@
package eu.midnightdust.visualoverhaul.fabric;
import eu.midnightdust.visualoverhaul.packet.HelloPacket;
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.*;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.HELLO_PACKET;
import static eu.midnightdust.visualoverhaul.VisualOverhaul.playersWithMod;
import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.playersWithMod;
public class VisualOverhaulFabric implements ModInitializer {
@Override
public void onInitialize() {
ServerPlayNetworking.registerGlobalReceiver(HELLO_PACKET, (server, player, handler, buf, responseSender) -> playersWithMod.add(player.getUuid()));
PayloadTypeRegistry.playC2S().register(HelloPacket.PACKET_ID, HelloPacket.codec);
PayloadTypeRegistry.playS2C().register(UpdateItemsPacket.PACKET_ID, UpdateItemsPacket.codec);
ServerPlayNetworking.registerGlobalReceiver(HelloPacket.PACKET_ID, (payload, context) -> playersWithMod.add(context.player().getUuid()));
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> playersWithMod.remove(handler.getPlayer().getUuid()));
};

View File

@@ -1,6 +1,7 @@
package eu.midnightdust.visualoverhaul.fabric.mixin;
import eu.midnightdust.visualoverhaul.VisualOverhaul;
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
@@ -11,9 +12,11 @@ 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.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -25,6 +28,10 @@ import java.util.stream.Stream;
@Mixin(AbstractFurnaceBlockEntity.class)
public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerBlockEntity {
@Shadow protected DefaultedList<ItemStack> inventory;
@Shadow protected abstract DefaultedList<ItemStack> getHeldStacks();
@Unique
private static boolean visualoverhaul$invUpdate = true;
@Unique
@@ -38,17 +45,16 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
@Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
if (world.getBlockState(pos).hasBlockEntity()) {
if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() != visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos);
passedData.writeItemStack(blockEntity.getStack(0));
passedData.writeItemStack(blockEntity.getStack(1));
passedData.writeItemStack(blockEntity.getStack(2));
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())) {
ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_FURNACE_ITEMS, passedData);
if (VisualOverhaulCommon.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, new UpdateItemsPacket(VisualOverhaulCommon.UPDATE_TYPE_FURNACE_ITEMS, pos, inv));
}
});
visualoverhaul$invUpdate = false;
@@ -57,8 +63,8 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
}
}
@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;
}
}

View File

@@ -1,7 +1,7 @@
package eu.midnightdust.visualoverhaul.fabric.mixin;
import eu.midnightdust.visualoverhaul.VisualOverhaul;
import io.netty.buffer.Unpooled;
import eu.midnightdust.visualoverhaul.VisualOverhaulCommon;
import eu.midnightdust.visualoverhaul.packet.UpdateItemsPacket;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.BlockState;
@@ -9,11 +9,12 @@ 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.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -25,6 +26,7 @@ import java.util.stream.Stream;
@Mixin(BrewingStandBlockEntity.class)
public abstract class MixinBrewingStandBlockEntity extends LockableContainerBlockEntity {
@Shadow private DefaultedList<ItemStack> inventory;
@Unique
private static boolean visualoverhaul$invUpdate = true;
@Unique
@@ -36,28 +38,25 @@ 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)) {
if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() != visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos);
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));
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())) {
ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_POTION_BOTTLES, passedData);
if (VisualOverhaulCommon.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, new UpdateItemsPacket(VisualOverhaulCommon.UPDATE_TYPE_POTION_BOTTLES, 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")
private void vo$onInventoryUpdate(CallbackInfoReturnable<DefaultedList<ItemStack>> cir) {
visualoverhaul$invUpdate = true;
}
}

View File

@@ -1,6 +1,7 @@
package eu.midnightdust.visualoverhaul.fabric.mixin;
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.fabricmc.fabric.api.networking.v1.PlayerLookup;
@@ -13,8 +14,10 @@ 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.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
@@ -41,18 +44,15 @@ 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)) {
if (!world.isClient && (JukeboxPacketUpdate.invUpdate || world.getPlayers().size() != JukeboxPacketUpdate.playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = PlayerLookup.tracking(blockEntity).stream();
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
passedData.writeBlockPos(pos);
passedData.writeItemStack(blockEntity.getStack());
watchingPlayers.forEach(player -> {
if (VisualOverhaul.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, VisualOverhaul.UPDATE_RECORD, passedData);
if (VisualOverhaulCommon.playersWithMod.contains(player.getUuid())) {
ServerPlayNetworking.send(player, new UpdateItemsPacket(VisualOverhaulCommon.UPDATE_TYPE_RECORD, pos, DefaultedList.ofSize(1, blockEntity.getStack())));
}
});
JukeboxPacketUpdate.invUpdate = false;
//JukeboxPacketUpdate.invUpdate = false;
}
JukeboxPacketUpdate.playerUpdate = world.getPlayers().size();
}

View File

@@ -1,23 +1,24 @@
org.gradle.jvmargs=-Xmx2048M
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
minecraft_version=1.21
yarn_mappings=1.21+build.2
enabled_platforms=fabric,neoforge
archives_base_name=visualoverhaul
mod_version=5.1.0
mod_version=5.2.0
maven_group=eu.midnightdust
release_type=release
curseforge_id=432008
modrinth_id=YQnwl5Vv
midnightlib_version=1.5.3
midnightlib_version=1.5.7
phonos_version=0.3.0+1.19.2
fabric_loader_version=0.15.7
fabric_api_version=0.96.3+1.20.4
fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21
neoforge_version=20.4.170
neoforge_version=21.0.14-beta
yarn_mappings_patch_neoforge_version = 1.21+build.4
architectury_version=11.0.12
quilt_loader_version=0.19.0-beta.18

View File

@@ -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"
}
}

View File

@@ -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);

View File

@@ -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;
}
}
}

View File

@@ -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));
}
}
}
});
});
}
}

View File

@@ -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()));
}
}

View File

@@ -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());
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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();
}

View File

@@ -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 {

View File

@@ -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"

View File

@@ -1,6 +0,0 @@
{
"pack": {
"description": "VisualOverhaul",
"pack_format": 9
}
}

View File

@@ -1,8 +1,7 @@
{
"required": true,
"package": "eu.midnightdust.visualoverhaul.neoforge.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_21",
"mixins": [
"MixinJukeboxBlock",
"MixinAbstractFurnaceBlockEntity",