Skip to content

Commit

Permalink
Update deps, replace trade sync packet with sync()
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Nov 15, 2019
1 parent d81a91e commit e940505
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
java
kotlin("jvm") version "1.3.40"
idea
id("fabric-loom") version "0.2.5-SNAPSHOT"
id("fabric-loom") version "0.2.6-SNAPSHOT"
`maven-publish`
//id("com.github.johnrengelman.shadow") version "5.1.0"
}
Expand Down Expand Up @@ -86,7 +86,7 @@ dependencies {
fun ExternalModuleDependency.byeFabric() = exclude(group = "net.fabricmc.fabric-api")

minecraft("com.mojang:minecraft:$minecraft")
mappings("net.fabricmc:yarn:" + v("minecraft") + '+' + v("mappings"))
mappings("net.fabricmc:yarn:" + v("minecraft") + '+' + v("mappings") + ":v2")

// Fabric
modImplementation("net.fabricmc:fabric-loader:" + v("fabric-loader"))
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ local-build = false

# Minecraft
minecraft = 1.14.4
mappings = build.12
mappings = build.15

# Fabric
fabric-loader = 0.6.1+build.164
fabric-api = 0.3.2+build.218-1.14
fabric-loader = 0.6.4+build.169
fabric-api = 0.4.1+build.245-1.14
fabric-kotlin = 1.3.40+build.1

# Mod dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import juuxel.adorn.util.Colors
import juuxel.adorn.util.color
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry
import net.fabricmc.fabric.api.server.PlayerStream
import net.minecraft.container.BlockContext
Expand Down Expand Up @@ -75,13 +76,10 @@ class TradingStationController(
slot.markDirty()

if (!world.isClient) {
context.run { world, pos ->
PlayerStream.watching(world, pos).forEach {
ServerSidePacketRegistry.INSTANCE.sendToPlayer(
it,
AdornNetworking.createTradeSyncPacket(pos, getTrade(context))
)
}
(getTradingStation(context) as? BlockEntityClientSerializable)?.sync() ?: run {
val exception = Exception("Stack trace")
exception.fillInStackTrace()
LOGGER.warn("[Adorn] Could not sync empty trading station, report this!", exception)
}
}

Expand Down
13 changes: 0 additions & 13 deletions src/main/kotlin/juuxel/adorn/lib/AdornNetworking.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import net.minecraft.util.math.BlockPos

object AdornNetworking {
val ENTITY_SPAWN = Adorn.id("entity_spawn")
val TRADE_SYNC = Adorn.id("trade_sync")

fun init() {
}
Expand All @@ -39,22 +38,10 @@ object AdornNetworking {
(context.player.world as? ClientWorld)?.addEntity(packet.id, entity)
}
}

ClientSidePacketRegistry.INSTANCE.register(TRADE_SYNC) { context, buf ->
val pos = buf.readBlockPos()
val be = context.player?.world?.getBlockEntity(pos) as? TradingStationBlockEntity ?: return@register
be.trade.fromTag(buf.readCompoundTag()!!)
}
}

fun createEntitySpawnPacket(entity: Entity) =
CustomPayloadS2CPacket(ENTITY_SPAWN, PacketByteBuf(Unpooled.buffer()).apply {
EntitySpawnS2CPacket(entity).write(this)
})

fun createTradeSyncPacket(pos: BlockPos, trade: Trade) =
CustomPayloadS2CPacket(TRADE_SYNC, PacketByteBuf(Unpooled.buffer()).apply {
writeBlockPos(pos)
writeCompoundTag(trade.toTag(CompoundTag()))
})
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

"depends": {
"fabricloader": ">=0.4.6",
"fabric": ">=0.3.0",
"fabric": ">=0.4.0",
"fabric-language-kotlin": "^1.3.30",
"libgui": "^1.3.2",
"jankson": "^1.0.0",
Expand Down

0 comments on commit e940505

Please sign in to comment.