mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 05:55:09 +01:00
Port to 1.21
- Rewrite packet system to use vanilla payloads - Water bottles will now appear slightly transparent - One of the hardest 1.21 ports yet
This commit is contained in:
@@ -1,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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user