Skip to content

Commit

Permalink
Update for 1.20.6 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
auxves authored May 17, 2024
1 parent f486fe3 commit af1af2f
Show file tree
Hide file tree
Showing 30 changed files with 352 additions and 292 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Build with Gradle
shell: bash
run: ./gradlew build

- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: jar
path: build/libs/*
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on: [release, workflow_dispatch]

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Build with Gradle
shell: bash
run: ./gradlew build

- uses: Kir-Antipov/[email protected]
with:
modrinth-id: Xv9MHBa1
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}

github-token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 2 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
java.sourceCompatibility = JavaVersion.VERSION_21
java.targetCompatibility = JavaVersion.VERSION_21

plugins {
id("fabric-loom")
Expand Down Expand Up @@ -30,10 +30,6 @@ tasks.named<Copy>("processResources") {
}
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

tasks.withType<Jar> {
from("LICENSE")
}
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
kotlin.code.style=official
org.gradle.jvmargs=-Xmx1G

version=3.1.0+1.20.2
version=3.1.0+1.20.6

# Versions (https://fabricmc.net/develop)
minecraft=1.20.2
yarn=1.20.2+build.4
loader=0.14.23
minecraft=1.20.6
yarn=1.20.6+build.1
loader=0.15.11

fabric_api=0.90.0+1.20.2
fabric_kotlin=1.10.10+kotlin.1.9.10
fabric_api=0.98.0+1.20.6
fabric_kotlin=1.10.20+kotlin.1.9.24
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pluginManagement {
}

plugins {
id("fabric-loom") version "1.3-SNAPSHOT"
kotlin("jvm") version "1.9.10"
id("fabric-loom") version "1.6-SNAPSHOT"
kotlin("jvm") version "1.9.24"
}
}
16 changes: 15 additions & 1 deletion src/main/java/dev/auxves/vibes/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

import dev.auxves.vibes.server.BridgesKt;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Block.class)
class BlockMixin {
Expand All @@ -15,7 +23,13 @@ class BlockMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")
)
private static boolean onSpawnEntity(World world, Entity entity) {
BridgesKt.onBreakShulkerBox(entity);
BridgesKt.onBreak(entity);
return world.spawnEntity(entity);
}

@Inject(method = "onPlaced", at = @At("HEAD"))
private void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack, CallbackInfo ci) {
BlockEntity entity = world.getBlockEntity(pos);
if (entity != null && itemStack.contains(DataComponentTypes.CONTAINER)) BridgesKt.changePosition(itemStack, entity);
}
}
23 changes: 0 additions & 23 deletions src/main/java/dev/auxves/vibes/mixin/ShulkerBoxBlockMixin.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/kotlin/dev/auxves/vibes/Entrypoint.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.auxves.vibes

import dev.auxves.vibes.item.Vibe
import dev.auxves.vibes.network.initNetwork
import dev.auxves.vibes.server.initServer
import dev.auxves.vibes.util.DataComponents
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents
import net.minecraft.item.ItemGroups
import net.minecraft.registry.Registries
Expand All @@ -14,11 +16,15 @@ object Vibes {

@Suppress("unused")
fun init() {
Registry.register(Registries.DATA_COMPONENT_TYPE, Vibes.id("uuid"), DataComponents.UUID)
Registry.register(Registries.DATA_COMPONENT_TYPE, Vibes.id("disc"), DataComponents.DISC)

Registry.register(Registries.ITEM, Vibe.id, Vibe)

ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register {
it.add(Vibe)
}

initNetwork()
initServer()
}
15 changes: 8 additions & 7 deletions src/main/kotlin/dev/auxves/vibes/client/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package dev.auxves.vibes.client

import dev.auxves.vibes.mixin.SoundManagerAccessor
import dev.auxves.vibes.mixin.SoundSystemAccessor
import dev.auxves.vibes.network.packet.*
import dev.auxves.vibes.network.payloads.*
import dev.auxves.vibes.sound.BlockPositionProvider
import dev.auxves.vibes.sound.EntityPositionProvider
import dev.auxves.vibes.sound.VibeInstance
import kotlinx.coroutines.*
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking
import net.minecraft.client.MinecraftClient
import net.minecraft.sound.SoundEvent
import java.util.*
Expand All @@ -33,19 +34,19 @@ fun init() {
soundSystem.sources
}

register<Play> { data ->
ClientPlayNetworking.registerGlobalReceiver(Play.ID) { data, _ ->
stop(data.uuid)

val entity = getEntity(data.player) ?: return@register
val entity = getEntity(data.player) ?: return@registerGlobalReceiver
val instance = VibeInstance(EntityPositionProvider(entity), SoundEvent.of(data.sound))
instances[data.uuid] = instance

client.soundManager.play(instance)
}

register<Stop> { data -> stop(data.uuid) }
ClientPlayNetworking.registerGlobalReceiver(Stop.ID) { data, _ -> stop(data.uuid) }

register<ChangePositionEntity> { data ->
ClientPlayNetworking.registerGlobalReceiver(ChangePositionEntity.ID) { data, _ ->
instances[data.uuid]?.let {
scope.launch {
delay(100)
Expand All @@ -55,13 +56,13 @@ fun init() {
}
}

register<ChangePositionBlock> { data ->
ClientPlayNetworking.registerGlobalReceiver(ChangePositionBlock.ID) { data, _ ->
instances[data.uuid]?.let {
it.position = BlockPositionProvider(data.blockPos)
}
}

register<ChangeDistance> { data ->
ClientPlayNetworking.registerGlobalReceiver(ChangeDistance.ID) { data, _ ->
instances[data.uuid]?.let {
sources[it]?.run { source -> source.setAttenuation(data.distance) }
}
Expand Down
27 changes: 15 additions & 12 deletions src/main/kotlin/dev/auxves/vibes/item/Vibe.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package dev.auxves.vibes.item

import dev.auxves.vibes.Vibes
import dev.auxves.vibes.network.packet.*
import dev.auxves.vibes.util.disc
import dev.auxves.vibes.util.isPlaying
import dev.auxves.vibes.util.uuid
import net.fabricmc.fabric.api.item.v1.FabricItemSettings
import dev.auxves.vibes.network.sendAll
import dev.auxves.vibes.network.payloads.*
import dev.auxves.vibes.util.*
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking
import net.minecraft.block.Blocks
import net.minecraft.block.JukeboxBlock
import net.minecraft.block.entity.JukeboxBlockEntity
import net.minecraft.client.item.TooltipContext
import net.minecraft.client.item.TooltipType
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.*
import net.minecraft.screen.slot.Slot
Expand All @@ -18,18 +17,22 @@ import net.minecraft.util.ActionResult
import net.minecraft.util.ClickType
import net.minecraft.util.Formatting
import net.minecraft.util.Rarity
import net.minecraft.world.World
import net.minecraft.world.event.GameEvent

private val settings = FabricItemSettings()
private val settings = Item.Settings()
.rarity(Rarity.RARE)
.maxCount(1)

object Vibe : Item(settings) {
val id = Vibes.id("vibe")

override fun appendTooltip(stack: ItemStack, world: World?, tooltip: MutableList<Text>, context: TooltipContext) {
stack.disc?.item?.appendTooltip(stack, world, tooltip, context)
override fun appendTooltip(
stack: ItemStack,
context: TooltipContext,
tooltip: MutableList<Text>,
type: TooltipType
) {
stack.disc?.item?.appendTooltip(stack, context, tooltip, type)

val helpKey = if (stack.disc == null) ".play" else ".stop"
tooltip.add(Text.translatable(translationKey + helpKey).formatted(Formatting.DARK_GRAY))
Expand All @@ -38,7 +41,7 @@ object Vibe : Item(settings) {
override fun onStackClicked(stack: ItemStack, slot: Slot, clickType: ClickType, player: PlayerEntity): Boolean {
if (clickType != ClickType.RIGHT) return false

val packet = when (val item = slot.stack.item) {
val payload = when (val item = slot.stack.item) {
is MusicDiscItem -> {
val disc = stack.disc ?: ItemStack.EMPTY
stack.disc = slot.stack
Expand All @@ -59,7 +62,7 @@ object Vibe : Item(settings) {
else -> return false
}

if (player.world.isClient) send(packet)
if (player.world.isClient) ClientPlayNetworking.send(payload)

return true
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/dev/auxves/vibes/network/Network.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.auxves.vibes.network

import dev.auxves.vibes.network.payloads.*
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
import net.minecraft.network.packet.CustomPayload
import net.minecraft.server.world.ServerWorld
import net.minecraft.world.World

fun initNetwork() {
PayloadTypeRegistry.playC2S().register(Play.ID, Play.PACKET_CODEC)
PayloadTypeRegistry.playS2C().register(Play.ID, Play.PACKET_CODEC)

PayloadTypeRegistry.playC2S().register(Stop.ID, Stop.PACKET_CODEC)
PayloadTypeRegistry.playS2C().register(Stop.ID, Stop.PACKET_CODEC)

PayloadTypeRegistry.playS2C().register(ChangeDistance.ID, ChangeDistance.PACKET_CODEC)
PayloadTypeRegistry.playS2C().register(ChangePositionBlock.ID, ChangePositionBlock.PACKET_CODEC)
PayloadTypeRegistry.playS2C().register(ChangePositionEntity.ID, ChangePositionEntity.PACKET_CODEC)
}

/** Sends a packet to every client */
fun World.sendAll(payload: CustomPayload) {
val world = this as? ServerWorld ?: return
world.players.forEach { ServerPlayNetworking.send(it, payload) }
}
21 changes: 0 additions & 21 deletions src/main/kotlin/dev/auxves/vibes/network/packet/ChangeDistance.kt

This file was deleted.

Loading

0 comments on commit af1af2f

Please sign in to comment.