Skip to content

Commit

Permalink
Adds Mocks for both Boat and ChestBoat (#851)
Browse files Browse the repository at this point in the history
* Adds Mocks for both Boat and ChestBoat

* chore(boats): Implement Changes

* feat(entities): Remove Loottable API from Chestboat and add getType

* Fix formatting

---------

Co-authored-by: Thorinwasher <ragnarlol96@gmail.com>
Co-authored-by: Thorinwasher <37477983+Thorinwasher@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 29, 2024
1 parent 001f91a commit 920fbc9
Show file tree
Hide file tree
Showing 6 changed files with 579 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/main/java/be/seeseemelk/mockbukkit/WorldMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import be.seeseemelk.mockbukkit.entity.BatMock;
import be.seeseemelk.mockbukkit.entity.BeeMock;
import be.seeseemelk.mockbukkit.entity.BlazeMock;
import be.seeseemelk.mockbukkit.entity.BoatMock;
import be.seeseemelk.mockbukkit.entity.CamelMock;
import be.seeseemelk.mockbukkit.entity.CatMock;
import be.seeseemelk.mockbukkit.entity.CaveSpiderMock;
import be.seeseemelk.mockbukkit.entity.ChestBoatMock;
import be.seeseemelk.mockbukkit.entity.ChickenMock;
import be.seeseemelk.mockbukkit.entity.CodMock;
import be.seeseemelk.mockbukkit.entity.CommandMinecartMock;
Expand Down Expand Up @@ -132,9 +134,11 @@
import org.bukkit.entity.Bat;
import org.bukkit.entity.Bee;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Camel;
import org.bukkit.entity.Cat;
import org.bukkit.entity.CaveSpider;
import org.bukkit.entity.ChestBoat;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cod;
import org.bukkit.entity.Cow;
Expand Down Expand Up @@ -251,8 +255,8 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -1316,6 +1320,14 @@ else if (clazz == AreaEffectCloud.class)
{
return new AreaEffectCloudMock(server, UUID.randomUUID());
}
else if (clazz == Boat.class)
{
return new BoatMock(server, UUID.randomUUID());
}
else if (clazz == ChestBoat.class)
{
return new ChestBoatMock(server, UUID.randomUUID());
}
else if (clazz == EnderPearl.class)
{
return new EnderPearlMock(server, UUID.randomUUID());
Expand Down Expand Up @@ -1371,7 +1383,7 @@ else if (clazz == Silverfish.class)
else if (clazz == Turtle.class)
{
return new TurtleMock(server, UUID.randomUUID());
}
}
else if (clazz == ThrownExpBottle.class)
{
return new ThrownExpBottleMock(server, UUID.randomUUID());
Expand Down Expand Up @@ -2764,12 +2776,14 @@ private boolean isOfHeightMap(Block block, HeightMap heightMap)
}
case MOTION_BLOCKING_NO_LEAVES ->
{
boolean isWaterLogged = block.getBlockData() instanceof Waterlogged waterlogged && waterlogged.isWaterlogged();
boolean isWaterLogged = block.getBlockData() instanceof Waterlogged waterlogged && waterlogged.isWaterlogged();
yield (block.isSolid() || isWaterLogged || block.isLiquid()) && !Tag.LEAVES.isTagged(block.getType());
}
case OCEAN_FLOOR -> block.isSolid();
case OCEAN_FLOOR_WG -> (block.getY() <= this.grassHeight && this.defaultBlock.isSolid()) || block.getY() == 0;
case WORLD_SURFACE_WG -> (block.getY() <= this.grassHeight && !this.defaultBlock.isAir()) || block.getY() == 0;
case OCEAN_FLOOR_WG ->
(block.getY() <= this.grassHeight && this.defaultBlock.isSolid()) || block.getY() == 0;
case WORLD_SURFACE_WG ->
(block.getY() <= this.grassHeight && !this.defaultBlock.isAir()) || block.getY() == 0;
case WORLD_SURFACE -> !block.getType().isAir();
};
}
Expand Down
171 changes: 171 additions & 0 deletions src/main/java/be/seeseemelk/mockbukkit/entity/BoatMock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package be.seeseemelk.mockbukkit.entity;

