mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
implement entities in paste -e
This commit is contained in:
@ -1,13 +1,23 @@
|
||||
package com.boydti.fawe.beta.implementation;
|
||||
|
||||
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.ListTag;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public interface IChunkExtent<T extends IChunk> extends Extent {
|
||||
@ -91,4 +101,21 @@ 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);
|
||||
CompoundTag tag = entity.getNbtData();
|
||||
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
|
||||
map.put("Id", new StringTag(entity.getType().getName()));
|
||||
ListTag pos = (ListTag) map.get("Pos");
|
||||
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));
|
||||
}
|
||||
chunk.setEntity(tag);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,21 @@ public class ReflectionUtils {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass();
|
||||
|
||||
public static <T, V> Map<T, V> getMap(Map<T, V> map) {
|
||||
try {
|
||||
Class<? extends Map> clazz = map.getClass();
|
||||
if (clazz != UNMODIFIABLE_MAP) return map;
|
||||
Field m = clazz.getDeclaredField("m");
|
||||
m.setAccessible(true);
|
||||
return (Map<T, V>) m.get(map);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getHandle(Object wrapper) {
|
||||
final Method getHandle = makeMethod(wrapper.getClass(), "getHandle");
|
||||
return callMethod(getHandle, wrapper);
|
||||
|
Reference in New Issue
Block a user