Re-implement full Entity support in history, entity removal, entity creation, etc. (#1812)

Co-authored-by: Alexander Brandes <mc.cache@web.de>
This commit is contained in:
Jordan
2022-06-21 14:52:02 +01:00
committed by GitHub
parent d62c88a2ca
commit 968799503f
43 changed files with 556 additions and 336 deletions

View File

@ -3699,6 +3699,15 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
}
}
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
try {
return this.getExtent().createEntity(location, entity, uuid);
} catch (WorldEditException e) {
throw new RuntimeException("Unexpected exception", e);
}
}
@Override
public void removeEntity(int x, int y, int z, UUID uuid) {
try {

View File

@ -141,6 +141,14 @@ public class AbstractDelegateExtent implements Extent {
return extent.createEntity(location, entity);
}
//FAWE start
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
return extent.createEntity(location, entity, uuid);
}
//FAWE end
@Override
@Nullable
public Operation commit() {

View File

@ -37,6 +37,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkNotNull;
@ -78,11 +79,23 @@ public class ChangeSetExtent extends AbstractDelegateExtent {
public Entity createEntity(Location location, BaseEntity state) {
Entity entity = super.createEntity(location, state);
if (entity != null) {
changeSet.add(new EntityCreate(location, state, entity));
changeSet.add(new EntityCreate(location, entity.getState(), entity));
}
return entity;
}
//FAWE start
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity state, UUID uuid) {
Entity entity = super.createEntity(location, state, uuid);
if (entity != null) {
changeSet.add(new EntityCreate(location, entity.getState(), entity));
}
return entity;
}
//FAWE end
@Override
public List<? extends Entity> getEntities() {
return wrapEntities(super.getEntities());

View File

@ -148,6 +148,21 @@ public interface Extent extends InputExtent, OutputExtent {
}
//FAWE start
/**
* Create an entity at the given location, forcing a UUID onto the entity
*
* Only use if you are aware of the consequences of forcing a UUID to an entity.
*
* @param entity the entity
* @param location the location
* @param uuid UUID to force the entity to have
* @return a reference to the created entity, or null if the entity could not be created
* @since TODO
*/
@Nullable
default Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
return null;
}
/**
* Create an entity at the given location.

View File

@ -38,6 +38,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
/**
* An extent that returns air blocks for all blocks and does not
@ -73,6 +74,14 @@ public class NullExtent implements Extent {
return null;
}
//FAWE start
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
return null;
}
//FAWE end
@Override
public BlockState getBlock(BlockVector3 position) {
return BlockTypes.AIR.getDefaultState();

View File

@ -34,6 +34,7 @@ import javax.annotation.Nullable;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import java.util.UUID;
/**
* An extent that can report back if an operation fails due to the extent(s) below it.
@ -106,6 +107,20 @@ public class TracingExtent extends AbstractDelegateExtent {
return result;
}
//FAWE start
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
BlockVector3 blockVector3 = location.toVector().toBlockPoint();
touchedLocations.add(blockVector3);
Entity result = super.createEntity(location, entity, uuid);
if (result == null) {
failedActions.put(blockVector3, Action.CREATE_ENTITY);
}
return result;
}
//FAWE end
@Override
public String toString() {
return "TracingExtent{delegate=" + getExtent() + "}";

View File

@ -304,6 +304,18 @@ public class BlockArrayClipboard implements Clipboard {
return getParent().createEntity(l, entity);
}
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
Location l = new Location(location.getExtent(),
location.getX() - offset.getBlockX(),
location.getY() - offset.getBlockY(),
location.getZ() - offset.getBlockZ(),
location.getYaw(), location.getPitch()
);
return getParent().createEntity(l, entity, uuid);
}
@Override
public void removeEntity(int x, int y, int z, UUID uuid) {
x -= offset.getX();

View File

@ -31,6 +31,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.UUID;
/**
* Extent that ticks the watchdog before every world-affecting action.
@ -86,6 +87,15 @@ public class WatchdogTickingExtent extends AbstractDelegateExtent {
return super.createEntity(location, entity);
}
//FAWE start
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
onOperation();
return super.createEntity(location, entity, uuid);
}
//FAWE end
@Override
public boolean setBiome(BlockVector3 position, BiomeType biome) {
onOperation();

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.function.entity;
import com.fastasyncworldedit.core.util.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.jnbt.FloatTag;
@ -165,6 +166,8 @@ public class ExtentEntityCopy implements EntityFunction {
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("WorldUUIDMost")) {
uuid = new UUID(tag.getLong("WorldUUIDMost"), tag.getLong("WorldUUIDLeast"));
} else if (tag.containsKey("PersistentIDMSB")) {
uuid = new UUID(tag.getLong("PersistentIDMSB"), tag.getLong("PersistentIDLSB"));
}
@ -177,8 +180,8 @@ public class ExtentEntityCopy implements EntityFunction {
uuid
);
} else {
TaskManager.taskManager().sync(entity::remove);
//FAWE end
entity.remove();
}
}
}

View File

@ -36,6 +36,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID;
public class RequestExtent implements Extent {
@ -75,6 +76,14 @@ public class RequestExtent implements Extent {
return getExtent().createEntity(location, entity);
}
//FAWE start
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
return getExtent().createEntity(location, entity, uuid);
}
//FAWE end
@Override
public BlockState getBlock(BlockVector3 position) {
return getExtent().getBlock(position);

View File

@ -52,6 +52,7 @@ import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* A null implementation of {@link World} that drops all changes and
@ -229,6 +230,14 @@ public class NullWorld extends AbstractWorld {
return null;
}
//FAWE start
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
return null;
}
//FAWE end
/**
* Return an instance of this null world.
*