fix entity undo

This commit is contained in:
wea_ondara 2020-07-26 15:52:51 +02:00
parent 05ef46994e
commit 50971ee311
8 changed files with 65 additions and 50 deletions

View File

@ -269,7 +269,6 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
private void removeEntity(Entity entity) { private void removeEntity(Entity entity) {
entity.die(); entity.die();
entity.valid = false;
} }
public Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) { public Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) {
@ -449,17 +448,12 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
if (type != null) { if (type != null) {
Entity entity = type.a(nmsWorld); Entity entity = type.a(nmsWorld);
if (entity != null) { if (entity != null) {
UUID uuid = entity.getUniqueID(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
if (nativeTag != null) { tag.remove(name);
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.f(tag);
entity.setLocation(x, y, z, yaw, pitch); entity.setLocation(x, y, z, yaw, pitch);
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
} }

View File

@ -277,7 +277,6 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
private void removeEntity(Entity entity) { private void removeEntity(Entity entity) {
entity.die(); entity.die();
entity.valid = false;
} }
public Chunk ensureLoaded(net.minecraft.server.v1_15_R1.World nmsWorld, int X, int Z) { 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) { if (type != null) {
Entity entity = type.a(nmsWorld); Entity entity = type.a(nmsWorld);
if (entity != null) { if (entity != null) {
UUID uuid = entity.getUniqueID(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
if (nativeTag != null) { tag.remove(name);
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.f(tag);
entity.setLocation(x, y, z, yaw, pitch); entity.setLocation(x, y, z, yaw, pitch);
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
} }

View File

@ -245,7 +245,6 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
private void removeEntity(Entity entity) { private void removeEntity(Entity entity) {
entity.die(); entity.die();
entity.valid = false;
} }
public Chunk ensureLoaded(net.minecraft.server.v1_16_R1.World nmsWorld, int X, int Z) { public Chunk ensureLoaded(net.minecraft.server.v1_16_R1.World nmsWorld, int X, int Z) {
@ -438,17 +437,12 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
if (type != null) { if (type != null) {
Entity entity = type.a(nmsWorld); Entity entity = type.a(nmsWorld);
if (entity != null) { if (entity != null) {
UUID uuid = entity.getUniqueID(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); final NBTTagCompound tag = (NBTTagCompound) adapter.fromNative(nativeTag);
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
if (nativeTag != null) { tag.remove(name);
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);
} }
entity.load(tag);
entity.setLocation(x, y, z, yaw, pitch); entity.setLocation(x, y, z, yaw, pitch);
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
} }

View File

@ -4,7 +4,10 @@ import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.IntArrayTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -16,8 +19,10 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.jetbrains.annotations.Range; import org.jetbrains.annotations.Range;
public interface IChunkExtent<T extends IChunk> extends Extent { public interface IChunkExtent<T extends IChunk> extends Extent {
@ -108,14 +113,47 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
CompoundTag tag = entity.getNbtData(); CompoundTag tag = entity.getNbtData();
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue()); Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
map.put("Id", new StringTag(entity.getType().getName())); map.put("Id", new StringTag(entity.getType().getName()));
//Set pos
ListTag pos = (ListTag) map.get("Pos"); ListTag pos = (ListTag) map.get("Pos");
List<Tag> posList;
if (pos != null) { if (pos != null) {
List<Tag> posList = ReflectionUtils.getList(pos.getValue()); posList = ReflectionUtils.getList(pos.getValue());
posList.set(0, new DoubleTag(location.getX() + 0.5)); } else {
posList.set(1, new DoubleTag(location.getY())); posList = new ArrayList<>();
posList.set(2, new DoubleTag(location.getZ() + 0.5)); pos = new ListTag(DoubleTag.class, posList);
map.put("Pos", pos);
} }
posList.set(0, new DoubleTag(location.getX() + 0.5));
posList.set(1, new DoubleTag(location.getY()));
posList.set(2, new DoubleTag(location.getZ() + 0.5));
//set new uuid
UUID newuuid = UUID.randomUUID();
IntArrayTag uuid = (IntArrayTag) map.get("UUID");
int[] uuidArray;
if (uuid != null) {
uuidArray = uuid.getValue();
} else {
uuidArray = new int[4];
uuid = new IntArrayTag(uuidArray);
map.put("UUID", uuid);
}
uuidArray[0] = (int) (newuuid.getMostSignificantBits() >> 32);
uuidArray[1] = (int) newuuid.getMostSignificantBits();
uuidArray[2] = (int) (newuuid.getLeastSignificantBits() >> 32);
uuidArray[3] = (int) newuuid.getLeastSignificantBits();
map.put("UUIDMost", new LongTag(newuuid.getMostSignificantBits()));
map.put("UUIDLeast", new LongTag(newuuid.getLeastSignificantBits()));
chunk.setEntity(tag); chunk.setEntity(tag);
return null; return null;
} }
@Override
default void removeEntity(int x, int y, int z, UUID uuid) {
final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4);
chunk.removeEntity(uuid);
}
} }

View File

@ -1,16 +1,9 @@
package com.boydti.fawe.object.change; package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.Change;
import java.util.Map;
public class MutableTileChange implements Change { public class MutableTileChange implements Change {

View File

@ -46,6 +46,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jetbrains.annotations.Range; import org.jetbrains.annotations.Range;
@ -155,6 +156,11 @@ public class AbstractDelegateExtent implements Extent {
return extent.createEntity(location, entity); return extent.createEntity(location, entity);
} }
@Override
public void removeEntity(int x, int y, int z, UUID uuid) {
extent.removeEntity(x, y, z, uuid);
}
@Override @Override
public List<? extends Entity> getEntities() { public List<? extends Entity> getEntities() {
return extent.getEntities(); return extent.getEntities();

View File

@ -36,11 +36,6 @@ public class PassthroughExtent extends AbstractDelegateExtent {
super(extent); super(extent);
} }
@Override
public void removeEntity(int x, int y, int z, UUID uuid) {
getExtent().removeEntity(x, y, z, uuid);
}
@Override @Override
public boolean regenerateChunk(int x, int z, @Nullable BiomeType type, @Nullable Long seed) { public boolean regenerateChunk(int x, int z, @Nullable BiomeType type, @Nullable Long seed) {
return getExtent().regenerateChunk(x, z, type, seed); return getExtent().regenerateChunk(x, z, type, seed);

View File

@ -36,7 +36,7 @@ public final class Constants {
static { static {
NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList( NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList(
"UUIDLeast", "UUIDMost", // Bukkit and Vanilla // "UUIDLeast", "UUIDMost", // Bukkit and Vanilla
"WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla "WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla
"PersistentIDMSB", "PersistentIDLSB" // Forge "PersistentIDMSB", "PersistentIDLSB" // Forge
)); ));