mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
Added minecart classes and World.spawn*Minecart(). Minecart.getPassenger() is still a stub that needs to be implemented (due to of a need of a MC entity -> CraftBukkit entity lookup) and StorageMinecart.getInventory() is waiting on the implementation of inventory.
By: sk89q <the.sk89q@gmail.com>
This commit is contained in:
parent
b3568f83e7
commit
bccefe4c85
5 changed files with 151 additions and 1 deletions
|
@ -0,0 +1,69 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import net.minecraft.server.EntityMinecart;
|
||||
import org.bukkit.LivingEntity;
|
||||
import org.bukkit.Minecart;
|
||||
import org.bukkit.Vector;
|
||||
|
||||
/**
|
||||
* A minecart.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftMinecart extends CraftVehicle implements Minecart {
|
||||
/**
|
||||
* Stores the minecart type ID, which is used by Minecraft to differentiate
|
||||
* minecart types. Here we use subclasses.
|
||||
*/
|
||||
public enum Type {
|
||||
Minecart(0),
|
||||
StorageMinecart(1),
|
||||
PoweredMinecart(2);
|
||||
|
||||
private final int id;
|
||||
|
||||
private Type(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
protected EntityMinecart minecart;
|
||||
|
||||
public CraftMinecart(CraftServer server, EntityMinecart entity) {
|
||||
super(server, entity);
|
||||
minecart = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(minecart.s, minecart.t, minecart.u);
|
||||
}
|
||||
|
||||
public void setVelocity(Vector vel) {
|
||||
minecart.s = vel.getX();
|
||||
minecart.t = vel.getY();
|
||||
minecart.u = vel.getZ();
|
||||
}
|
||||
|
||||
public LivingEntity getPassenger() {
|
||||
// @TODO: Implement
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return minecart.j == null;
|
||||
}
|
||||
|
||||
public void setDamage(int damage) {
|
||||
minecart.a = damage;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return minecart.a;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import net.minecraft.server.EntityMinecart;
|
||||
import org.bukkit.PoweredMinecart;
|
||||
|
||||
/**
|
||||
* A powered minecart.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftPoweredMinecart extends CraftMinecart
|
||||
implements PoweredMinecart {
|
||||
public CraftPoweredMinecart(CraftServer server, EntityMinecart entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import net.minecraft.server.EntityMinecart;
|
||||
import org.bukkit.StorageMinecart;
|
||||
|
||||
/**
|
||||
* A storage minecart.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftStorageMinecart extends CraftMinecart
|
||||
implements StorageMinecart {
|
||||
public CraftStorageMinecart(CraftServer server, EntityMinecart entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import net.minecraft.server.Entity;
|
||||
|
||||
import org.bukkit.Vehicle;
|
||||
|
||||
/**
|
||||
* A vehicle.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class CraftVehicle extends CraftEntity implements Vehicle {
|
||||
public CraftVehicle(CraftServer server, Entity entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
}
|
|
@ -3,15 +3,19 @@ package org.bukkit.craftbukkit;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.EntityMinecart;
|
||||
import java.util.Random;
|
||||
import net.minecraft.server.WorldGenBigTree;
|
||||
import net.minecraft.server.WorldGenTrees;
|
||||
import net.minecraft.server.WorldServer;
|
||||
import net.minecraft.server.EntityArrow;
|
||||
import org.bukkit.Arrow;
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Minecart;
|
||||
import org.bukkit.PoweredMinecart;
|
||||
import org.bukkit.StorageMinecart;
|
||||
import org.bukkit.Vector;
|
||||
import org.bukkit.World;
|
||||
|
||||
|
@ -88,6 +92,33 @@ public class CraftWorld implements World {
|
|||
return new CraftArrow(world.getServer(), arrow);
|
||||
}
|
||||
|
||||
public Minecart spawnMinecart(Location loc) {
|
||||
EntityMinecart minecart = new EntityMinecart(
|
||||
world,
|
||||
loc.getX(), loc.getY(), loc.getZ(),
|
||||
CraftMinecart.Type.Minecart.getID());
|
||||
world.a(minecart);
|
||||
return new CraftMinecart(world.getServer(), minecart);
|
||||
}
|
||||
|
||||
public StorageMinecart spawnStorageMinecart(Location loc) {
|
||||
EntityMinecart minecart = new EntityMinecart(
|
||||
world,
|
||||
loc.getX(), loc.getY(), loc.getZ(),
|
||||
CraftMinecart.Type.StorageMinecart.getID());
|
||||
world.a(minecart);
|
||||
return new CraftStorageMinecart(world.getServer(), minecart);
|
||||
}
|
||||
|
||||
public PoweredMinecart spawnPoweredMinecart(Location loc) {
|
||||
EntityMinecart minecart = new EntityMinecart(
|
||||
world,
|
||||
loc.getX(), loc.getY(), loc.getZ(),
|
||||
CraftMinecart.Type.PoweredMinecart.getID());
|
||||
world.a(minecart);
|
||||
return new CraftPoweredMinecart(world.getServer(), minecart);
|
||||
}
|
||||
|
||||
public boolean generateTree(Location loc) {
|
||||
WorldGenTrees treeGen = new WorldGenTrees();
|
||||
return treeGen.a(world, rand,
|
||||
|
|
Loading…
Reference in a new issue