Skip to content

Commit 00c4a20

Browse files
authored
Merge pull request #276 from pylonmc/bug-fix-bonanza
Bug fix bonanza
2 parents d8be87a + ad641c6 commit 00c4a20

9 files changed

Lines changed: 62 additions & 18 deletions

File tree

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/block/BlockListener.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ internal object BlockListener : Listener {
5656
val item = event.itemInHand
5757
val player = event.player
5858

59+
if (!item.type.isBlock) {
60+
return
61+
}
62+
5963
val pylonItem = PylonItem.fromStack(item) ?: return
6064
if (!event.player.canUse(pylonItem, true)) {
6165
event.isCancelled = true
@@ -67,15 +71,11 @@ internal object BlockListener : Listener {
6771
if (pylonItem.schema.pylonBlockKey == null
6872
|| BlockStorage.isPylonBlock(event.block)
6973
) {
70-
event.isCancelled = true;
74+
event.isCancelled = true
7175
return
7276
}
7377
}
7478

75-
val relative = event.blockPlaced.position - event.blockAgainst.position
76-
val blockFace = BlockFace.entries.find { it.modX == relative.x && it.modY == relative.y && it.modZ == relative.z }
77-
?: BlockFace.SELF
78-
7979
val pylonBlock = pylonItem.place(BlockCreateContext.PlayerPlace(player, item, event))
8080

8181
if (pylonBlock == null) {
@@ -139,22 +139,22 @@ internal object BlockListener : Listener {
139139

140140
@EventHandler(ignoreCancelled = true)
141141
private fun disallowForming(event: BlockFormEvent) {
142-
if (BlockStorage.isPylonBlock(event.block.position)) {
142+
if (BlockStorage.isPylonBlock(event.block)) {
143143
event.isCancelled = true
144144
}
145145
}
146146

147147
@EventHandler(ignoreCancelled = true)
148148
private fun disallowFromTo(event: BlockFromToEvent) {
149-
if (BlockStorage.isPylonBlock(event.block.position)) {
149+
if (BlockStorage.isPylonBlock(event.toBlock)) {
150150
event.isCancelled = true
151151
}
152152
}
153153

154154
@EventHandler(ignoreCancelled = true)
155155
private fun disallowMovementByPistons(event: BlockPistonExtendEvent) {
156156
for (block in event.blocks) {
157-
if (BlockStorage.isPylonBlock(block.position)) {
157+
if (BlockStorage.isPylonBlock(block)) {
158158
event.isCancelled = true
159159
return
160160
}
@@ -164,7 +164,7 @@ internal object BlockListener : Listener {
164164
@EventHandler(ignoreCancelled = true)
165165
private fun disallowMovementByPistons(event: BlockPistonRetractEvent) {
166166
for (block in event.blocks) {
167-
if (BlockStorage.isPylonBlock(block.position)) {
167+
if (BlockStorage.isPylonBlock(block)) {
168168
event.isCancelled = true
169169
return
170170
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/fluid/FluidPipeConnector.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.pylonmc.pylon.core.block.base.PylonEntityHolderBlock
55
import io.github.pylonmc.pylon.core.block.context.BlockBreakContext
66
import io.github.pylonmc.pylon.core.block.context.BlockBreakContext.PlayerBreak
77
import io.github.pylonmc.pylon.core.block.context.BlockCreateContext
8+
import io.github.pylonmc.pylon.core.block.context.BlockItemContext
89
import io.github.pylonmc.pylon.core.block.waila.WailaConfig
910
import io.github.pylonmc.pylon.core.entity.EntityStorage
1011
import io.github.pylonmc.pylon.core.fluid.FluidPointType
@@ -55,6 +56,14 @@ class FluidPipeConnector : PylonBlock, PylonEntityHolderBlock {
5556
return EntityStorage.getAs<FluidPipeDisplay?>(uuid)!!.pipe
5657
}
5758

59+
override fun getItem(context: BlockItemContext): ItemStack? {
60+
// Breaking is handled by other fluid pipe logic
61+
if (context is BlockItemContext.PickBlock) {
62+
return pipe.stack
63+
}
64+
return null
65+
}
66+
5867
companion object {
5968
val KEY = pylonKey("fluid_pipe_connector")
6069
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/fluid/FluidPipeMarker.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.github.pylonmc.pylon.core.block.context.BlockBreakContext
66
import io.github.pylonmc.pylon.core.block.context.BlockBreakContext.PlayerBreak
77
import io.github.pylonmc.pylon.core.block.context.BlockBreakContext.PluginBreak
88
import io.github.pylonmc.pylon.core.block.context.BlockCreateContext
9+
import io.github.pylonmc.pylon.core.block.context.BlockItemContext
910
import io.github.pylonmc.pylon.core.block.waila.WailaConfig
1011
import io.github.pylonmc.pylon.core.datatypes.PylonSerializers
1112
import io.github.pylonmc.pylon.core.entity.EntityStorage
@@ -64,6 +65,14 @@ class FluidPipeMarker : PylonBlock, PylonBreakHandler {
6465
override fun getWaila(player: Player): WailaConfig?
6566
= WailaConfig(defaultTranslationKey.arguments(PylonArgument.of("pipe", getPipeDisplay()!!.pipe.stack.effectiveName())))
6667

68+
override fun getItem(context: BlockItemContext): ItemStack? {
69+
// Breaking is handled by other fluid pipe logic
70+
if (context is BlockItemContext.PickBlock) {
71+
return getPipeDisplay()?.pipe?.stack
72+
}
73+
return null
74+
}
75+
6776
companion object {
6877
val KEY = pylonKey("fluid_pipe_marker")
6978

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/fluid/connecting/ConnectingTask.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.pylonmc.pylon.core.block.BlockStorage
55
import io.github.pylonmc.pylon.core.config.PylonConfig
66
import io.github.pylonmc.pylon.core.content.fluid.FluidPipe
77
import io.github.pylonmc.pylon.core.content.fluid.FluidPipeConnector
8+
import io.github.pylonmc.pylon.core.content.fluid.FluidPipeDisplay
89
import io.github.pylonmc.pylon.core.content.fluid.FluidPipeMarker
910
import io.github.pylonmc.pylon.core.content.fluid.FluidPointInteraction
1011
import io.github.pylonmc.pylon.core.entity.EntityStorage
@@ -196,6 +197,15 @@ class ConnectingTask(
196197
val clonedTo = to // kotlin complains if no clone
197198
return when (clonedTo) {
198199
is ConnectingPointPipeMarker -> clonedTo.marker.getPipeDisplay()!!.pipe == pipe
200+
is ConnectingPointInteraction -> {
201+
val connectedPipes = clonedTo.interaction.connectedPipeDisplays
202+
if (connectedPipes.isEmpty()) {
203+
return true // no pipes connected so any pipe type valid
204+
}
205+
// Slight hack - use an arbitrary connected pipe to find out the pipe type
206+
val arbitraryDisplay = clonedTo.interaction.connectedPipeDisplays.iterator().next()
207+
EntityStorage.getAs<FluidPipeDisplay>(arbitraryDisplay)!!.pipe == pipe
208+
}
199209
is ConnectingPointPipeConnector -> clonedTo.connector.pipe == pipe
200210
else -> true
201211
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ItemButton.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.github.pylonmc.pylon.core.guide.button.ResearchButton.Companion.addRes
66
import io.github.pylonmc.pylon.core.guide.pages.item.ItemRecipesPage
77
import io.github.pylonmc.pylon.core.guide.pages.item.ItemUsagesPage
88
import io.github.pylonmc.pylon.core.guide.pages.research.ResearchItemsPage
9+
import io.github.pylonmc.pylon.core.i18n.PylonArgument
910
import io.github.pylonmc.pylon.core.item.PylonItem
1011
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
1112
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canCraft
@@ -84,10 +85,17 @@ class ItemButton @JvmOverloads constructor(
8485
if (!player.canCraft(item)) {
8586
builder.set(DataComponentTypes.ITEM_MODEL, Material.BARRIER.key)
8687
.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false)
87-
.lore(Component.translatable("pylon.pyloncore.guide.button.item.not-researched"))
88+
8889
if (item.research != null) {
90+
builder.lore(Component.translatable(
91+
"pylon.pyloncore.guide.button.item.not-researched-with-name",
92+
PylonArgument.of("research_name", item.research!!.name)
93+
))
8994
addResearchCostLore(builder, player, item.research!!)
95+
} else {
96+
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.not-researched"))
9097
}
98+
9199
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.research-instructions"))
92100
}
93101

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/PylonItemListener.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.github.pylonmc.pylon.core.item.base.*
88
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canUse
99
import io.github.pylonmc.pylon.core.util.findPylonItemInInventory
1010
import io.papermc.paper.event.player.PlayerPickItemEvent
11+
import org.bukkit.Bukkit
1112
import org.bukkit.entity.Player
1213
import org.bukkit.event.Event
1314
import org.bukkit.event.EventHandler

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/recipe/RecipeListener.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import io.github.pylonmc.pylon.core.item.PylonItem
44
import io.github.pylonmc.pylon.core.item.base.VanillaCookingFuel
55
import io.github.pylonmc.pylon.core.item.base.VanillaCookingItem
66
import io.github.pylonmc.pylon.core.item.base.VanillaCraftingItem
7-
import io.github.pylonmc.pylon.core.item.base.VanillaSmithingMaterial
87
import io.github.pylonmc.pylon.core.item.base.VanillaSmithingMineral
98
import io.github.pylonmc.pylon.core.item.base.VanillaSmithingTemplate
109
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canCraft
10+
import io.github.pylonmc.pylon.core.recipe.vanilla.CookingRecipeWrapper
1111
import io.github.pylonmc.pylon.core.recipe.vanilla.VanillaRecipeType
1212
import io.github.pylonmc.pylon.core.util.isPylonAndIsNot
13+
import io.github.pylonmc.pylon.core.util.isPylonSimilar
1314
import org.bukkit.Bukkit
1415
import org.bukkit.Keyed
1516
import org.bukkit.block.Furnace
@@ -51,12 +52,14 @@ internal object PylonRecipeListener : Listener {
5152

5253
@EventHandler(priority = EventPriority.LOWEST)
5354
private fun onCook(e: BlockCookEvent) {
54-
if (PylonItem.fromStack(e.result) == null) return
55+
if (PylonItem.fromStack(e.source) == null) return
5556

57+
var pylonRecipe: CookingRecipeWrapper? = null
5658
for (recipe in RecipeType.vanillaCookingRecipes()) {
57-
if (recipe.recipe.inputChoice.test(e.result)) {
59+
if (recipe.key !in VanillaRecipeType.nonPylonRecipes && recipe.recipe.inputChoice.test(e.source)) {
5860
e.result = recipe.recipe.result.clone()
59-
return
61+
pylonRecipe = recipe
62+
break
6063
}
6164
}
6265
}
@@ -71,14 +74,16 @@ internal object PylonRecipeListener : Listener {
7174
val furnace = (e.block.state as Furnace)
7275
val input = furnace.inventory.smelting
7376
if (input != null && input.isPylonAndIsNot<VanillaCookingItem>()) {
74-
var isProcessingPylonRecipe = false
77+
var pylonRecipe: CookingRecipeWrapper? = null
7578
for (recipe in RecipeType.vanillaCookingRecipes()) {
7679
if (recipe.key !in VanillaRecipeType.nonPylonRecipes && recipe.recipe.inputChoice.test(input)) {
77-
isProcessingPylonRecipe = true
80+
pylonRecipe = recipe
7881
break
7982
}
8083
}
81-
if (!isProcessingPylonRecipe) {
84+
val isFurnaceOutputValidToPutRecipeResultIn = pylonRecipe != null
85+
&& (furnace.inventory.result == null || pylonRecipe.isOutput(furnace.inventory.result!!))
86+
if (pylonRecipe == null || !isFurnaceOutputValidToPutRecipeResultIn) {
8287
e.isCancelled = true
8388
}
8489
}

pylon-core/src/main/resources/lang/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ guide:
135135
error: "<red>Fluid item failed to load"
136136
item:
137137
not-researched: "<red><u>Not researched yet</u>"
138+
not-researched-with-name: "<red><u>Not researched yet <gray>(%research_name%<gray>)"
138139
research-instructions: |-
139140
<arrow:#3a2939> <guideinsn>Shift left click</guideinsn> to research
140141
<arrow:#3a2939> <guideinsn>Shift right click</guideinsn> to see other research unlocks

pylon-core/src/main/resources/lang/enws.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ guide:
126126
name: "%fluid% <gray>(%amount%<gray>)"
127127
error: "<red>Thy fluid item hath faileth to loadeth!!! Repent!!!"
128128
item:
129-
not-researched: "<#ff0000>Not revealed yet"
129+
not-researched: "<red><u>Not revealed yet"
130+
not-researched-with-name: "<red><u>Not revealed yet <gray>(%research_name%<gray>)"
130131
research-instructions: |-
131132
<arrow> <guideinsn>Strike with thy left hand while crouching</guideinsn> to reveal
132133
<arrow> <guideinsn>Strike with thy right hand while crouching</guideinsn> to see other revelations

0 commit comments

Comments
 (0)