mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-16 17:16:11 +00:00
fix entity undo
This commit is contained in:
parent
05ef46994e
commit
50971ee311
@ -269,7 +269,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 X, int Z) {
|
||||
@ -449,17 +448,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);
|
||||
}
|
||||
|
@ -245,7 +245,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) {
|
||||
@ -438,17 +437,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);
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.IntArrayTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
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;
|
||||
@ -16,8 +19,10 @@ 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.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
@ -108,14 +113,47 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
CompoundTag tag = entity.getNbtData();
|
||||
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
|
||||
map.put("Id", new StringTag(entity.getType().getName()));
|
||||
|
||||
//Set pos
|
||||
ListTag pos = (ListTag) map.get("Pos");
|
||||
List<Tag> posList;
|
||||
if (pos != null) {
|
||||
List<Tag> posList = ReflectionUtils.getList(pos.getValue());
|
||||
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));
|
||||
posList = ReflectionUtils.getList(pos.getValue());
|
||||
} else {
|
||||
posList = new ArrayList<>();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,9 @@
|
||||
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.IntTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.history.UndoContext;
|
||||
import com.sk89q.worldedit.history.change.Change;
|
||||
import java.util.Map;
|
||||
|
||||
public class MutableTileChange implements Change {
|
||||
|
||||
|
@ -46,6 +46,7 @@ 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;
|
||||
@ -155,6 +156,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();
|
||||
|
@ -36,11 +36,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);
|
||||
|
@ -36,7 +36,7 @@ public final class Constants {
|
||||
|
||||
static {
|
||||
NO_COPY_ENTITY_NBT_FIELDS = Collections.unmodifiableList(Arrays.asList(
|
||||
"UUIDLeast", "UUIDMost", // Bukkit and Vanilla
|
||||
// "UUIDLeast", "UUIDMost", // Bukkit and Vanilla
|
||||
"WorldUUIDLeast", "WorldUUIDMost", // Bukkit and Vanilla
|
||||
"PersistentIDMSB", "PersistentIDLSB" // Forge
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user