Skip to content

Commit a45eb59

Browse files
authored
Merge pull request #621 from pylonmc/idra/facades
Pipe and cargo facades
2 parents b91060a + 3a62335 commit a45eb59

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.github.pylonmc.rebar.block.base
2+
3+
import io.github.pylonmc.rebar.event.api.annotation.MultiHandler
4+
import io.github.pylonmc.rebar.item.RebarItem
5+
import org.bukkit.Material
6+
import org.bukkit.block.Block
7+
import org.bukkit.event.Event
8+
import org.bukkit.event.EventPriority
9+
import org.bukkit.event.player.PlayerInteractEvent
10+
import org.bukkit.inventory.EquipmentSlot
11+
12+
/**
13+
* Represents a block that takes the form of another block when right clicked, such as fluid
14+
* pipes and cargo ducts.
15+
*/
16+
interface RebarFacadeBlock : RebarInteractBlock {
17+
18+
/**
19+
* Implemented automatically by any class that extends PylonBlock
20+
*/
21+
val block: Block
22+
23+
val facadeDefaultBlockType: Material
24+
25+
@MultiHandler(priorities = [EventPriority.MONITOR])
26+
override fun onInteract(event: PlayerInteractEvent, priority: EventPriority) {
27+
if (!event.action.isRightClick || event.player.isSneaking || event.hand != EquipmentSlot.HAND) {
28+
return
29+
}
30+
31+
val item = event.player.inventory.getItem(EquipmentSlot.HAND)
32+
if (RebarItem.isRebarItem(item)) {
33+
return
34+
}
35+
36+
if (block.type != Material.STRUCTURE_VOID) {
37+
block.type = Material.STRUCTURE_VOID
38+
event.setUseItemInHand(Event.Result.DENY)
39+
event.setUseInteractedBlock(Event.Result.DENY)
40+
return
41+
}
42+
43+
if (item.type.isBlock && !item.type.isAir) {
44+
block.type = item.type
45+
event.setUseItemInHand(Event.Result.DENY)
46+
event.setUseInteractedBlock(Event.Result.DENY)
47+
}
48+
}
49+
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/content/cargo/CargoDuct.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package io.github.pylonmc.rebar.content.cargo
22

33
import io.github.pylonmc.rebar.block.BlockStorage
44
import io.github.pylonmc.rebar.block.RebarBlock
5-
import io.github.pylonmc.rebar.block.base.RebarBreakHandler
6-
import io.github.pylonmc.rebar.block.base.RebarCargoBlock
7-
import io.github.pylonmc.rebar.block.base.RebarEntityHolderBlock
5+
import io.github.pylonmc.rebar.block.base.*
86
import io.github.pylonmc.rebar.block.base.RebarEntityHolderBlock.Companion.holders
9-
import io.github.pylonmc.rebar.block.base.RebarEntityGroupCulledBlock
107
import io.github.pylonmc.rebar.block.context.BlockBreakContext
118
import io.github.pylonmc.rebar.block.context.BlockCreateContext
129
import io.github.pylonmc.rebar.datatypes.RebarSerializers
@@ -33,7 +30,8 @@ import org.bukkit.event.Listener
3330
import org.bukkit.event.entity.EntityRemoveEvent
3431
import org.bukkit.persistence.PersistentDataContainer
3532

36-
class CargoDuct : RebarBlock, RebarBreakHandler, RebarEntityHolderBlock, RebarEntityGroupCulledBlock {
33+
class CargoDuct : RebarBlock, RebarBreakHandler, RebarEntityHolderBlock, RebarEntityGroupCulledBlock, RebarFacadeBlock {
34+
override val facadeDefaultBlockType = Material.STRUCTURE_VOID
3735

3836
var connectedFaces = mutableListOf<BlockFace>()
3937
val faceGroups = mutableMapOf<BlockFace, RebarEntityGroupCulledBlock.EntityCullingGroup>()

rebar/src/main/kotlin/io/github/pylonmc/rebar/content/fluid/FluidIntersectionMarker.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package io.github.pylonmc.rebar.content.fluid
33
import io.github.pylonmc.rebar.block.RebarBlock
44
import io.github.pylonmc.rebar.block.base.RebarBreakHandler
55
import io.github.pylonmc.rebar.block.base.RebarEntityHolderBlock
6+
import io.github.pylonmc.rebar.block.base.RebarFacadeBlock
67
import io.github.pylonmc.rebar.block.context.BlockBreakContext
78
import io.github.pylonmc.rebar.block.context.BlockBreakContext.PlayerBreak
89
import io.github.pylonmc.rebar.block.context.BlockCreateContext
9-
import io.github.pylonmc.rebar.datatypes.RebarSerializers
1010
import io.github.pylonmc.rebar.entity.EntityStorage
1111
import io.github.pylonmc.rebar.i18n.RebarArgument
1212
import io.github.pylonmc.rebar.item.RebarItem
1313
import io.github.pylonmc.rebar.util.rebarKey
1414
import io.github.pylonmc.rebar.waila.WailaDisplay
15+
import org.bukkit.Material
1516
import org.bukkit.block.Block
16-
import org.bukkit.entity.LivingEntity
1717
import org.bukkit.entity.Player
1818
import org.bukkit.inventory.ItemStack
1919
import org.bukkit.persistence.PersistentDataContainer
@@ -23,7 +23,8 @@ import org.bukkit.persistence.PersistentDataContainer
2323
* on pipe corners/junctions.
2424
* TODO: [io.github.pylonmc.rebar.block.base.RebarEntityGroupCulledBlock]
2525
*/
26-
class FluidIntersectionMarker : RebarBlock, RebarEntityHolderBlock, RebarBreakHandler {
26+
class FluidIntersectionMarker : RebarBlock, RebarEntityHolderBlock, RebarBreakHandler, RebarFacadeBlock {
27+
override val facadeDefaultBlockType = Material.STRUCTURE_VOID
2728
override var disableBlockTextureEntity = true
2829

2930
@Suppress("unused")

rebar/src/main/kotlin/io/github/pylonmc/rebar/content/fluid/FluidSectionMarker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package io.github.pylonmc.rebar.content.fluid
33
import io.github.pylonmc.rebar.block.RebarBlock
44
import io.github.pylonmc.rebar.block.base.RebarBreakHandler
55
import io.github.pylonmc.rebar.block.base.RebarEntityHolderBlock
6+
import io.github.pylonmc.rebar.block.base.RebarFacadeBlock
67
import io.github.pylonmc.rebar.block.context.BlockBreakContext
78
import io.github.pylonmc.rebar.block.context.BlockBreakContext.PlayerBreak
89
import io.github.pylonmc.rebar.block.context.BlockCreateContext
910
import io.github.pylonmc.rebar.i18n.RebarArgument
1011
import io.github.pylonmc.rebar.util.rebarKey
1112
import io.github.pylonmc.rebar.waila.WailaDisplay
13+
import org.bukkit.Material
1214
import org.bukkit.block.Block
1315
import org.bukkit.entity.Player
1416
import org.bukkit.inventory.ItemStack
@@ -19,7 +21,8 @@ import org.bukkit.persistence.PersistentDataContainer
1921
* blocks from being placed on top of them.
2022
* TODO: [io.github.pylonmc.rebar.block.base.RebarEntityGroupCulledBlock]
2123
*/
22-
class FluidSectionMarker : RebarBlock, RebarBreakHandler, RebarEntityHolderBlock {
24+
class FluidSectionMarker : RebarBlock, RebarBreakHandler, RebarEntityHolderBlock, RebarFacadeBlock {
25+
override val facadeDefaultBlockType = Material.STRUCTURE_VOID
2326
override var disableBlockTextureEntity = true
2427

2528
@Suppress("unused")

0 commit comments

Comments
 (0)