mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 09:11:26 +01:00
SPIGOT-7083: Add Boat.WoodenType, Boat.Status; deprecate TreeSpecies
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
60fb93349f
commit
2f0d31aa17
@ -16,6 +16,15 @@
|
|||||||
public class EntityBoat extends Entity {
|
public class EntityBoat extends Entity {
|
||||||
|
|
||||||
private static final DataWatcherObject<Integer> DATA_ID_HURT = DataWatcher.defineId(EntityBoat.class, DataWatcherRegistry.INT);
|
private static final DataWatcherObject<Integer> DATA_ID_HURT = DataWatcher.defineId(EntityBoat.class, DataWatcherRegistry.INT);
|
||||||
|
@@ -82,7 +91,7 @@
|
||||||
|
private boolean inputDown;
|
||||||
|
private double waterLevel;
|
||||||
|
private float landFriction;
|
||||||
|
- private EntityBoat.EnumStatus status;
|
||||||
|
+ public EntityBoat.EnumStatus status;
|
||||||
|
private EntityBoat.EnumStatus oldStatus;
|
||||||
|
private double lastYd;
|
||||||
|
private boolean isAboveBubbleColumn;
|
||||||
@@ -91,6 +100,14 @@
|
@@ -91,6 +100,14 @@
|
||||||
private float bubbleAngle;
|
private float bubbleAngle;
|
||||||
private float bubbleAngleO;
|
private float bubbleAngleO;
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package org.bukkit.craftbukkit.entity;
|
package org.bukkit.craftbukkit.entity;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import net.minecraft.world.entity.vehicle.EntityBoat;
|
import net.minecraft.world.entity.vehicle.EntityBoat;
|
||||||
import org.bukkit.TreeSpecies;
|
import org.bukkit.TreeSpecies;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.entity.Boat;
|
import org.bukkit.entity.Boat;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public class CraftBoat extends CraftVehicle implements Boat {
|
public class CraftBoat extends CraftVehicle implements Boat {
|
||||||
@ -22,6 +25,18 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
|||||||
getHandle().setType(getBoatType(species));
|
getHandle().setType(getBoatType(species));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getBoatType() {
|
||||||
|
return boatTypeFromNms(getHandle().getBoatType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBoatType(Type type) {
|
||||||
|
Preconditions.checkArgument(type != null, "Boat.Type cannot be null");
|
||||||
|
|
||||||
|
getHandle().setType(boatTypeToNms(type));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMaxSpeed() {
|
public double getMaxSpeed() {
|
||||||
return getHandle().maxSpeed;
|
return getHandle().maxSpeed;
|
||||||
@ -66,6 +81,11 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
|||||||
getHandle().landBoats = workOnLand;
|
getHandle().landBoats = workOnLand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status getStatus() {
|
||||||
|
return boatStatusFromNms(getHandle().status);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityBoat getHandle() {
|
public EntityBoat getHandle() {
|
||||||
return (EntityBoat) entity;
|
return (EntityBoat) entity;
|
||||||
@ -73,7 +93,7 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CraftBoat";
|
return "CraftBoat{boatType=" + getBoatType() + ",status=" + getStatus() + ",passengers=" + getPassengers().stream().map(Entity::toString).collect(Collectors.joining("-", "{", "}")) + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,6 +101,44 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
|||||||
return EntityType.BOAT;
|
return EntityType.BOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Boat.Type boatTypeFromNms(EntityBoat.EnumBoatType boatType) {
|
||||||
|
return switch (boatType) {
|
||||||
|
default -> throw new EnumConstantNotPresentException(Type.class, boatType.name());
|
||||||
|
case OAK -> Type.OAK;
|
||||||
|
case BIRCH -> Type.BIRCH;
|
||||||
|
case ACACIA -> Type.ACACIA;
|
||||||
|
case JUNGLE -> Type.JUNGLE;
|
||||||
|
case SPRUCE -> Type.SPRUCE;
|
||||||
|
case DARK_OAK -> Type.DARK_OAK;
|
||||||
|
case MANGROVE -> Type.MANGROVE;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityBoat.EnumBoatType boatTypeToNms(Boat.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
default -> throw new EnumConstantNotPresentException(EntityBoat.EnumBoatType.class, type.name());
|
||||||
|
case MANGROVE -> EntityBoat.EnumBoatType.MANGROVE;
|
||||||
|
case SPRUCE -> EntityBoat.EnumBoatType.SPRUCE;
|
||||||
|
case DARK_OAK -> EntityBoat.EnumBoatType.DARK_OAK;
|
||||||
|
case JUNGLE -> EntityBoat.EnumBoatType.JUNGLE;
|
||||||
|
case ACACIA -> EntityBoat.EnumBoatType.ACACIA;
|
||||||
|
case BIRCH -> EntityBoat.EnumBoatType.BIRCH;
|
||||||
|
case OAK -> EntityBoat.EnumBoatType.OAK;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Status boatStatusFromNms(EntityBoat.EnumStatus enumStatus) {
|
||||||
|
return switch (enumStatus) {
|
||||||
|
default -> throw new EnumConstantNotPresentException(Status.class, enumStatus.name());
|
||||||
|
case IN_AIR -> Status.IN_AIR;
|
||||||
|
case ON_LAND -> Status.ON_LAND;
|
||||||
|
case UNDER_WATER -> Status.UNDER_WATER;
|
||||||
|
case UNDER_FLOWING_WATER -> Status.UNDER_FLOWING_WATER;
|
||||||
|
case IN_WATER -> Status.IN_WATER;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static TreeSpecies getTreeSpecies(EntityBoat.EnumBoatType boatType) {
|
public static TreeSpecies getTreeSpecies(EntityBoat.EnumBoatType boatType) {
|
||||||
switch (boatType) {
|
switch (boatType) {
|
||||||
case SPRUCE:
|
case SPRUCE:
|
||||||
@ -99,6 +157,7 @@ public class CraftBoat extends CraftVehicle implements Boat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static EntityBoat.EnumBoatType getBoatType(TreeSpecies species) {
|
public static EntityBoat.EnumBoatType getBoatType(TreeSpecies species) {
|
||||||
switch (species) {
|
switch (species) {
|
||||||
case REDWOOD:
|
case REDWOOD:
|
||||||
|
26
paper-server/src/test/java/org/bukkit/entity/BoatTest.java
Normal file
26
paper-server/src/test/java/org/bukkit/entity/BoatTest.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package org.bukkit.entity;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.vehicle.EntityBoat;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftBoat;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class BoatTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypes() {
|
||||||
|
for (EntityBoat.EnumBoatType enumBoatType : EntityBoat.EnumBoatType.values()) {
|
||||||
|
CraftBoat.boatTypeFromNms(enumBoatType);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Boat.Type enumBoatType : Boat.Type.values()) {
|
||||||
|
CraftBoat.boatTypeToNms(enumBoatType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStatus() {
|
||||||
|
for (EntityBoat.EnumStatus enumStatus : EntityBoat.EnumStatus.values()) {
|
||||||
|
CraftBoat.boatStatusFromNms(enumStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user