1
0
Fork 0

Fix portals opening when activated

main
Marissa Staib 6 years ago
parent cc17c0da71
commit 4f304895ad
  1. 4
      TODO
  2. 12
      minecraftportal.iml
  3. 4
      src/main/kotlin/net/deliciousreya/minecraftportal/MinecraftPortalPlugin.kt
  4. 1
      src/main/kotlin/net/deliciousreya/minecraftportal/extensions/Vector.kt
  5. 44
      src/main/kotlin/net/deliciousreya/minecraftportal/model/PortalFrame.kt

@ -1,10 +1,10 @@
* identify and pair portals by type/color * automatically open the door of a portal that is freshly activated
* save portal pairs to disk and reload them on restarting the server * save portal pairs to disk and reload them on restarting the server
* deactivate most recently placed portal and replace with newly placed one when 3+ portals are created
* teleport from one to the other a set time after entering a teleportation chamber and closing the door * teleport from one to the other a set time after entering a teleportation chamber and closing the door
* automatically open the door after effects wear off * automatically open the door after effects wear off
* close the door on the other side when someone shuts the door * close the door on the other side when someone shuts the door
* teleport everyone inside the portal, not just the person who closed the door * teleport everyone inside the portal, not just the person who closed the door
* interrupt teleportation if portal is destroyed mid-teleportation * interrupt teleportation if portal is destroyed mid-teleportation
* cancel teleportation if someone moves out of the teleporter during teleportation (maybe prevent them from starting?)
* save any effects that would be overwritten by teleportation (including to disk!), and put them back when the player opens the door or arrives * save any effects that would be overwritten by teleportation (including to disk!), and put them back when the player opens the door or arrives
* add portal particles and ambient sounds to the teleporter when portals are paired * add portal particles and ambient sounds to the teleporter when portals are paired

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="minecraftportal" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="net.deliciousreya" external.system.module.version="0.1" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -25,7 +25,6 @@ class MinecraftPortalPlugin() : JavaPlugin(), Listener
override fun onEnable() { override fun onEnable() {
super.onEnable() super.onEnable()
logger.info("Loaded the portal plugin!")
server.pluginManager.registerEvents(this, this) server.pluginManager.registerEvents(this, this)
} }
@ -37,12 +36,9 @@ class MinecraftPortalPlugin() : JavaPlugin(), Listener
PortalFrame.State.INACTIVE PortalFrame.State.INACTIVE
) )
if (newPortal != null) { if (newPortal != null) {
logger.info("found portal frame, creating portal")
val replacedPortal = portals.activateAndReplacePortal(newPortal) val replacedPortal = portals.activateAndReplacePortal(newPortal)
newPortal.activate() newPortal.activate()
replacedPortal?.deactivate() replacedPortal?.deactivate()
} else {
logger.info("no portal frame found matching placed block, ignoring")
} }
} }
} }

