Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Visit our website: https://pylonmc.github.io/

## Warning
> [!CAUTION]
> REBAR IS CURRENTLY EXPERIMENTAL. ONLY RUN IT ON A TEST SERVER THAT YOU ARE WILLING TO DELETE. THE NEXT PYLON VERSION WILL PROBABLY NOT BE COMPATIBLE WITH THE PREVIOUS ONE. IF YOU INSTALL REBAR SOMEWHERE YOU SHOULDN'T AND END UP LOSING DATA, WE WILL POINT AND LAUGH AT YOU
> REBAR IS CURRENTLY EXPERIMENTAL. ONLY RUN IT ON A TEST SERVER THAT YOU ARE WILLING TO DELETE. THE NEXT REBAR VERSION WILL PROBABLY NOT BE COMPATIBLE WITH THE PREVIOUS ONE. IF YOU INSTALL REBAR SOMEWHERE YOU SHOULDN'T AND END UP LOSING DATA, WE WILL POINT AND LAUGH AT YOU

## Rebar in pictures
<img width="250" alt="using-smeltery" src="https://github.com/user-attachments/assets/b8a7ba3c-9103-46a5-ab43-f31de08dd492" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.netty.channel.ChannelPromise
import io.papermc.paper.datacomponent.DataComponentTypes
import net.minecraft.network.HashedPatchMap
import net.minecraft.network.HashedStack
import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.game.*
import net.minecraft.server.level.ServerPlayer
import net.minecraft.util.HashOps
Expand Down Expand Up @@ -51,83 +52,90 @@ class PlayerPacketHandler(private val player: ServerPlayer, private val handler:

private inner class PacketHandler : ChannelDuplexHandler() {
override fun write(ctx: ChannelHandlerContext, packet: Any, promise: ChannelPromise) {
var packet = packet
when (packet) {
is ClientboundContainerSetContentPacket -> {
packet.items.forEach(::translate)
translate(packet.carriedItem)
}
@Suppress("UNCHECKED_CAST")
super.write(ctx, handleOutgoingPacket(packet as Packet<in ClientGamePacketListener>), promise)
}

is ClientboundContainerSetSlotPacket -> translate(packet.item)
is ClientboundSetCursorItemPacket -> translate(packet.contents)
is ClientboundRecipeBookAddPacket -> {
// This requires a full copy for some reason
packet = ClientboundRecipeBookAddPacket(
packet.entries.map {
ClientboundRecipeBookAddPacket.Entry(
RecipeDisplayEntry(
it.contents.id,
handleRecipeDisplay(it.contents.display),
it.contents.group,
it.contents.category,
it.contents.craftingRequirements
),
it.flags
)
},
packet.replace
)
}
is ClientboundMerchantOffersPacket -> {
for (offer in packet.offers) {
translate(offer.baseCostA.itemStack)
offer.costB.ifPresent {
translate(it.itemStack)
}
translate(offer.result)
}
}
override fun channelRead(ctx: ChannelHandlerContext, packet: Any) {
@Suppress("UNCHECKED_CAST")
super.channelRead(ctx, handleIncomingPacket(packet as Packet<in ServerGamePacketListener>))
}
}

private fun handleOutgoingPacket(packet: Packet<in ClientGamePacketListener>): Packet<in ClientGamePacketListener> =
when (packet) {
is ClientboundBundlePacket -> ClientboundBundlePacket(packet.subPackets().map(::handleOutgoingPacket))

is ClientboundContainerSetContentPacket -> packet.apply {
items.forEach(::translate)
translate(packet.carriedItem)
}

is ClientboundPlaceGhostRecipePacket -> {
packet = ClientboundPlaceGhostRecipePacket(
packet.containerId,
handleRecipeDisplay(packet.recipeDisplay)
is ClientboundContainerSetSlotPacket -> packet.apply { translate(item) }
is ClientboundSetCursorItemPacket -> packet.apply { translate(contents) }
is ClientboundRecipeBookAddPacket -> ClientboundRecipeBookAddPacket(
packet.entries.map {
ClientboundRecipeBookAddPacket.Entry(
RecipeDisplayEntry(
it.contents.id,
handleRecipeDisplay(it.contents.display),
it.contents.group,
it.contents.category,
it.contents.craftingRequirements
),
it.flags
)
},
packet.replace
)

is ClientboundMerchantOffersPacket -> packet.apply {
for (offer in offers) {
translate(offer.baseCostA.itemStack)
offer.costB.ifPresent {
translate(it.itemStack)
}
translate(offer.result)
}
}
super.write(ctx, packet, promise)

is ClientboundPlaceGhostRecipePacket -> ClientboundPlaceGhostRecipePacket(
packet.containerId,
handleRecipeDisplay(packet.recipeDisplay)
)

else -> packet
}

override fun channelRead(ctx: ChannelHandlerContext, packet: Any) {
var packet = packet
packet = when (packet) {
is ServerboundContainerClickPacket -> ServerboundContainerClickPacket(
packet.containerId,
packet.stateId,
packet.slotNum,
packet.buttonNum,
packet.clickType,
packet.changedSlots,
if (packet.changedSlots.size == 1) {
HashedStack.create(
player.containerMenu.getSlot(packet.changedSlots.keys.single()).item,
hashGenerator
)
private fun handleIncomingPacket(packet: Packet<in ServerGamePacketListener>): Packet<in ServerGamePacketListener> =
when (packet) {
is ServerboundContainerClickPacket -> ServerboundContainerClickPacket(
packet.containerId,
packet.stateId,
packet.slotNum,
packet.buttonNum,
packet.clickType,
packet.changedSlots,
if (packet.changedSlots.size == 1) {
val slot = packet.changedSlots.keys.single()
val menu = player.containerMenu
if (menu.isValidSlotIndex(slot)) {
HashedStack.create(menu.getSlot(slot).item, hashGenerator)
} else {
HashedStack.create(player.containerMenu.carried, hashGenerator)
HashedStack.EMPTY
}
)
} else {
HashedStack.create(player.containerMenu.carried, hashGenerator)
}
)

is ServerboundSetCreativeModeSlotPacket -> ServerboundSetCreativeModeSlotPacket(
packet.slotNum,
reset(packet.itemStack)
)
is ServerboundSetCreativeModeSlotPacket -> ServerboundSetCreativeModeSlotPacket(
packet.slotNum,
reset(packet.itemStack)
)

else -> packet
}
super.channelRead(ctx, packet)
else -> packet
}
}

private fun handleRecipeDisplay(display: RecipeDisplay): RecipeDisplay {
return when (display) {
Expand Down Expand Up @@ -242,6 +250,6 @@ class PlayerPacketHandler(private val player: ServerPlayer, private val handler:
}

companion object {
private const val HANDLER_NAME = "pylon_packet_handler"
private const val HANDLER_NAME = "rebar_packet_handler"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataContainer
import java.util.*
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap

@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ class RebarServerPlaceRecipe private constructor(
ServerPlaceRecipe.CraftingMenuAccess::class.java,
Inventory::class.java,
Boolean::class.javaPrimitiveType,
Integer::class.javaPrimitiveType,
Integer::class.javaPrimitiveType,
Int::class.javaPrimitiveType,
Int::class.javaPrimitiveType,
List::class.java,
List::class.java
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object StackedItemContentsWrapper {
}
}

@Suppress("UNCHECKED_CAST")
fun StackedItemContents.getRaw(): StackedContents<ItemOrExact> = rawGetter.invokeExact(this) as StackedContents<ItemOrExact>

/**
Expand Down
6 changes: 2 additions & 4 deletions rebar/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ dependencies {

paperLibraryApi("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.22.0")
paperLibraryApi("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.22.0")
paperLibraryApi("xyz.xenondevs.invui:invui-core:1.49")
// see https://github.com/NichtStudioCode/InvUI/blob/main/inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/version/InventoryAccessRevision.java
paperLibrary("xyz.xenondevs.invui:inventory-access-r26:1.49:remapped-mojang")
paperLibraryApi("xyz.xenondevs.invui:invui-kotlin:1.49")
paperLibraryApi("xyz.xenondevs.invui:invui:2.0.0-beta.1")
paperLibraryApi("xyz.xenondevs.invui:invui-kotlin:2.0.0-beta.1")
implementation("com.github.Tofaa2.EntityLib:spigot:a5184b3bdc")
implementation("com.github.retrooper:packetevents-spigot:2.11.1")
implementation("info.debatty:java-string-similarity:2.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.stream.Stream;

/**
* Loads the necessary libraries for Rebar Core to run - internal.
* Loads the necessary libraries for Rebar to run - internal.
*/
@ApiStatus.Internal
@SuppressWarnings({"UnstableApiUsage", "unused"})
Expand Down
4 changes: 3 additions & 1 deletion rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ import org.bukkit.permissions.Permission
import org.bukkit.permissions.PermissionDefault
import org.bukkit.plugin.java.JavaPlugin
import xyz.xenondevs.invui.InvUI
import java.util.*
import xyz.xenondevs.invui.i18n.Languages
import java.util.Locale
import kotlin.io.path.*

/**
Expand Down Expand Up @@ -90,6 +91,7 @@ object Rebar : JavaPlugin(), RebarAddon {
}

InvUI.getInstance().setPlugin(this)
Languages.getInstance().enableServerSideTranslations(false) // we do our own

val packetEvents = PacketEvents.getAPI()
packetEvents.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin
import org.jetbrains.annotations.ApiStatus

/**
* Bootstraps Rebar Core - internal.
* Bootstraps Rebar - internal.
*/
@ApiStatus.Internal
@Suppress("UnstableApiUsage", "unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import org.bukkit.event.player.PlayerToggleSneakEvent
import org.bukkit.event.world.StructureGrowEvent
import org.bukkit.inventory.BlockInventoryHolder
import org.bukkit.inventory.EquipmentSlot
import java.util.*
import java.util.UUID
import java.util.WeakHashMap


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import io.github.pylonmc.rebar.Rebar
import io.github.pylonmc.rebar.addon.RebarAddon
import io.github.pylonmc.rebar.block.BlockStorage.breakBlock
import io.github.pylonmc.rebar.block.base.RebarBreakHandler
import io.github.pylonmc.rebar.block.context.BlockBreakContext
import io.github.pylonmc.rebar.block.context.BlockCreateContext
import io.github.pylonmc.rebar.resourcepack.block.BlockTextureEngine
import io.github.pylonmc.rebar.config.RebarConfig
import io.github.pylonmc.rebar.datatypes.RebarSerializers
import io.github.pylonmc.rebar.event.*
import io.github.pylonmc.rebar.registry.RebarRegistry
import io.github.pylonmc.rebar.resourcepack.block.BlockTextureEngine
import io.github.pylonmc.rebar.util.isFromAddon
import io.github.pylonmc.rebar.util.position.BlockPosition
import io.github.pylonmc.rebar.util.position.ChunkPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.github.pylonmc.rebar.i18n.RebarArgument
import io.github.pylonmc.rebar.item.RebarItem
import io.github.pylonmc.rebar.item.builder.ItemStackBuilder
import io.github.pylonmc.rebar.util.rebarKey
import io.papermc.paper.datacomponent.DataComponentTypes
import io.github.pylonmc.rebar.waila.WailaDisplay
import io.papermc.paper.datacomponent.DataComponentTypes
import net.kyori.adventure.bossbar.BossBar
import org.bukkit.Color
import org.bukkit.Material
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.github.pylonmc.rebar.block
import com.github.retrooper.packetevents.protocol.world.Location
import com.github.retrooper.packetevents.util.Vector3f
import io.github.pylonmc.rebar.Rebar
import io.github.pylonmc.rebar.block.RebarBlock.Companion.rebarBlockTextureEntityKey
import io.github.pylonmc.rebar.block.RebarBlock.Companion.register
import io.github.pylonmc.rebar.block.base.RebarDirectionalBlock
import io.github.pylonmc.rebar.block.base.RebarEntityHolderBlock
import io.github.pylonmc.rebar.block.base.RebarGuiBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@ import com.github.shynixn.mccoroutine.bukkit.ticks
import io.github.pylonmc.rebar.Rebar
import io.github.pylonmc.rebar.block.BlockStorage
import io.github.pylonmc.rebar.block.RebarBlock
import io.github.pylonmc.rebar.block.base.RebarCargoBlock.Companion.cargoItemsTransferredPerSecond
import io.github.pylonmc.rebar.config.RebarConfig
import io.github.pylonmc.rebar.content.cargo.CargoDuct
import io.github.pylonmc.rebar.datatypes.RebarSerializers
import io.github.pylonmc.rebar.entity.display.ItemDisplayBuilder
import io.github.pylonmc.rebar.entity.display.transform.LineBuilder
import io.github.pylonmc.rebar.event.RebarBlockBreakEvent
import io.github.pylonmc.rebar.event.RebarBlockDeserializeEvent
import io.github.pylonmc.rebar.event.RebarBlockLoadEvent
import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent
import io.github.pylonmc.rebar.event.RebarBlockSerializeEvent
import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent
import io.github.pylonmc.rebar.event.RebarCargoConnectEvent
import io.github.pylonmc.rebar.event.RebarCargoDisconnectEvent
import io.github.pylonmc.rebar.event.*
import io.github.pylonmc.rebar.logistics.CargoRoutes
import io.github.pylonmc.rebar.logistics.LogisticGroup
import io.github.pylonmc.rebar.logistics.LogisticGroupType
import io.github.pylonmc.rebar.logistics.CargoRoutes
import io.github.pylonmc.rebar.util.IMMEDIATE_FACES
import io.github.pylonmc.rebar.util.rebarKey
import kotlinx.coroutines.Job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.jetbrains.annotations.ApiStatus
import java.util.IdentityHashMap
import kotlin.collections.set

/**
* Represents a block that has a specific facing direction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.EquipmentSlot
import org.jetbrains.annotations.MustBeInvokedByOverriders
import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper
import xyz.xenondevs.invui.gui.Gui
import xyz.xenondevs.invui.inventory.VirtualInventory
import xyz.xenondevs.invui.window.Window
import java.util.*
import java.util.IdentityHashMap

/**
* A simple interface that opens a GUI when the block is right clicked
Expand Down Expand Up @@ -55,9 +54,9 @@ interface RebarGuiBlock : RebarBreakHandler, RebarInteractBlock, RebarNoVanillaC
event.setUseInteractedBlock(Event.Result.DENY)
event.setUseItemInHand(Event.Result.DENY)

Window.single()
.setGui(guiBlocks[this]!!)
.setTitle(AdventureComponentWrapper(guiTitle))
Window.builder()
.setUpperGui(guiBlocks[this]!!)
.setTitle(guiTitle)
.setViewer(event.player)
.build()
.open()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package io.github.pylonmc.rebar.block.base
import io.github.pylonmc.rebar.event.RebarBlockBreakEvent
import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent
import io.github.pylonmc.rebar.logistics.LogisticGroup
import io.github.pylonmc.rebar.logistics.slot.LogisticSlot
import io.github.pylonmc.rebar.logistics.LogisticGroupType
import io.github.pylonmc.rebar.logistics.slot.LogisticSlot
import io.github.pylonmc.rebar.logistics.slot.VirtualInventoryLogisticSlot
import org.bukkit.block.Block
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.jetbrains.annotations.ApiStatus
import xyz.xenondevs.invui.inventory.VirtualInventory
import java.util.*
import java.util.IdentityHashMap

/**
* A block which can have items removed or added via a logistics system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface RebarRecipeProcessor<T: RebarRecipe> {

@Suppress("UNCHECKED_CAST")
val currentRecipe: T?
@Suppress("UNCHECKED_CAST")
@ApiStatus.NonExtendable
// cast should always be safe due to type restriction when starting recipe
get() = recipeProcessorData.currentRecipe as T?
Expand Down
Loading