parent
bc83629876
commit
ebdab500b3
@ -0,0 +1,124 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="Palette2"> |
||||
<group name="Swing"> |
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> |
||||
</item> |
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> |
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> |
||||
<initial-values> |
||||
<property name="text" value="Button" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="RadioButton" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="CheckBox" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="Label" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
||||
<preferred-size width="200" height="200" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
||||
<preferred-size width="200" height="200" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> |
||||
<preferred-size width="-1" height="20" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> |
||||
</item> |
||||
</group> |
||||
</component> |
||||
</project> |
@ -0,0 +1,96 @@ |
||||
package net.deliciousreya.minecraftportal |
||||
|
||||
import com.google.common.collect.ImmutableList |
||||
import org.bukkit.Location |
||||
import org.bukkit.Material.AIR |
||||
import org.bukkit.Material.GLASS |
||||
import org.bukkit.block.Block |
||||
import org.bukkit.util.Vector |
||||
import net.deliciousreya.minecraftportal.extensions.* |
||||
|
||||
fun findPortalFrameConnectedTo(block:Block): PortalScanResults { |
||||
var bestScan:PortalScanResults? = null |
||||
if (block.type == GLASS) { |
||||
for (direction in PortalFrame.Direction.values()) { |
||||
for (vector in direction.glassOffsets) { |
||||
val scanResult = checkPortalFrameAt(block.location.subtract(vector), direction) |
||||
if (scanResult.frame != null) { |
||||
return scanResult |
||||
} |
||||
if (bestScan == null || scanResult > bestScan) { |
||||
bestScan = scanResult |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (block.type == GLASS) { |
||||
for (direction in PortalFrame.Direction.values()) { |
||||
val scanResult = checkPortalFrameAt(block.location.subtract(direction.mineralOffset), direction) |
||||
if (scanResult.frame != null) { |
||||
return scanResult |
||||
} else if (bestScan == null || scanResult > bestScan) { |
||||
bestScan = scanResult |
||||
} |
||||
} |
||||
} |
||||
if (bestScan != null) { |
||||
return bestScan |
||||
} else { |
||||
return PortalScanResults(null, ImmutableList.of(), ImmutableList.of()) |
||||
} |
||||
} |
||||
|
||||
/** Detects whether there is a portal frame in the given location, extending in the given direction. */ |
||||
fun checkPortalFrameAt(location:Location, direction:PortalFrame.Direction): PortalScanResults { |
||||
val matches = ImmutableList.Builder<Block>() |
||||
val nonmatches = ImmutableList.Builder<Block>() |
||||
for (vector in direction.glassOffsets) { |
||||
val block = (location + vector).block |
||||
(if (block.type == GLASS) matches else nonmatches).add(block) |
||||
} |
||||
for (vector in direction.airOffsets) { |
||||
val block = (location + vector).block |
||||
(if (block.type == AIR) matches else nonmatches).add(block) |
||||
} |
||||
val block = (location + direction.mineralOffset).block |
||||
(if (block.type == GLASS) matches else nonmatches).add(block) |
||||
val nonmatchesBuilt = nonmatches.build() |
||||
return PortalScanResults(if (nonmatchesBuilt.isEmpty()) {PortalFrame(location, direction)} else {null}, matches.build(), nonmatchesBuilt) |
||||
} |
||||
|
||||
data class PortalScanResults(val frame: PortalFrame?, val matchingBlocks:List<Block>, val nonMatchingBlocks:List<Block>) : Comparable<PortalScanResults> { |
||||
override fun compareTo(other:PortalScanResults): Int { |
||||
return matchingBlocks.size - other.matchingBlocks.size |
||||
} |
||||
} |
||||
|
||||
/** Information about a portal frame. */ |
||||
data class PortalFrame(val lowerLeftCorner: Location, val direction: Direction) { |
||||
val UP = Vector(0, 1, 0) |
||||
/** The direction along which a portal frame extends. */ |
||||
enum class Direction(vector: Vector) { |
||||
X_AXIS(Vector(1, 0, 0)), |
||||
Z_AXIS(Vector(0, 0, 1)); |
||||
|
||||
private val rightSideVector = vector * 2 |
||||
|
||||
val glassOffsets: ImmutableList<Vector> = ImmutableList.of( |
||||
Vector(0, 0, 0), |
||||
Vector(0, 1, 0), |
||||
Vector(0, 2, 0), |
||||
Vector(0, 3, 0), |
||||
vector, |
||||
rightSideVector, |
||||
Vector(0, 1, 0) + rightSideVector, |
||||
Vector(0, 2, 0) + rightSideVector, |
||||
Vector(0, 3, 0) + rightSideVector |
||||
) |
||||
|
||||
val mineralOffset: Vector = Vector(0, 3, 0) + vector |
||||
|
||||
val airOffsets: ImmutableList<Vector> = ImmutableList.of( |
||||
Vector(0, 1, 0) + vector, |
||||
Vector(0, 2, 0) + vector |
||||
) |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
package net.deliciousreya.minecraftportal.extensions |
||||
|
||||
import org.bukkit.Location |
||||
import org.bukkit.util.Vector |
||||
|
||||
operator fun Location.plus(v: Vector):Location { |
||||
return this.clone().add(v) |
||||
} |
||||
|
||||
operator fun Location.plus(l: Location):Location { |
||||
return this.clone().add(l) |
||||
} |
||||
|
||||
fun Location.plus(x: Double, y: Double, z: Double):Location { |
||||
return this.clone().add(x, y, z) |
||||
} |
||||
|
||||
operator fun Location.minus(v:Vector):Location { |
||||
return this.clone().subtract(v) |
||||
} |
||||
|
||||
operator fun Location.minus(l: Location):Location { |
||||
return this.clone().subtract(l) |
||||
} |
||||
|
||||
fun Location.minus(x: Double, y: Double, z: Double):Location { |
||||
return this.clone().subtract(x, y, z) |
||||
} |
||||
|
||||
operator fun Location.times(n:Double):Location { |
||||
return this.clone().multiply(n) |
||||
} |
@ -0,0 +1,31 @@ |
||||
package net.deliciousreya.minecraftportal.extensions |
||||
|
||||
import org.bukkit.util.Vector |
||||
|
||||
operator fun Vector.plus(v:Vector):Vector { |
||||
return this.clone().add(v) |
||||
} |
||||
|
||||
operator fun Vector.minus(v:Vector):Vector { |
||||
return this.clone().subtract(v) |
||||
} |
||||
|
||||
operator fun Vector.times(n:Int):Vector { |
||||
return this.clone().multiply(n) |
||||
} |
||||
|
||||
operator fun Vector.times(n:Float):Vector { |
||||
return this.clone().multiply(n) |
||||
} |
||||
|
||||
operator fun Vector.times(n:Double):Vector { |
||||
return this.clone().multiply(n) |
||||
} |
||||
|
||||
operator fun Vector.times(v:Vector):Vector { |
||||
return this.clone().multiply(v) |
||||
} |
||||
|
||||
operator fun Vector.div(v:Vector):Vector { |
||||
return this.clone().divide(v) |
||||
} |
Loading…
Reference in new issue