mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 14:05:08 +01:00
First release! - VisualOverhaul 1.0.0
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package eu.midnightdust.visualoverhaul.mixin;
|
||||
|
||||
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.fabricmc.fabric.api.server.PlayerStream;
|
||||
import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl;
|
||||
import net.minecraft.block.entity.*;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Tickable;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Mixin(JukeboxBlockEntity.class)
|
||||
public abstract class MixinJukeboxBlockEntity extends BlockEntity implements Tickable {
|
||||
|
||||
|
||||
@Shadow private ItemStack record;
|
||||
Boolean sendData = true;
|
||||
|
||||
private MixinJukeboxBlockEntity(BlockEntityType<?> blockEntityType) {
|
||||
super(blockEntityType);
|
||||
|
||||
}
|
||||
|
||||
@Unique
|
||||
public void tick() {
|
||||
if (!this.world.isClient) {
|
||||
Stream<PlayerEntity> watchingPlayers = PlayerStream.watching(world, getPos());
|
||||
PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
|
||||
passedData.writeBlockPos(pos);
|
||||
passedData.writeItemStack(record);
|
||||
|
||||
watchingPlayers.forEach(player -> ServerSidePacketRegistryImpl.INSTANCE.sendToPlayer(player, VisualOverhaul.UPDATE_RECORD, passedData));
|
||||
sendData = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "getRecord", cancellable = true)
|
||||
public void getRecord(CallbackInfoReturnable cir) {
|
||||
this.sendData = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user