mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Add support for copying entities between Extents.
This commit is contained in:
@ -23,7 +23,10 @@ import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.entity.EntityHanging;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@ -40,17 +43,42 @@ class ForgeEntity implements Entity {
|
||||
|
||||
@Override
|
||||
public BaseEntity getState() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
entity.writeToNBT(tag);
|
||||
return new BaseEntity(EntityList.getEntityString(entity), NBTConverter.fromNative(tag));
|
||||
String id = EntityList.getEntityString(entity);
|
||||
if (id != null) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
entity.writeToNBT(tag);
|
||||
return new BaseEntity(id, NBTConverter.fromNative(tag));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(
|
||||
ForgeAdapter.adapt(entity.worldObj),
|
||||
new Vector(entity.posX, entity.posY, entity.posZ),
|
||||
ForgeAdapter.adapt(entity.getLookVec()));
|
||||
Vector position;
|
||||
float pitch;
|
||||
float yaw;
|
||||
|
||||
if (entity instanceof EntityHanging) {
|
||||
EntityHanging hanging = (EntityHanging) entity;
|
||||
|
||||
position = new Vector(hanging.xPosition, hanging.yPosition, hanging.zPosition);
|
||||
|
||||
Direction direction = MCDirections.fromHanging(hanging.hangingDirection);
|
||||
if (direction != null) {
|
||||
yaw = direction.toVector().toYaw();
|
||||
pitch = direction.toVector().toPitch();
|
||||
} else {
|
||||
yaw = (float) Math.toRadians(entity.rotationYaw);
|
||||
pitch = (float) Math.toRadians(entity.rotationPitch);
|
||||
}
|
||||
} else {
|
||||
position = new Vector(entity.posX, entity.posY, entity.posZ);
|
||||
yaw = (float) Math.toRadians(entity.rotationYaw);
|
||||
pitch = (float) Math.toRadians(entity.rotationPitch);
|
||||
}
|
||||
|
||||
return new Location(ForgeAdapter.adapt(entity.worldObj), position, yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,10 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.LazyBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Direction.Flag;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
@ -500,7 +503,29 @@ public class ForgeWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getEntities() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
World world = getWorld();
|
||||
for (Vector2D pt : region.getChunks()) {
|
||||
if (!world.getChunkProvider().chunkExists(pt.getBlockX(), pt.getBlockZ())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Chunk chunk = world.getChunkProvider().provideChunk(pt.getBlockX(), pt.getBlockZ());
|
||||
for (List<net.minecraft.entity.Entity> entitySubList : chunk.entityLists) {
|
||||
for (net.minecraft.entity.Entity entity : entitySubList) {
|
||||
if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) {
|
||||
entities.add(new ForgeEntity(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities() {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
for (Object entity : getWorld().getLoadedEntityList()) {
|
||||
entities.add(new ForgeEntity((net.minecraft.entity.Entity) entity));
|
||||
@ -518,6 +543,19 @@ public class ForgeWorld extends AbstractWorld {
|
||||
if (tag != null) {
|
||||
createdEntity.readFromNBT(NBTConverter.toNative(entity.getNbtData()));
|
||||
}
|
||||
|
||||
createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), (float) Math.toDegrees(location.getYaw()), (float) Math.toDegrees(location.getPitch()));
|
||||
|
||||
// Special handling for hanging entities
|
||||
if (createdEntity instanceof EntityHanging) {
|
||||
EntityHanging hanging = (EntityHanging) createdEntity;
|
||||
hanging.xPosition = location.getBlockX();
|
||||
hanging.yPosition = location.getBlockY();
|
||||
hanging.zPosition = location.getBlockZ();
|
||||
Direction direction = Direction.findClosest(location.getDirection(), Flag.CARDINAL);
|
||||
hanging.setDirection(MCDirections.toHanging(direction));
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(createdEntity);
|
||||
return new ForgeEntity(createdEntity);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user