import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.UnimplementedOperationException;
import com.google.common.base.Preconditions;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.entity.Boat;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class BoatMock extends VehicleMock implements Boat
{

private @NotNull Type boatType = Type.OAK;
private double maxSpeed = 0.4D;
private double ocupiedDeceleration = 0.2D;
private double unoccupiedDeceleration = -1;
private boolean workOnLand = false;

/**
* Constructs a new {@link BoatMock} on the provided {@link ServerMock} with a specified {@link UUID}.
*
* @param server The server to create the entity on.
* @param uuid The UUID of the entity.
*/
public BoatMock(@NotNull ServerMock server, @NotNull UUID uuid)
{
super(server, uuid);
}

@Override
@Deprecated
public @NotNull TreeSpecies getWoodType()
{
return switch (boatType)
{
case SPRUCE -> TreeSpecies.REDWOOD;
case BIRCH -> TreeSpecies.BIRCH;
case JUNGLE -> TreeSpecies.JUNGLE;
case ACACIA -> TreeSpecies.ACACIA;
case DARK_OAK -> TreeSpecies.DARK_OAK;
default -> TreeSpecies.GENERIC;
};
}

@Override
@Deprecated
public void setWoodType(@NotNull TreeSpecies species)
{
Preconditions.checkNotNull(species, "Species can not be null");
Type type;

type = switch (species)
{
case GENERIC -> Type.OAK;
case BIRCH -> Type.BIRCH;
case ACACIA -> Type.ACACIA;
case JUNGLE -> Type.JUNGLE;
case DARK_OAK -> Type.DARK_OAK;
case REDWOOD -> Type.SPRUCE;
};

this.boatType = type;

}

@Override
public @NotNull Type getBoatType()
{
return this.boatType;
}

@Override
public void setBoatType(@NotNull Type type)
{
Preconditions.checkNotNull(type, "Type cannot be null");
this.boatType = type;
}

@Override
@Deprecated
public double getMaxSpeed()
{
return this.maxSpeed;
}

@Override
@Deprecated
public void setMaxSpeed(double speed)
{
Preconditions.checkArgument(speed >= 0.0D, "Speed cannot be negative");
this.maxSpeed = speed;
}

@Override
@Deprecated
public double getOccupiedDeceleration()
{
return this.ocupiedDeceleration;
}

@Override
@Deprecated
public void setOccupiedDeceleration(double rate)
{
Preconditions.checkArgument(rate >= 0.0D, "Rate cannot be negative");
this.ocupiedDeceleration = rate;
}

@Override
@Deprecated
public double getUnoccupiedDeceleration()
{
return this.unoccupiedDeceleration;
}

@Override
@Deprecated
public void setUnoccupiedDeceleration(double rate)
{
this.unoccupiedDeceleration = rate;
}

@Override
@Deprecated
public boolean getWorkOnLand()
{
return workOnLand;
}

@Override
@Deprecated
public void setWorkOnLand(boolean workOnLand)
{
this.workOnLand = workOnLand;
}

@Override
public @NotNull Status getStatus()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public @NotNull Material getBoatMaterial()
{
return switch (boatType)
{
case OAK -> Material.OAK_BOAT;
case SPRUCE -> Material.SPRUCE_BOAT;
case BIRCH -> Material.BIRCH_BOAT;
case JUNGLE -> Material.JUNGLE_BOAT;
case ACACIA -> Material.ACACIA_BOAT;
case CHERRY -> Material.CHERRY_BOAT;
case DARK_OAK -> Material.DARK_OAK_BOAT;
case MANGROVE -> Material.MANGROVE_BOAT;
case BAMBOO -> Material.BAMBOO_RAFT;
};
}

@Override
public @NotNull EntityType getType()
{
return EntityType.BOAT;
}

}

0 comments on commit 920fbc9

Please sign in to comment.