@ -4,6 +4,7 @@ import org.bukkit.util.Vector
val ZERO = Vector(0, 0, 0) val ZERO = Vector(0, 0, 0)
val UP = Vector(0, 1, 0) val UP = Vector(0, 1, 0)
val MID_BLOCK = Vector(0.5, 0.5, 0.5)
operator fun Vector.plus(v:Vector):Vector { operator fun Vector.plus(v:Vector):Vector {
return this.clone().add(v) return this.clone().add(v)

@ -13,7 +13,9 @@ import org.bukkit.Material.*
import org.bukkit.Particle import org.bukkit.Particle
import org.bukkit.Sound import org.bukkit.Sound
import org.bukkit.block.BlockFace import org.bukkit.block.BlockFace
import org.bukkit.material.Directional import org.bukkit.block.data.Directional
import org.bukkit.block.data.Openable
import org.bukkit.block.data.type.Door
val MINERAL_TYPES: ImmutableMap<Material, Material> = ImmutableMap.Builder<Material, Material>() val MINERAL_TYPES: ImmutableMap<Material, Material> = ImmutableMap.Builder<Material, Material>()
.put(COAL_BLOCK, BLACK_STAINED_GLASS) .put(COAL_BLOCK, BLACK_STAINED_GLASS)
@ -82,7 +84,8 @@ fun checkPortalFrameAt(location:Location, direction: PortalFrame.EntranceDirecti
} }
for (vector in direction.doorOffsets) { for (vector in direction.doorOffsets) {
val block = (location + vector).block val block = (location + vector).block
if (block.type !in state.doorBlocks || (block.blockData is Directional && (block.blockData as Directional).facing != direction.doorDirection)) { val door = block.blockData
if (block.type !in state.doorBlocks || (door is Directional && door.facing != direction.doorDirection)) {
return null return null
} }
} }
@ -110,10 +113,10 @@ data class PortalFrame(val lowerLeftFrontCorner: Location, val direction: Entran
} }
/** The direction along which a portal frame extends. */ /** The direction along which a portal frame extends. */
enum class EntranceDirection(toRight: Vector, toBack: Vector, val doorDirection: BlockFace, val protoEnum: PortalSaveDataProtos.Portal.Direction) { enum class EntranceDirection(toRight: Vector, toBack: Vector, val doorDirection: BlockFace, val protoEnum: PortalSaveDataProtos.Portal.Direction) {
NORTH(Vector(1, 0, 0), Vector(0, 0, 1), BlockFace.NORTH, PortalSaveDataProtos.Portal.Direction.NORTH), NORTH(Vector(1, 0, 0), Vector(0, 0, 1), BlockFace.SOUTH, PortalSaveDataProtos.Portal.Direction.NORTH),
SOUTH(Vector(1, 0, 0), Vector(0, 0, -1), BlockFace.SOUTH, PortalSaveDataProtos.Portal.Direction.SOUTH), SOUTH(Vector(1, 0, 0), Vector(0, 0, -1), BlockFace.NORTH, PortalSaveDataProtos.Portal.Direction.SOUTH),
EAST(Vector(0, 0, 1), Vector(-1, 0, 0), BlockFace.EAST, PortalSaveDataProtos.Portal.Direction.EAST), EAST(Vector(0, 0, 1), Vector(-1, 0, 0), BlockFace.WEST, PortalSaveDataProtos.Portal.Direction.EAST),
WEST(Vector(0, 0, 1), Vector(1, 0, 0), BlockFace.WEST, PortalSaveDataProtos.Portal.Direction.WEST); WEST(Vector(0, 0, 1), Vector(1, 0, 0), BlockFace.EAST, PortalSaveDataProtos.Portal.Direction.WEST);
val glassOffsets: ImmutableList<Vector> = ImmutableList.of( val glassOffsets: ImmutableList<Vector> = ImmutableList.of(
// check corners first: // check corners first:
@ -178,20 +181,41 @@ data class PortalFrame(val lowerLeftFrontCorner: Location, val direction: Entran
val mineral = (lowerLeftFrontCorner + direction.mineralOffset).block.type val mineral = (lowerLeftFrontCorner + direction.mineralOffset).block.type
fun open() {
val block = portalCenter.block
val data = block.blockData
if (data is Openable) {
data.isOpen = true
block.blockData = data
}
}
fun close() {
val block = portalCenter.block
val data = block.blockData
if (data is Openable) {
data.isOpen = false
block.blockData = data
}
}
fun activate() { fun activate() {
val mineral = (lowerLeftFrontCorner + direction.mineralOffset).block val mineral = (lowerLeftFrontCorner + direction.mineralOffset).block
for (offset in direction.glassOffsets) { for (offset in direction.glassOffsets) {
(lowerLeftFrontCorner + offset).block.type = MINERAL_TYPES.getOrDefault(mineral.type, BROWN_STAINED_GLASS) (lowerLeftFrontCorner + offset).block.type = MINERAL_TYPES.getOrDefault(mineral.type, BROWN_STAINED_GLASS)
} }
portalCenter.world?.playSound(portalCenter, Sound.BLOCK_BEACON_ACTIVATE, 20f, 1f) val midCenter = portalCenter + MID_BLOCK
portalCenter.world?.spawnParticle(Particle.SPELL, portalCenter, 40) portalCenter.world?.playSound(midCenter, Sound.BLOCK_BEACON_ACTIVATE, 20f, 1f)
portalCenter.world?.spawnParticle(Particle.SPELL, midCenter, 75)
open()
} }
fun deactivate() { fun deactivate() {
for (offset in direction.glassOffsets) { for (offset in direction.glassOffsets) {
(lowerLeftFrontCorner + offset).block.type = GLASS (lowerLeftFrontCorner + offset).block.type = GLASS
} }
portalCenter.world?.playSound(portalCenter, Sound.BLOCK_BEACON_DEACTIVATE, 20f, 1f) val midCenter = portalCenter + MID_BLOCK
portalCenter.world?.spawnParticle(Particle.SMOKE_NORMAL, portalCenter, 40) portalCenter.world?.playSound(midCenter, Sound.BLOCK_BEACON_DEACTIVATE, 20f, 1f)
portalCenter.world?.spawnParticle(Particle.SMOKE_NORMAL, midCenter, 75)
} }
} }
Loading…
Cancel
Save