mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Changed Location to use Extents rather than worlds and overhauled the new Entity code a bit.
This commit is contained in:
39
src/forge/java/com/sk89q/worldedit/forge/ForgeAdapter.java
Normal file
39
src/forge/java/com/sk89q/worldedit/forge/ForgeAdapter.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
final class ForgeAdapter {
|
||||
|
||||
private ForgeAdapter() {
|
||||
}
|
||||
|
||||
public static World adapt(net.minecraft.world.World world) {
|
||||
return new ForgeWorld(world);
|
||||
}
|
||||
|
||||
public static Vector adapt(Vec3 vector) {
|
||||
return new Vector(vector.xCoord, vector.yCoord, vector.zCoord);
|
||||
}
|
||||
|
||||
}
|
67
src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java
Normal file
67
src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
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 net.minecraft.entity.EntityList;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
class ForgeEntity implements Entity {
|
||||
|
||||
private final net.minecraft.entity.Entity entity;
|
||||
|
||||
ForgeEntity(net.minecraft.entity.Entity entity) {
|
||||
checkNotNull(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseEntity getState() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
entity.writeToNBT(tag);
|
||||
return new BaseEntity(EntityList.getEntityString(entity), NBTConverter.fromNative(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(
|
||||
ForgeAdapter.adapt(entity.worldObj),
|
||||
new Vector(entity.posX, entity.posY, entity.posZ),
|
||||
ForgeAdapter.adapt(entity.getLookVec()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return ForgeAdapter.adapt(entity.worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
entity.setDead();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.LazyBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
@ -32,8 +33,8 @@ import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.mapping.NullResolver;
|
||||
import com.sk89q.worldedit.world.mapping.Resolver;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityHanging;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.item.*;
|
||||
@ -55,7 +56,7 @@ import net.minecraft.world.gen.ChunkProviderServer;
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
@ -227,7 +228,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
int num = 0;
|
||||
double radiusSq = radius * radius;
|
||||
|
||||
for (Entity obj : (Iterable<Entity>) getWorld().loadedEntityList) {
|
||||
for (net.minecraft.entity.Entity obj : (Iterable<net.minecraft.entity.Entity>) getWorld().loadedEntityList) {
|
||||
if ((obj instanceof EntityLiving)) {
|
||||
EntityLiving ent = (EntityLiving) obj;
|
||||
|
||||
@ -270,7 +271,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
int num = 0;
|
||||
double radiusSq = Math.pow(radius, 2.0D);
|
||||
|
||||
for (Entity ent : (Iterable<Entity>) getWorld().loadedEntityList) {
|
||||
for (net.minecraft.entity.Entity ent : (Iterable<net.minecraft.entity.Entity>) getWorld().loadedEntityList) {
|
||||
if ((radius != -1) && (origin.distanceSq(new Vector(ent.posX, ent.posY, ent.posZ)) > radiusSq)) {
|
||||
continue;
|
||||
}
|
||||
@ -497,7 +498,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getMetaData(com.sk89q.worldedit.entity.Entity entity, Class<T> metaDataClass) {
|
||||
public <T> T getMetaData(Entity entity, Class<T> metaDataClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -508,14 +509,29 @@ public class ForgeWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
|
||||
return Collections.emptyList();
|
||||
public List<Entity> getEntities() {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
for (Object entity : getWorld().getLoadedEntityList()) {
|
||||
entities.add(new ForgeEntity((net.minecraft.entity.Entity) entity));
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public com.sk89q.worldedit.entity.Entity createEntity(Location location, BaseEntity entity) {
|
||||
return null;
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
World world = getWorld();
|
||||
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world);
|
||||
if (createdEntity != null) {
|
||||
CompoundTag tag = entity.getNbtData();
|
||||
if (tag != null) {
|
||||
createdEntity.readFromNBT(NBTConverter.toNative(entity.getNbtData()));
|
||||
}
|
||||
world.spawnEntityInWorld(createdEntity);
|
||||
return new ForgeEntity(createdEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user