mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Merge pull request #518 from aurorasmiles/fixEntities
start reimplementing entities
This commit is contained in:
commit
1e070b3a71
@ -289,7 +289,6 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
|
||||
private void removeEntity(Entity entity) {
|
||||
entity.die();
|
||||
entity.valid = false;
|
||||
}
|
||||
|
||||
public Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int chunkX,
|
||||
@ -483,21 +482,12 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
if (type != null) {
|
||||
Entity entity = type.a(nmsWorld);
|
||||
if (entity != null) {
|
||||
UUID uuid = entity.getUniqueID();
|
||||
entityTagMap.put("UUIDMost",
|
||||
new LongTag(uuid.getMostSignificantBits()));
|
||||
entityTagMap.put("UUIDLeast",
|
||||
new LongTag(uuid.getLeastSignificantBits()));
|
||||
if (nativeTag != null) {
|
||||
BukkitImplAdapter adapter =
|
||||
WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
final NBTTagCompound tag =
|
||||
(NBTTagCompound) adapter.fromNative(nativeTag);
|
||||
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
entity.f(tag);
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
|
||||
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
entity.f(tag);
|
||||
entity.setLocation(x, y, z, yaw, pitch);
|
||||
nmsWorld
|
||||
.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
@ -277,7 +277,6 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
|
||||
|
||||
private void removeEntity(Entity entity) {
|
||||
entity.die();
|
||||
entity.valid = false;
|
||||
}
|
||||
|
||||
public Chunk ensureLoaded(net.minecraft.server.v1_15_R1.World nmsWorld, int X, int Z) {
|
||||
@ -467,17 +466,13 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
|
||||
if (type != null) {
|
||||
Entity entity = type.a(nmsWorld);
|
||||
if (entity != null) {
|
||||
UUID uuid = entity.getUniqueID();
|
||||
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
|
||||
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
|
||||
if (nativeTag != null) {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
|
||||
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
entity.f(tag);
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
|
||||
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
|
||||
entity.f(tag);
|
||||
entity.setLocation(x, y, z, yaw, pitch);
|
||||
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
}
|
||||
|
@ -243,7 +243,6 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
|
||||
|
||||
private void removeEntity(Entity entity) {
|
||||
entity.die();
|
||||
entity.valid = false;
|
||||
}
|
||||
|
||||
public Chunk ensureLoaded(net.minecraft.server.v1_16_R1.World nmsWorld, int X, int Z) {
|
||||
@ -436,17 +435,12 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
|
||||
if (type != null) {
|
||||
Entity entity = type.a(nmsWorld);
|
||||
if (entity != null) {
|
||||
UUID uuid = entity.getUniqueID();
|
||||
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
|
||||
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
|
||||
if (nativeTag != null) {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
|
||||
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
entity.save(tag);
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
|
||||
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
entity.load(tag);
|
||||
entity.setLocation(x, y, z, yaw, pitch);
|
||||
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class BukkitEntity implements Entity {
|
||||
|
||||
@Override
|
||||
public com.sk89q.worldedit.world.entity.EntityType getType() {
|
||||
return EntityTypes.get(type.getName().toUpperCase(Locale.ROOT));
|
||||
return EntityTypes.get(type.getName().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,31 +143,8 @@ public class BukkitWorld extends AbstractWorld {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
try {
|
||||
Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity);
|
||||
if (createdEntity != null) {
|
||||
return new BukkitEntity(createdEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Corrupt entity found when creating: " + entity.getType().getId());
|
||||
if (entity.getNbtData() != null) {
|
||||
logger.warn(entity.getNbtData().toString());
|
||||
}
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//createEntity was moved to IChunkExtent to prevent issues with Async Entitiy Add.
|
||||
|
||||
/**
|
||||
* Get the world handle.
|
||||
*
|
||||
|
@ -78,6 +78,7 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
|
||||
public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
|
||||
private final Spigot_v1_14_R4 parent;
|
||||
@ -235,7 +236,11 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
Supplier<CompoundTag> saveTag = () -> {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
readEntityIntoTag(mcEntity, tag);
|
||||
return (CompoundTag) toNative(tag);
|
||||
|
||||
//add Id for AbstractChangeSet to work
|
||||
CompoundTag natve = (CompoundTag) toNative(tag);
|
||||
natve.getValue().put("Id", new StringTag(id));
|
||||
return natve;
|
||||
};
|
||||
return new LazyBaseEntity(type, saveTag);
|
||||
} else {
|
||||
|
@ -48,7 +48,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
@ -82,6 +81,7 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
|
||||
public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
|
||||
private final Spigot_v1_15_R2 parent;
|
||||
@ -245,7 +245,11 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I
|
||||
Supplier<CompoundTag> saveTag = () -> {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
readEntityIntoTag(mcEntity, tag);
|
||||
return (CompoundTag) toNative(tag);
|
||||
|
||||
//add Id for AbstractChangeSet to work
|
||||
CompoundTag natve = (CompoundTag) toNative(tag);
|
||||
natve.getValue().put("Id", new StringTag(id));
|
||||
return natve;
|
||||
};
|
||||
return new LazyBaseEntity(type, saveTag);
|
||||
} else {
|
||||
|
@ -22,17 +22,12 @@ package com.sk89q.worldedit.bukkit.adapter.impl;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IChunkGet;
|
||||
import com.boydti.fawe.beta.IQueueChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.*;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -42,7 +37,6 @@ import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.LazyBaseEntity;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
@ -55,7 +49,6 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import net.minecraft.server.v1_16_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
@ -65,22 +58,17 @@ import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
|
||||
public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
|
||||
private final Spigot_v1_16_R1 parent;
|
||||
@ -244,7 +232,11 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I
|
||||
Supplier<CompoundTag> saveTag = () -> {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
readEntityIntoTag(mcEntity, tag);
|
||||
return (CompoundTag) toNative(tag);
|
||||
|
||||
//add Id for AbstractChangeSet to work
|
||||
CompoundTag natve = (CompoundTag) toNative(tag);
|
||||
natve.getValue().put("Id", new StringTag(id));
|
||||
return natve;
|
||||
};
|
||||
return new LazyBaseEntity(type, saveTag);
|
||||
} else {
|
||||
|
@ -2,12 +2,26 @@ package com.boydti.fawe.beta.implementation;
|
||||
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.IntArrayTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.LongTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
@ -91,4 +105,88 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4);
|
||||
return chunk.getOpacity(x & 15, y, z & 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Entity createEntity(Location location, BaseEntity entity) {
|
||||
final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
Map<String, Tag> map = new HashMap<>(entity.getNbtData().getValue()); //do not modify original entity data
|
||||
map.put("Id", new StringTag(entity.getType().getName()));
|
||||
|
||||
//Set pos
|
||||
List<DoubleTag> posList = new ArrayList<>();
|
||||
posList.add(new DoubleTag(location.getX()));
|
||||
posList.add(new DoubleTag(location.getY()));
|
||||
posList.add(new DoubleTag(location.getZ()));
|
||||
map.put("Pos", new ListTag(DoubleTag.class, posList));
|
||||
|
||||
//set new uuid
|
||||
UUID newuuid = UUID.randomUUID();
|
||||
int[] uuidArray = new int[4];
|
||||
uuidArray[0] = (int) (newuuid.getMostSignificantBits() >> 32);
|
||||
uuidArray[1] = (int) newuuid.getMostSignificantBits();
|
||||
uuidArray[2] = (int) (newuuid.getLeastSignificantBits() >> 32);
|
||||
uuidArray[3] = (int) newuuid.getLeastSignificantBits();
|
||||
map.put("UUID", new IntArrayTag(uuidArray));
|
||||
|
||||
map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits()));
|
||||
map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits()));
|
||||
|
||||
map.put("PersistentIDMSB", new LongTag(newuuid.getMostSignificantBits()));
|
||||
map.put("PersistentIDLSB", new LongTag(newuuid.getLeastSignificantBits()));
|
||||
|
||||
chunk.setEntity(new CompoundTag(map));
|
||||
return new IChunkEntity(this, location, newuuid, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void removeEntity(int x, int y, int z, UUID uuid) {
|
||||
final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4);
|
||||
chunk.removeEntity(uuid);
|
||||
}
|
||||
|
||||
class IChunkEntity implements Entity {
|
||||
|
||||
private final Extent extent;
|
||||
private final Location location;
|
||||
private final UUID uuid;
|
||||
private final BaseEntity base;
|
||||
|
||||
public IChunkEntity(Extent extent, Location location, UUID uuid, BaseEntity base) {
|
||||
this.extent = extent;
|
||||
this.location = location;
|
||||
this.uuid = uuid;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseEntity getState() {
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
extent.removeEntity(location.getBlockX(), location.getBlockY(), location.getBlockZ(), uuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getFacet(Class<? extends T> cls) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setLocation(Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,12 +78,12 @@ public class MutableEntityChange implements Change {
|
||||
return;
|
||||
}
|
||||
List<DoubleTag> pos = (List<DoubleTag>) posTag.getValue();
|
||||
int x = MathMan.roundInt(pos.get(0).getValue());
|
||||
int y = MathMan.roundInt(pos.get(1).getValue());
|
||||
int z = MathMan.roundInt(pos.get(2).getValue());
|
||||
double x = pos.get(0).getValue();
|
||||
double y = pos.get(1).getValue();
|
||||
double z = pos.get(2).getValue();
|
||||
Extent extent = context.getExtent();
|
||||
Location location = new Location(extent, x, y, z, 0, 0);
|
||||
String id = tag.getString("id");
|
||||
String id = tag.getString("Id");
|
||||
EntityType type = EntityTypes.parse(id);
|
||||
BaseEntity entity = new BaseEntity(type, tag);
|
||||
context.getExtent().createEntity(location, entity);
|
||||
|
@ -43,6 +43,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@ -437,6 +438,11 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable
|
||||
public List<? extends Entity> getEntities() {
|
||||
return new ArrayList<>(entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
return new ArrayList<>(entities.stream().filter(e -> region.contains(e.getLocation().toBlockPoint())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(Entity entity) {
|
||||
|
@ -27,6 +27,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MemoryOptimizedClipboard extends LinearClipboard {
|
||||
@ -292,11 +293,15 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
|
||||
return new ArrayList<>(entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
return new ArrayList<>(entities.stream().filter(e -> region.contains(e.getLocation().toBlockPoint())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(Entity entity) {
|
||||
if (entity instanceof ClipboardEntity) {
|
||||
this.entities.remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ import com.boydti.fawe.util.ExtentTraverser;
|
||||
import com.boydti.fawe.util.MaskTraverser;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
@ -112,6 +114,7 @@ import com.sk89q.worldedit.regions.shape.RegionShape;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||
@ -147,6 +150,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
|
||||
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
|
||||
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* An {@link Extent} that handles history, {@link BlockBag}s, change limits,
|
||||
@ -3084,4 +3088,32 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities() {
|
||||
return world.getEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
return world.getEntities(region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
try {
|
||||
return this.getExtent().createEntity(location, entity);
|
||||
} catch (WorldEditException e) {
|
||||
throw new RuntimeException("Unexpected exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int x, int y, int z, UUID uuid) {
|
||||
try {
|
||||
this.getExtent().removeEntity(x, y, z, uuid);
|
||||
} catch (WorldEditException e) {
|
||||
throw new RuntimeException("Unexpected exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,15 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -153,6 +157,11 @@ public class AbstractDelegateExtent implements Extent {
|
||||
return extent.createEntity(location, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int x, int y, int z, UUID uuid) {
|
||||
extent.removeEntity(x, y, z, uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities() {
|
||||
return extent.getEntities();
|
||||
|
@ -37,11 +37,6 @@ public class PassthroughExtent extends AbstractDelegateExtent {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(int x, int y, int z, UUID uuid) {
|
||||
getExtent().removeEntity(x, y, z, uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerateChunk(int x, int z, @Nullable BiomeType type, @Nullable Long seed) {
|
||||
return getExtent().regenerateChunk(x, z, type, seed);
|
||||
|
@ -45,6 +45,7 @@ import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Stores block data as a multi-dimensional array of {@link BlockState}s and
|
||||
@ -197,13 +198,49 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
region = region.clone();
|
||||
region.shift(BlockVector3.ZERO.subtract(origin));
|
||||
return getParent().getEntities(region);
|
||||
return getParent().getEntities(region).stream().map(e ->
|
||||
{
|
||||
if (e instanceof ClipboardEntity) {
|
||||
ClipboardEntity ce = (ClipboardEntity) e;
|
||||
Location oldloc = ce.getLocation();
|
||||
Location loc = new Location(oldloc.getExtent(),
|
||||
oldloc.getX() + origin.getBlockX(),
|
||||
oldloc.getY() + origin.getBlockY(),
|
||||
oldloc.getZ() + origin.getBlockZ(),
|
||||
oldloc.getYaw(), oldloc.getPitch());
|
||||
return new ClipboardEntity(loc, ce.entity);
|
||||
}
|
||||
return e;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities() {
|
||||
return getParent().getEntities().stream().map(e ->
|
||||
{
|
||||
if (e instanceof ClipboardEntity) {
|
||||
ClipboardEntity ce = (ClipboardEntity) e;
|
||||
Location oldloc = ce.getLocation();
|
||||
Location loc = new Location(oldloc.getExtent(),
|
||||
oldloc.getX() + origin.getBlockX(),
|
||||
oldloc.getY() + origin.getBlockY(),
|
||||
oldloc.getZ() + origin.getBlockZ(),
|
||||
oldloc.getYaw(), oldloc.getPitch());
|
||||
return new ClipboardEntity(loc, ce.entity);
|
||||
}
|
||||
return e;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
return getParent().createEntity(location, entity);
|
||||
Location l = new Location(location.getExtent(),
|
||||
location.getX() - origin.getBlockX(),
|
||||
location.getY() - origin.getBlockY(),
|
||||
location.getZ() - origin.getBlockZ(),
|
||||
location.getYaw(), location.getPitch());
|
||||
return getParent().createEntity(l, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -286,7 +323,7 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
private final float yaw, pitch;
|
||||
|
||||
public ClipboardEntity(Location loc, BaseEntity entity) {
|
||||
this((Clipboard) loc.getExtent(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getYaw(), loc.getPitch(), entity);
|
||||
this((Clipboard) loc.getExtent(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), entity);
|
||||
}
|
||||
|
||||
public ClipboardEntity(Clipboard clipboard, double x, double y, double z, float yaw, float pitch, BaseEntity entity) {
|
||||
|
@ -37,6 +37,7 @@ import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Copies entities provided to the function to the provided destination
|
||||
@ -44,6 +45,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class ExtentEntityCopy implements EntityFunction {
|
||||
|
||||
private final Extent source;
|
||||
private final Extent destination;
|
||||
private final Vector3 from;
|
||||
private final Vector3 to;
|
||||
@ -58,11 +60,35 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
* @param to the destination position
|
||||
* @param transform the transformation to apply to both position and orientation
|
||||
*/
|
||||
@Deprecated
|
||||
public ExtentEntityCopy(Vector3 from, Extent destination, Vector3 to, Transform transform) {
|
||||
checkNotNull(from);
|
||||
checkNotNull(destination);
|
||||
checkNotNull(to);
|
||||
checkNotNull(transform);
|
||||
this.source = null;
|
||||
this.destination = destination;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param source the source {@code Extent}
|
||||
* @param from the from position
|
||||
* @param destination the destination {@code Extent}
|
||||
* @param to the destination position
|
||||
* @param transform the transformation to apply to both position and orientation
|
||||
*/
|
||||
public ExtentEntityCopy(Extent source, Vector3 from, Extent destination, Vector3 to, Transform transform) {
|
||||
checkNotNull(source);
|
||||
checkNotNull(from);
|
||||
checkNotNull(destination);
|
||||
checkNotNull(to);
|
||||
checkNotNull(transform);
|
||||
this.source = source;
|
||||
this.destination = destination;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
@ -119,7 +145,22 @@ public class ExtentEntityCopy implements EntityFunction {
|
||||
|
||||
// Remove
|
||||
if (isRemoving() && success) {
|
||||
entity.remove();
|
||||
UUID uuid = null;
|
||||
if (tag.containsKey("UUID")) {
|
||||
int[] arr = tag.getIntArray("UUID");
|
||||
uuid = new UUID((long)arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long)arr[2] << 32 | (arr[3] & 0xFFFFFFFFL));
|
||||
} else if (tag.containsKey("UUIDMost")) {
|
||||
uuid = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast"));
|
||||
} else if (tag.containsKey("PersistentIDMSB")) {
|
||||
uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB"));
|
||||
}
|
||||
if (uuid != null) {
|
||||
if (source != null) {
|
||||
source.removeEntity(entity.getLocation().getBlockX(), entity.getLocation().getBlockY(), entity.getLocation().getBlockZ(), uuid);
|
||||
} else {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
|
@ -393,7 +393,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
Operations.completeBlindly(blockCopy);
|
||||
|
||||
if (!entities.isEmpty()) {
|
||||
ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform);
|
||||
ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform);
|
||||
entityCopy.setRemoving(removingEntities);
|
||||
List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region));
|
||||
entities2.removeIf(entity -> {
|
||||
@ -402,6 +402,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
});
|
||||
EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
|
||||
Operations.completeBlindly(entityVisitor);
|
||||
affectedEntities += entityVisitor.getAffected();
|
||||
}
|
||||
|
||||
if (transExt != null) {
|
||||
|
@ -36,9 +36,9 @@ public final class Constants {
|
||||
|
||||
static {
|
||||
NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList(
|
||||
"UUIDLeast", "UUIDMost", // Bukkit and Vanilla
|
||||
"WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla
|
||||
"PersistentIDMSB", "PersistentIDLSB" // Forge
|
||||
//"UUIDLeast", "UUIDMost", // Bukkit and Vanilla //UUID values need to be set manully to a new UUID
|
||||
"WorldUUIDLeast", "WorldUUIDMost" // Bukkit and Vanilla
|
||||
//"PersistentIDMSB", "PersistentIDLSB" // Forge //UUID values need to be set manully to a new UUID
|
||||
));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user