Adds some more fixes and improvements for vehicle teleportation
This commit is contained in:
parent
b1aa53c1a9
commit
0fe2a5b380
@ -12,18 +12,6 @@ public class BloxPopulator {
|
||||
private Material nextMat;
|
||||
private Axis nextAxis;
|
||||
|
||||
/**
|
||||
* Instantiates a new block populator
|
||||
*
|
||||
* @param blockLocation <p>The location to start from</p>
|
||||
* @param material <p>The material to populate</p>
|
||||
*/
|
||||
public BloxPopulator(BlockLocation blockLocation, Material material) {
|
||||
this.blockLocation = blockLocation;
|
||||
nextMat = material;
|
||||
nextAxis = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new block populator
|
||||
*
|
||||
|
@ -80,6 +80,7 @@ public class VehicleEventListener implements Listener {
|
||||
Stargate.log.warning(Stargate.getString("prefox") + "Unable to find portal destination");
|
||||
return;
|
||||
}
|
||||
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + destinationPortal.getId());
|
||||
destinationPortal.teleport(vehicle, entrancePortal);
|
||||
}
|
||||
}
|
||||
|
@ -391,7 +391,7 @@ public class GateHandler {
|
||||
*
|
||||
* @param gateFolder <p>The folder containing gate config files</p>
|
||||
*/
|
||||
public static void populateDefaults(String gateFolder) {
|
||||
private static void populateDefaults(String gateFolder) {
|
||||
loadGateFromJar("nethergate.gate", gateFolder);
|
||||
loadGateFromJar("watergate.gate", gateFolder);
|
||||
}
|
||||
|
@ -33,6 +33,18 @@ public class GateLayout {
|
||||
readLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets two of the corners of the gate layout creating the smallest box the gate can be contained within
|
||||
*
|
||||
* @return <p>Two of the gate's corners</p>
|
||||
*/
|
||||
public RelativeBlockVector[] getCorners() {
|
||||
return new RelativeBlockVector[] {
|
||||
new RelativeBlockVector(0, 0, 0),
|
||||
new RelativeBlockVector(layout[0].length - 1, layout.length - 1, 1)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the character array describing this layout
|
||||
*
|
||||
|
@ -13,6 +13,7 @@ import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.SignHelper;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -38,6 +39,9 @@ import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* This class represents a portal in space which points to one or several other portals
|
||||
*/
|
||||
public class Portal {
|
||||
|
||||
// Gate location block info
|
||||
@ -54,6 +58,7 @@ public class Portal {
|
||||
private BlockLocation button;
|
||||
private BlockLocation[] frame;
|
||||
private BlockLocation[] entrances;
|
||||
|
||||
// Gate information
|
||||
private String name;
|
||||
private String destination;
|
||||
@ -551,7 +556,7 @@ public class Portal {
|
||||
// Close this gate, then the dest gate.
|
||||
Material closedType = gate.getPortalClosedBlock();
|
||||
for (BlockLocation inside : getEntrances()) {
|
||||
Stargate.blockPopulatorQueue.add(new BloxPopulator(inside, closedType));
|
||||
Stargate.blockPopulatorQueue.add(new BloxPopulator(inside, closedType, null));
|
||||
}
|
||||
|
||||
updatePortalClosedState();
|
||||
@ -663,6 +668,8 @@ public class Portal {
|
||||
exit = stargatePortalEvent.getExit();
|
||||
}
|
||||
|
||||
loadChunks();
|
||||
|
||||
// If no event is passed in, assume it's a teleport, and act as such
|
||||
if (event == null) {
|
||||
exit.setYaw(this.getRotation());
|
||||
@ -698,8 +705,6 @@ public class Portal {
|
||||
Location traveller = vehicle.getLocation();
|
||||
Location exit = getExit(vehicle, traveller);
|
||||
|
||||
adjustRotation(traveller, exit, origin);
|
||||
|
||||
double velocity = vehicle.getVelocity().length();
|
||||
|
||||
// Stop and teleport
|
||||
@ -707,7 +712,10 @@ public class Portal {
|
||||
|
||||
// Get new velocity
|
||||
final Vector newVelocity = new Vector(modX, 0.0F, modZ);
|
||||
//-z
|
||||
Stargate.debug("teleport", modX + " " + modZ);
|
||||
newVelocity.multiply(velocity);
|
||||
adjustRotation(traveller, exit, origin);
|
||||
|
||||
List<Entity> passengers = vehicle.getPassengers();
|
||||
World vehicleWorld = exit.getWorld();
|
||||
@ -716,6 +724,8 @@ public class Portal {
|
||||
return;
|
||||
}
|
||||
|
||||
loadChunks();
|
||||
|
||||
if (!passengers.isEmpty()) {
|
||||
if (vehicle instanceof RideableMinecart || vehicle instanceof Boat) {
|
||||
putPassengersInNewVehicle(vehicle, passengers, vehicleWorld, exit, newVelocity);
|
||||
@ -770,6 +780,7 @@ public class Portal {
|
||||
private void handleVehiclePassengers(List<Entity> passengers, Vehicle targetVehicle, Location exit) {
|
||||
for (Entity passenger : passengers) {
|
||||
passenger.eject();
|
||||
//TODO: Fix random java.lang.IllegalStateException: Removing entity while ticking!
|
||||
if (!passenger.teleport(exit)) {
|
||||
Stargate.debug("handleVehiclePassengers", "Failed to teleport passenger");
|
||||
}
|
||||
@ -794,9 +805,11 @@ public class Portal {
|
||||
exitLocation = exit.modRelativeLoc(0D, 0D, 1, traveller.getYaw(),
|
||||
traveller.getPitch(), modX * back, 1, modZ * back);
|
||||
|
||||
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
||||
if (entitySize > 1) {
|
||||
exitLocation = preventExitSuffocation(relativeExit, exitLocation, entity);
|
||||
if (entity != null) {
|
||||
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
||||
if (entitySize > 1) {
|
||||
exitLocation = preventExitSuffocation(relativeExit, exitLocation, entity);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Stargate.log.log(Level.WARNING, Stargate.getString("prefix") + "Missing destination point in .gate file " + gate.getFilename());
|
||||
@ -892,13 +905,16 @@ public class Portal {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the chunk the portal is located at is loaded
|
||||
*
|
||||
* @return <p>True if the chunk containing the portal is loaded</p>
|
||||
* Loads the chunks at the portal's corners
|
||||
*/
|
||||
public boolean isChunkLoaded() {
|
||||
public void loadChunks() {
|
||||
//TODO: Improve this in the case where the portal sits between two chunks
|
||||
return getWorld().isChunkLoaded(topLeft.getBlock().getChunk());
|
||||
for (RelativeBlockVector vector : gate.getLayout().getCorners()) {
|
||||
Chunk chunk = getBlockAt(vector).getChunk();
|
||||
if (!getWorld().isChunkLoaded(chunk)) {
|
||||
chunk.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,7 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
public class PortalDirection {
|
||||
|
||||
|
||||
|
||||
}
|
@ -15,7 +15,6 @@ import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class GateLayoutTest {
|
||||
|
||||
@ -40,7 +39,7 @@ public class GateLayoutTest {
|
||||
expected.add(new RelativeBlockVector(1, 3, 0));
|
||||
expected.add(new RelativeBlockVector(2, 3, 0));
|
||||
|
||||
Set<RelativeBlockVector> exits = layout.getExits().keySet();
|
||||
List<RelativeBlockVector> exits = layout.getExits();
|
||||
exits.forEach((blockVector) -> assertTrue(expected.contains(blockVector)));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user