#1181: Consolidate Location conversion code
By: Doc <nachito94@msn.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -85,7 +86,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
||||
if (random != null) {
|
||||
builder = builder.withRandom(new RandomSourceWrapper(random));
|
||||
}
|
||||
setMaybe(builder, LootContextParameters.ORIGIN, new Vec3D(loc.getX(), loc.getY(), loc.getZ()));
|
||||
setMaybe(builder, LootContextParameters.ORIGIN, CraftLocation.toVec3D(loc));
|
||||
if (getHandle() != LootTable.EMPTY) {
|
||||
// builder.luck(context.getLuck());
|
||||
|
||||
@@ -137,7 +138,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
|
||||
if (position == null) {
|
||||
position = info.getParamOrNull(LootContextParameters.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParameterSets
|
||||
}
|
||||
Location location = new Location(info.getLevel().getWorld(), position.x(), position.y(), position.z());
|
||||
Location location = CraftLocation.toBukkit(position, info.getLevel().getWorld());
|
||||
LootContext.Builder contextBuilder = new LootContext.Builder(location);
|
||||
|
||||
if (info.hasParam(LootContextParameters.KILLER_ENTITY)) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
@@ -206,12 +207,11 @@ public enum CraftParticle {
|
||||
}
|
||||
if (particle.getDataType() == Vibration.class) {
|
||||
Vibration vibration = (Vibration) obj;
|
||||
Location origin = vibration.getOrigin();
|
||||
|
||||
PositionSource source;
|
||||
if (vibration.getDestination() instanceof Vibration.Destination.BlockDestination) {
|
||||
Location destination = ((Vibration.Destination.BlockDestination) vibration.getDestination()).getLocation();
|
||||
source = new BlockPositionSource(new BlockPosition(destination.getBlockX(), destination.getBlockY(), destination.getBlockZ()));
|
||||
source = new BlockPositionSource(CraftLocation.toBlockPosition(destination));
|
||||
} else if (vibration.getDestination() instanceof Vibration.Destination.EntityDestination) {
|
||||
Entity destination = ((CraftEntity) ((Vibration.Destination.EntityDestination) vibration.getDestination()).getEntity()).getHandle();
|
||||
source = new EntityPositionSource(destination, destination.getEyeHeight());
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.world.level.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Raid;
|
||||
import org.bukkit.Raid.RaidStatus;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.Raider;
|
||||
|
||||
public final class CraftRaid implements Raid {
|
||||
@@ -49,7 +50,7 @@ public final class CraftRaid implements Raid {
|
||||
public Location getLocation() {
|
||||
BlockPosition pos = handle.getCenter();
|
||||
World world = handle.getLevel();
|
||||
return new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ());
|
||||
return CraftLocation.toBukkit(pos, world.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,6 +65,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.craftbukkit.util.BlockStateListPopulator;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
@@ -306,7 +307,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||
|
||||
@Override
|
||||
public boolean generateTree(Location location, Random random, TreeType treeType) {
|
||||
BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition pos = CraftLocation.toBlockPosition(location);
|
||||
return generateTree(getHandle(), getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, new RandomSourceWrapper(random), treeType);
|
||||
}
|
||||
|
||||
@@ -320,7 +321,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||
|
||||
@Override
|
||||
public boolean generateTree(Location location, Random random, TreeType treeType, Predicate<BlockState> predicate) {
|
||||
BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition pos = CraftLocation.toBlockPosition(location);
|
||||
BlockStateListPopulator populator = new BlockStateListPopulator(getHandle());
|
||||
boolean result = generateTree(populator, getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, new RandomSourceWrapper(random), treeType);
|
||||
populator.refreshTiles();
|
||||
|
||||
@@ -190,6 +190,7 @@ import org.bukkit.craftbukkit.tag.CraftFluidTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftItemTag;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftIconCache;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftSpawnCategory;
|
||||
@@ -1568,7 +1569,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
WorldServer worldServer = ((CraftWorld) world).getHandle();
|
||||
Location structureLocation = world.locateNearestStructure(location, structureType, radius, findUnexplored);
|
||||
BlockPosition structurePosition = new BlockPosition(structureLocation.getBlockX(), structureLocation.getBlockY(), structureLocation.getBlockZ());
|
||||
BlockPosition structurePosition = CraftLocation.toBlockPosition(structureLocation);
|
||||
|
||||
// Create map with trackPlayer = true, unlimitedTracking = true
|
||||
net.minecraft.world.item.ItemStack stack = ItemWorldMap.create(worldServer, structurePosition.getX(), structurePosition.getZ(), MapView.Scale.NORMAL.getValue(), true, true);
|
||||
@@ -1967,7 +1968,7 @@ public final class CraftServer implements Server {
|
||||
if (pos == null) {
|
||||
completions = getCommandMap().tabComplete(player, message);
|
||||
} else {
|
||||
completions = getCommandMap().tabComplete(player, message, new Location(world.getWorld(), pos.x, pos.y, pos.z));
|
||||
completions = getCommandMap().tabComplete(player, message, CraftLocation.toBukkit(pos, world.getWorld()));
|
||||
}
|
||||
} catch (CommandException ex) {
|
||||
player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command");
|
||||
|
||||
@@ -101,6 +101,7 @@ import org.bukkit.craftbukkit.metadata.BlockMetadataStore;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
|
||||
@@ -180,7 +181,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
public Location getSpawnLocation() {
|
||||
BlockPosition spawn = world.getSharedSpawnPos();
|
||||
float yaw = world.getSharedSpawnAngle();
|
||||
return new Location(this, spawn.getX(), spawn.getY(), spawn.getZ(), yaw, 0);
|
||||
return CraftLocation.toBukkit(spawn, this, yaw, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -948,8 +949,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
}
|
||||
|
||||
Vector dir = direction.clone().normalize().multiply(maxDistance);
|
||||
Vec3D startPos = new Vec3D(start.getX(), start.getY(), start.getZ());
|
||||
Vec3D endPos = new Vec3D(start.getX() + dir.getX(), start.getY() + dir.getY(), start.getZ() + dir.getZ());
|
||||
Vec3D startPos = CraftLocation.toVec3D(start);
|
||||
Vec3D endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
|
||||
MovingObjectPosition nmsHitResult = this.getHandle().clip(new RayTrace(startPos, endPos, ignorePassableBlocks ? RayTrace.BlockCollisionOption.COLLIDER : RayTrace.BlockCollisionOption.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), null));
|
||||
|
||||
return CraftRayTraceResult.fromNMS(this, nmsHitResult);
|
||||
@@ -1142,7 +1143,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
Validate.notNull(effect, "Effect cannot be null");
|
||||
Validate.notNull(location.getWorld(), "World cannot be null");
|
||||
int packetData = effect.getId();
|
||||
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(packetData, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), data, false);
|
||||
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(packetData, CraftLocation.toBlockPosition(location), data, false);
|
||||
int distance;
|
||||
radius *= radius;
|
||||
|
||||
@@ -1885,7 +1886,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CraftStructureSearchResult(CraftStructure.minecraftToBukkit(found.getSecond().value(), getHandle().registryAccess()), new Location(this, found.getFirst().getX(), found.getFirst().getY(), found.getFirst().getZ()));
|
||||
return new CraftStructureSearchResult(CraftStructure.minecraftToBukkit(found.getSecond().value(), getHandle().registryAccess()), CraftLocation.toBukkit(found.getFirst(), this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1894,7 +1895,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
Validate.isTrue(radius >= 0, "Radius cannot be negative");
|
||||
|
||||
PersistentRaid persistentRaid = world.getRaids();
|
||||
net.minecraft.world.entity.raid.Raid raid = persistentRaid.getNearbyRaid(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), radius * radius);
|
||||
net.minecraft.world.entity.raid.Raid raid = persistentRaid.getNearbyRaid(CraftLocation.toBlockPosition(location), radius * radius);
|
||||
return (raid == null) ? null : new CraftRaid(raid);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Beehive;
|
||||
import org.bukkit.craftbukkit.entity.CraftBee;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.Bee;
|
||||
|
||||
public class CraftBeehive extends CraftBlockEntityState<TileEntityBeehive> implements Beehive {
|
||||
@@ -22,13 +23,13 @@ public class CraftBeehive extends CraftBlockEntityState<TileEntityBeehive> imple
|
||||
@Override
|
||||
public Location getFlower() {
|
||||
BlockPosition flower = getSnapshot().savedFlowerPos;
|
||||
return (flower == null) ? null : new Location(getWorld(), flower.getX(), flower.getY(), flower.getZ());
|
||||
return (flower == null) ? null : CraftLocation.toBukkit(flower, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlower(Location location) {
|
||||
Preconditions.checkArgument(location == null || this.getWorld().equals(location.getWorld()), "Flower must be in same world");
|
||||
getSnapshot().savedFlowerPos = (location == null) ? null : new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
getSnapshot().savedFlowerPos = (location == null) ? null : CraftLocation.toBlockPosition(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,13 +5,11 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.EnumDirection;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
@@ -54,6 +52,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
|
||||
@@ -106,7 +105,7 @@ public class CraftBlock implements Block {
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(getWorld(), position.getX(), position.getY(), position.getZ());
|
||||
return CraftLocation.toBukkit(position, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -605,8 +604,8 @@ public class CraftBlock implements Block {
|
||||
}
|
||||
|
||||
Vector dir = direction.clone().normalize().multiply(maxDistance);
|
||||
Vec3D startPos = new Vec3D(start.getX(), start.getY(), start.getZ());
|
||||
Vec3D endPos = new Vec3D(start.getX() + dir.getX(), start.getY() + dir.getY(), start.getZ() + dir.getZ());
|
||||
Vec3D startPos = CraftLocation.toVec3D(start);
|
||||
Vec3D endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
|
||||
|
||||
MovingObjectPosition nmsHitResult = world.clip(new RayTrace(startPos, endPos, RayTrace.BlockCollisionOption.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), null), position);
|
||||
return CraftRayTraceResult.fromNMS(this.getWorld(), nmsHitResult);
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.material.Attachable;
|
||||
import org.bukkit.material.MaterialData;
|
||||
@@ -239,7 +240,7 @@ public class CraftBlockState implements BlockState {
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(world, getX(), getY(), getZ());
|
||||
return CraftLocation.toBukkit(this.position, this.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.world.level.block.entity.TileEntityEndGateway;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.EndGateway;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
|
||||
public class CraftEndGateway extends CraftBlockEntityState<TileEntityEndGateway> implements EndGateway {
|
||||
|
||||
@@ -16,7 +17,7 @@ public class CraftEndGateway extends CraftBlockEntityState<TileEntityEndGateway>
|
||||
@Override
|
||||
public Location getExitLocation() {
|
||||
BlockPosition pos = this.getSnapshot().exitPortal;
|
||||
return pos == null ? null : new Location(this.isPlaced() ? this.getWorld() : null, pos.getX(), pos.getY(), pos.getZ());
|
||||
return pos == null ? null : CraftLocation.toBukkit(pos, this.isPlaced() ? this.getWorld() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,7 +27,7 @@ public class CraftEndGateway extends CraftBlockEntityState<TileEntityEndGateway>
|
||||
} else if (!Objects.equals(location.getWorld(), this.isPlaced() ? this.getWorld() : null)) {
|
||||
throw new IllegalArgumentException("Cannot set exit location to different world");
|
||||
} else {
|
||||
this.getSnapshot().exitPortal = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
this.getSnapshot().exitPortal = CraftLocation.toBlockPosition(location);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.block.structure.Mirror;
|
||||
import org.bukkit.block.structure.StructureRotation;
|
||||
import org.bukkit.block.structure.UsageMode;
|
||||
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
||||
import org.bukkit.craftbukkit.util.CraftBlockVector;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public BlockVector getRelativePosition() {
|
||||
return new BlockVector(getSnapshot().structurePos.getX(), getSnapshot().structurePos.getY(), getSnapshot().structurePos.getZ());
|
||||
return CraftBlockVector.toBukkit(getSnapshot().structurePos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,12 +63,12 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
Validate.isTrue(isBetween(vector.getBlockX(), -MAX_SIZE, MAX_SIZE), "Structure Size (X) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockY(), -MAX_SIZE, MAX_SIZE), "Structure Size (Y) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockZ(), -MAX_SIZE, MAX_SIZE), "Structure Size (Z) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
|
||||
getSnapshot().structurePos = new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
getSnapshot().structurePos = CraftBlockVector.toBlockPosition(vector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector getStructureSize() {
|
||||
return new BlockVector(getSnapshot().structureSize.getX(), getSnapshot().structureSize.getY(), getSnapshot().structureSize.getZ());
|
||||
return CraftBlockVector.toBukkit(getSnapshot().structureSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +76,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
Validate.isTrue(isBetween(vector.getBlockX(), 0, MAX_SIZE), "Structure Size (X) must be between 0 and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockY(), 0, MAX_SIZE), "Structure Size (Y) must be between 0 and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockZ(), 0, MAX_SIZE), "Structure Size (Z) must be between 0 and " + MAX_SIZE);
|
||||
getSnapshot().structureSize = new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
getSnapshot().structureSize = CraftBlockVector.toBlockPosition(vector);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockSupport;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -610,7 +611,7 @@ public class CraftBlockData implements BlockData {
|
||||
CraftWorld world = (CraftWorld) location.getWorld();
|
||||
Preconditions.checkArgument(world != null, "location must not have a null world");
|
||||
|
||||
BlockPosition position = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition position = CraftLocation.toBlockPosition(location);
|
||||
return state.canSurvive(world.getHandle(), position);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.boss.DragonBattle;
|
||||
import org.bukkit.boss.DragonBattle.RespawnPhase;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
|
||||
public class CraftDragonBattle implements DragonBattle {
|
||||
@@ -35,7 +36,7 @@ public class CraftDragonBattle implements DragonBattle {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Location(handle.level.getWorld(), handle.portalLocation.getX(), handle.portalLocation.getY(), handle.portalLocation.getZ());
|
||||
return CraftLocation.toBukkit(this.handle.portalLocation, this.handle.level.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
@@ -70,7 +71,7 @@ public class CraftAllay extends CraftCreature implements org.bukkit.entity.Allay
|
||||
public void startDancing(Location location) {
|
||||
Preconditions.checkArgument(location != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(location.getBlock().getType().equals(Material.JUKEBOX), "The Block in the Location need to be a JukeBox");
|
||||
getHandle().setJukeboxPlaying(BlockPosition.containing(location.getX(), location.getY(), location.getZ()), true);
|
||||
getHandle().setJukeboxPlaying(CraftLocation.toBlockPosition(location), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +95,6 @@ public class CraftAllay extends CraftCreature implements org.bukkit.entity.Allay
|
||||
|
||||
public Location getJukebox() {
|
||||
BlockPosition nmsJukeboxPos = getHandle().jukeboxPos;
|
||||
return (nmsJukeboxPos != null) ? new Location(getWorld(), nmsJukeboxPos.getX(), nmsJukeboxPos.getY(), nmsJukeboxPos.getZ()) : null;
|
||||
return (nmsJukeboxPos != null) ? CraftLocation.toBukkit(nmsJukeboxPos, getWorld()) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.animal.EntityBee;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.Bee;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@@ -32,25 +33,25 @@ public class CraftBee extends CraftAnimals implements Bee {
|
||||
@Override
|
||||
public Location getHive() {
|
||||
BlockPosition hive = getHandle().getHivePos();
|
||||
return (hive == null) ? null : new Location(getWorld(), hive.getX(), hive.getY(), hive.getZ());
|
||||
return (hive == null) ? null : CraftLocation.toBukkit(hive, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHive(Location location) {
|
||||
Preconditions.checkArgument(location == null || this.getWorld().equals(location.getWorld()), "Hive must be in same world");
|
||||
getHandle().hivePos = (location == null) ? null : new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
getHandle().hivePos = (location == null) ? null : CraftLocation.toBlockPosition(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getFlower() {
|
||||
BlockPosition flower = getHandle().getSavedFlowerPos();
|
||||
return (flower == null) ? null : new Location(getWorld(), flower.getX(), flower.getY(), flower.getZ());
|
||||
return (flower == null) ? null : CraftLocation.toBukkit(flower, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlower(Location location) {
|
||||
Preconditions.checkArgument(location == null || this.getWorld().equals(location.getWorld()), "Flower must be in same world");
|
||||
getHandle().setSavedFlowerPos(location == null ? null : new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
getHandle().setSavedFlowerPos(location == null ? null : CraftLocation.toBlockPosition(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EntityEnderCrystal;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class CraftEnderCrystal extends CraftEntity implements EnderCrystal {
|
||||
@Override
|
||||
public Location getBeamTarget() {
|
||||
BlockPosition pos = getHandle().getBeamTarget();
|
||||
return pos == null ? null : new Location(getWorld(), pos.getX(), pos.getY(), pos.getZ());
|
||||
return pos == null ? null : CraftLocation.toBukkit(pos, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,7 +36,7 @@ public class CraftEnderCrystal extends CraftEntity implements EnderCrystal {
|
||||
} else if (location.getWorld() != getWorld()) {
|
||||
throw new IllegalArgumentException("Cannot set beam target location to different world");
|
||||
} else {
|
||||
getHandle().setBeamTarget(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
getHandle().setBeamTarget(CraftLocation.toBlockPosition(location));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.world.item.Items;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EnderSignal;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -39,7 +40,7 @@ public class CraftEnderSignal extends CraftEntity implements EnderSignal {
|
||||
@Override
|
||||
public void setTargetLocation(Location location) {
|
||||
Preconditions.checkArgument(getWorld().equals(location.getWorld()), "Cannot target EnderSignal across worlds");
|
||||
getHandle().signalTo(BlockPosition.containing(location.getX(), location.getY(), location.getZ()));
|
||||
getHandle().signalTo(CraftLocation.toBlockPosition(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -175,6 +175,7 @@ import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftSpawnCategory;
|
||||
import org.bukkit.craftbukkit.util.CraftVector;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -437,7 +438,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(getWorld(), entity.getX(), entity.getY(), entity.getZ(), entity.getBukkitYaw(), entity.getXRot());
|
||||
return CraftLocation.toBukkit(entity.position(), getWorld(), entity.getBukkitYaw(), entity.getXRot());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -537,7 +538,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
if (location.getWorld() != null && !location.getWorld().equals(getWorld())) {
|
||||
// Prevent teleportation to an other world during world generation
|
||||
Preconditions.checkState(!entity.generation, "Cannot teleport entity to an other world during world generation");
|
||||
entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), new Position(location.getX(), location.getY(), location.getZ()));
|
||||
entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toPosition(location));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
EntityFishingHook hook = getHandle();
|
||||
|
||||
if (this.biteChance == -1) {
|
||||
if (hook.level.isRainingAt(new BlockPosition(MathHelper.floor(hook.getX()), MathHelper.floor(hook.getY()) + 1, MathHelper.floor(hook.getZ())))) {
|
||||
if (hook.level.isRainingAt(BlockPosition.containing(hook.position()).offset(0, 1, 0))) {
|
||||
return 1 / 300.0;
|
||||
}
|
||||
return 1 / 500.0;
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.inventory.CraftMerchantCustom;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.Firework;
|
||||
@@ -136,7 +137,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
Preconditions.checkArgument(location.getWorld() != null, "Location needs to be in a world");
|
||||
Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds");
|
||||
|
||||
BlockPosition blockposition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition blockposition = CraftLocation.toBlockPosition(location);
|
||||
IBlockData iblockdata = getHandle().level.getBlockState(blockposition);
|
||||
if (!(iblockdata.getBlock() instanceof BlockBed)) {
|
||||
return false;
|
||||
@@ -147,7 +148,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
}
|
||||
|
||||
// From BlockBed
|
||||
iblockdata = (IBlockData) iblockdata.setValue(BlockBed.OCCUPIED, true);
|
||||
iblockdata = iblockdata.setValue(BlockBed.OCCUPIED, true);
|
||||
getHandle().level.setBlock(blockposition, iblockdata, 4);
|
||||
|
||||
return true;
|
||||
@@ -165,7 +166,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
Preconditions.checkState(isSleeping(), "Not sleeping");
|
||||
|
||||
BlockPosition bed = getHandle().getSleepingPos().get();
|
||||
return new Location(getWorld(), bed.getX(), bed.getY(), bed.getZ());
|
||||
return CraftLocation.toBukkit(bed, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -340,7 +341,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
getHandle().openMenu(((BlockWorkbench) Blocks.CRAFTING_TABLE).getMenuProvider(null, getHandle().level, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ())));
|
||||
getHandle().openMenu(((BlockWorkbench) Blocks.CRAFTING_TABLE).getMenuProvider(null, getHandle().level, CraftLocation.toBlockPosition(location)));
|
||||
if (force) {
|
||||
getHandle().containerMenu.checkReachable = false;
|
||||
}
|
||||
@@ -360,7 +361,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
}
|
||||
|
||||
// If there isn't an enchant table we can force create one, won't be very useful though.
|
||||
BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition pos = CraftLocation.toBlockPosition(location);
|
||||
getHandle().openMenu(((BlockEnchantmentTable) Blocks.ENCHANTING_TABLE).getMenuProvider(null, getHandle().level, pos));
|
||||
|
||||
if (force) {
|
||||
|
||||
@@ -137,6 +137,7 @@ import org.bukkit.craftbukkit.map.RenderData;
|
||||
import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -380,7 +381,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
// Do not directly assign here, from the packethandler we'll assign it.
|
||||
getHandle().connection.send(new PacketPlayOutSpawnPosition(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), loc.getYaw()));
|
||||
getHandle().connection.send(new PacketPlayOutSpawnPosition(CraftLocation.toBlockPosition(loc), loc.getYaw()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -597,7 +598,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
int packetData = effect.getId();
|
||||
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(packetData, new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), data, false);
|
||||
PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(packetData, CraftLocation.toBlockPosition(loc), data, false);
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -626,7 +627,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
public void sendBlockChange(Location loc, Material material, byte data) {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), CraftMagicNumbers.getBlock(material, data));
|
||||
PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(CraftLocation.toBlockPosition(loc), CraftMagicNumbers.getBlock(material, data));
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -634,7 +635,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
public void sendBlockChange(Location loc, BlockData block) {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), ((CraftBlockData) block).getState());
|
||||
PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(CraftLocation.toBlockPosition(loc), ((CraftBlockData) block).getState());
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -699,7 +700,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
stage = -1; // The protocol states that any other value will reset the damage, which this API promises
|
||||
}
|
||||
|
||||
PacketPlayOutBlockBreakAnimation packet = new PacketPlayOutBlockBreakAnimation(sourceId, new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), stage);
|
||||
PacketPlayOutBlockBreakAnimation packet = new PacketPlayOutBlockBreakAnimation(sourceId, CraftLocation.toBlockPosition(loc), stage);
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@@ -730,7 +731,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
|
||||
IChatBaseComponent[] components = CraftSign.sanitizeLines(lines);
|
||||
TileEntitySign sign = new TileEntitySign(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Blocks.OAK_SIGN.defaultBlockState());
|
||||
TileEntitySign sign = new TileEntitySign(CraftLocation.toBlockPosition(loc), Blocks.OAK_SIGN.defaultBlockState());
|
||||
sign.setColor(EnumColor.byId(dyeColor.getWoolData()));
|
||||
sign.setHasGlowingText(hasGlowingText);
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
@@ -1018,7 +1019,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
Optional<Vec3D> spawnLoc = EntityHuman.findRespawnPositionAndUseSpawnBlock(world, bed, getHandle().getRespawnAngle(), getHandle().isRespawnForced(), true);
|
||||
if (spawnLoc.isPresent()) {
|
||||
Vec3D vec = spawnLoc.get();
|
||||
return new Location(world.getWorld(), vec.x, vec.y, vec.z, getHandle().getRespawnAngle(), 0);
|
||||
return CraftLocation.toBukkit(vec, world.getWorld(), getHandle().getRespawnAngle(), 0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -1034,7 +1035,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
if (location == null) {
|
||||
getHandle().setRespawnPosition(null, null, 0.0F, override, false, PlayerSpawnChangeEvent.Cause.PLUGIN);
|
||||
} else {
|
||||
getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), location.getYaw(), override, false, PlayerSpawnChangeEvent.Cause.PLUGIN);
|
||||
getHandle().setRespawnPosition(((CraftWorld) location.getWorld()).getHandle().dimension(), CraftLocation.toBlockPosition(location), location.getYaw(), override, false, PlayerSpawnChangeEvent.Cause.PLUGIN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1043,7 +1044,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
Preconditions.checkState(isSleeping(), "Not sleeping");
|
||||
|
||||
BlockPosition bed = getHandle().getRespawnPosition();
|
||||
return new Location(getWorld(), bed.getX(), bed.getY(), bed.getZ());
|
||||
return CraftLocation.toBukkit(bed, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,11 +34,10 @@ public abstract class CraftRaider extends CraftMonster implements Raider {
|
||||
@Override
|
||||
public void setPatrolTarget(Block block) {
|
||||
if (block == null) {
|
||||
getHandle().setPatrolTarget((BlockPosition) null);
|
||||
getHandle().setPatrolTarget(null);
|
||||
} else {
|
||||
Preconditions.checkArgument(block.getWorld().equals(this.getWorld()), "Block must be in same world");
|
||||
|
||||
getHandle().setPatrolTarget(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
getHandle().setPatrolTarget(((CraftBlock) block).getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Sniffer;
|
||||
|
||||
@@ -33,7 +34,7 @@ public class CraftSniffer extends CraftAnimals implements Sniffer {
|
||||
|
||||
@Override
|
||||
public Collection<Location> getExploredLocations() {
|
||||
return this.getHandle().getExploredPositions().map(blockPosition -> new Location(this.getLocation().getWorld(), blockPosition.getX(), blockPosition.getY(), blockPosition.getZ())).collect(Collectors.toList());
|
||||
return this.getHandle().getExploredPositions().map(blockPosition -> CraftLocation.toBukkit(blockPosition, this.getLocation().getWorld())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,7 +44,7 @@ public class CraftSniffer extends CraftAnimals implements Sniffer {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition blockPosition = CraftLocation.toBlockPosition(location);
|
||||
this.getHandle().getBrain().setMemory(MemoryModuleType.SNIFFER_EXPLORED_POSITIONS, this.getHandle().getExploredPositions().filter(blockPositionExplored -> !blockPositionExplored.equals(blockPosition)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ public class CraftSniffer extends CraftAnimals implements Sniffer {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getHandle().storeExploredPosition(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
this.getHandle().storeExploredPosition(CraftLocation.toBlockPosition(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +71,7 @@ public class CraftSniffer extends CraftAnimals implements Sniffer {
|
||||
|
||||
@Override
|
||||
public Location findPossibleDigLocation() {
|
||||
return this.getHandle().calculateDigPosition().map(blockPosition -> new Location(this.getLocation().getWorld(), blockPosition.getX(), blockPosition.getY(), blockPosition.getZ())).orElse(null);
|
||||
return this.getHandle().calculateDigPosition().map(blockPosition -> CraftLocation.toBukkit(blockPosition, this.getLocation().getWorld())).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.monster.EntityVex;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Vex;
|
||||
|
||||
@@ -42,7 +43,7 @@ public class CraftVex extends CraftMonster implements Vex {
|
||||
@Override
|
||||
public Location getBound() {
|
||||
BlockPosition blockPosition = getHandle().getBoundOrigin();
|
||||
return (blockPosition == null) ? null : new Location(getWorld(), blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||
return (blockPosition == null) ? null : CraftLocation.toBukkit(blockPosition, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,7 +52,7 @@ public class CraftVex extends CraftMonster implements Vex {
|
||||
getHandle().setBoundOrigin(null);
|
||||
} else {
|
||||
Preconditions.checkArgument(getWorld().equals(location.getWorld()), "The bound world cannot be different to the entity's world.");
|
||||
getHandle().setBoundOrigin(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
getHandle().setBoundOrigin(CraftLocation.toBlockPosition(location));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
@@ -100,7 +101,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds");
|
||||
Preconditions.checkState(!getHandle().generation, "Cannot sleep during world generation");
|
||||
|
||||
BlockPosition position = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition position = CraftLocation.toBlockPosition(location);
|
||||
IBlockData iblockdata = getHandle().level.getBlockState(position);
|
||||
if (!(iblockdata.getBlock() instanceof BlockBed)) {
|
||||
return false;
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.bukkit.block.structure.Mirror;
|
||||
import org.bukkit.block.structure.StructureRotation;
|
||||
import org.bukkit.craftbukkit.CraftRegionAccessor;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.util.CraftBlockVector;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.craftbukkit.util.RandomSourceWrapper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
@@ -66,7 +68,7 @@ public class CraftStructure implements Structure {
|
||||
.setRandom(randomSource);
|
||||
definedstructureinfo.palette = palette;
|
||||
|
||||
BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
BlockPosition blockPosition = CraftBlockVector.toBlockPosition(location);
|
||||
structure.placeInWorld(((CraftRegionAccessor) regionAccessor).getHandle(), blockPosition, blockPosition, definedstructureinfo, randomSource, 2);
|
||||
}
|
||||
|
||||
@@ -92,12 +94,12 @@ public class CraftStructure implements Structure {
|
||||
throw new IllegalArgumentException("Size must be at least 1x1x1 but was " + size.getBlockX() + "x" + size.getBlockY() + "x" + size.getBlockZ());
|
||||
}
|
||||
|
||||
structure.fillFromWorld(((CraftWorld) world).getHandle(), new BlockPosition(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ()), new BlockPosition(size.getBlockX(), size.getBlockY(), size.getBlockZ()), includeEntities, Blocks.STRUCTURE_VOID);
|
||||
structure.fillFromWorld(((CraftWorld) world).getHandle(), CraftLocation.toBlockPosition(origin), CraftBlockVector.toBlockPosition(size), includeEntities, Blocks.STRUCTURE_VOID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector getSize() {
|
||||
return new BlockVector(structure.getSize().getX(), structure.getSize().getY(), structure.getSize().getZ());
|
||||
return CraftBlockVector.toBukkit(structure.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.core.BaseBlockPosition;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
public final class CraftBlockVector {
|
||||
|
||||
private CraftBlockVector() {
|
||||
}
|
||||
|
||||
public static BlockPosition toBlockPosition(BlockVector blockVector) {
|
||||
return new BlockPosition(blockVector.getBlockX(), blockVector.getBlockY(), blockVector.getBlockZ());
|
||||
}
|
||||
|
||||
public static BlockVector toBukkit(BaseBlockPosition baseBlockPosition) {
|
||||
return new BlockVector(baseBlockPosition.getX(), baseBlockPosition.getY(), baseBlockPosition.getZ());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.Position;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
public final class CraftLocation {
|
||||
|
||||
private CraftLocation() {
|
||||
}
|
||||
|
||||
public static Location toBukkit(Vec3D vec3D) {
|
||||
return toBukkit(vec3D, null);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Vec3D vec3D, World world) {
|
||||
return toBukkit(vec3D, world, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Vec3D vec3D, World world, float yaw, float pitch) {
|
||||
return new Location(world, vec3D.x(), vec3D.y(), vec3D.z(), yaw, pitch);
|
||||
}
|
||||
|
||||
public static Location toBukkit(BlockPosition blockPosition) {
|
||||
return toBukkit(blockPosition, null);
|
||||
}
|
||||
|
||||
public static Location toBukkit(BlockPosition blockPosition, World world) {
|
||||
return toBukkit(blockPosition, world, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static Location toBukkit(BlockPosition blockPosition, World world, float yaw, float pitch) {
|
||||
return new Location(world, blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), yaw, pitch);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Position position) {
|
||||
return toBukkit(position, null, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Position position, World world) {
|
||||
return toBukkit(position, world, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static Location toBukkit(Position position, World world, float yaw, float pitch) {
|
||||
return new Location(world, position.x(), position.y(), position.z(), yaw, pitch);
|
||||
}
|
||||
|
||||
public static BlockPosition toBlockPosition(Location location) {
|
||||
return new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
public static Position toPosition(Location location) {
|
||||
return new Position(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static Vec3D toVec3D(Location location) {
|
||||
return new Vec3D(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user