Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements a Cart Lift block to teleport players either directly up or down
- Loading branch information
Showing
3 changed files
with
71 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
vehicles/src/main/java/com/sk89q/craftbook/cart/CartLift.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.sk89q.craftbook.cart; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Minecart; | ||
|
||
public class CartLift extends CartMechanism { | ||
|
||
@Override | ||
public void impact(Minecart cart, CartMechanismBlocks blocks, boolean minor) { | ||
// validate | ||
if (cart == null) return; | ||
if (blocks.sign == null) return; | ||
if (!(blocks.matches("lift up") || blocks.matches("lift down"))) return; | ||
|
||
// go | ||
boolean up = blocks.matches("lift up"); | ||
Block destination = blocks.sign; | ||
|
||
BlockFace face; | ||
if (up) face = BlockFace.UP; | ||
else face = BlockFace.DOWN; | ||
|
||
while (true) { | ||
|
||
destination = destination.getRelative(face); | ||
|
||
if (destination.getState() instanceof Sign | ||
&& blocks.base.getTypeId() == destination.getRelative(BlockFace.UP).getTypeId()) { | ||
String testLine = ((Sign) destination.getState()).getLine(2); | ||
|
||
if (testLine.equalsIgnoreCase("[Lift Up]") || testLine.equalsIgnoreCase("[Lift Down]") | ||
|| testLine.equalsIgnoreCase("[Lift]")) { | ||
destination.getRelative(BlockFace.UP, 2); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
cart.teleport(destination.getLocation()); | ||
} | ||
|
||
@Override | ||
public void enter(Minecart cart, Entity entity, CartMechanismBlocks blocks, | ||
boolean minor) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters