mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-03 11:56:40 +00:00
Added basic entity handling with copy and paste.
Paintings do not currently respawn properly, entity pastes cannot be undone yet, and schematics do not yet store entities @celticminstrel needs to fix painting spawning
This commit is contained in:
64
src/main/java/com/sk89q/worldedit/spout/SpoutEntity.java
Normal file
64
src/main/java/com/sk89q/worldedit/spout/SpoutEntity.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.spout;
|
||||
|
||||
import com.sk89q.worldedit.LocalEntity;
|
||||
import com.sk89q.worldedit.Location;
|
||||
import org.spout.api.entity.Controller;
|
||||
import org.spout.api.entity.Entity;
|
||||
import org.spout.api.entity.type.ControllerType;
|
||||
import org.spout.api.geo.World;
|
||||
import org.spout.api.geo.discrete.Point;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class SpoutEntity extends LocalEntity {
|
||||
private final ControllerType type;
|
||||
private final int entityId;
|
||||
|
||||
public SpoutEntity(Location position, int id, Controller controller) {
|
||||
super(position);
|
||||
type = controller.getType();
|
||||
this.entityId = id;
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawn(Location loc) {
|
||||
World world = ((SpoutWorld) loc.getWorld()).getWorld();
|
||||
Point pos = SpoutUtil.toPoint(world, loc.getPosition());
|
||||
Controller controller = type.createController();
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
Entity e = world.createAndSpawnEntity(pos, controller);
|
||||
|
||||
if (e != null) {
|
||||
e.setPitch(loc.getPitch());
|
||||
e.setYaw(loc.getYaw());
|
||||
// TODO: Copy datatable info
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -24,9 +24,11 @@ package com.sk89q.worldedit.spout;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockWorldVector;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldVector;
|
||||
import org.spout.api.Game;
|
||||
import org.spout.api.entity.Entity;
|
||||
import org.spout.api.geo.World;
|
||||
import org.spout.api.geo.cuboid.Block;
|
||||
import org.spout.api.geo.discrete.Point;
|
||||
@ -105,4 +107,8 @@ public class SpoutUtil {
|
||||
public static World toWorld(WorldVector pt) {
|
||||
return ((SpoutWorld) pt.getWorld()).getWorld();
|
||||
}
|
||||
|
||||
public static Location toLocation(Entity ent) {
|
||||
return new Location(getLocalWorld(ent.getWorld()), toVector(ent.getPosition()), ent.getYaw(), ent.getPitch());
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.BiomeType;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.EntityType;
|
||||
import com.sk89q.worldedit.LocalEntity;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
@ -49,6 +50,9 @@ import org.spout.vanilla.controller.object.projectile.Arrow;
|
||||
import org.spout.vanilla.controller.object.vehicle.Boat;
|
||||
import org.spout.vanilla.controller.object.vehicle.Minecart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpoutWorld extends LocalWorld {
|
||||
private World world;
|
||||
|
||||
@ -732,4 +736,35 @@ public class SpoutWorld extends LocalWorld {
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpoutEntity[] getEntities(Region region) {
|
||||
List<SpoutEntity> entities = new ArrayList<SpoutEntity>();
|
||||
for (Vector pt : region.getChunkCubes()) {
|
||||
Chunk chunk = world.getChunk(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), false);
|
||||
if (chunk == null) {
|
||||
continue;
|
||||
}
|
||||
for (Entity ent : chunk.getEntities()) {
|
||||
if (region.contains(SpoutUtil.toVector(ent.getPosition()))) {
|
||||
entities.add(new SpoutEntity(SpoutUtil.toLocation(ent), ent.getId(), ent.getController()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities.toArray(new SpoutEntity[entities.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int killEntities(LocalEntity[] entities) {
|
||||
int amount = 0;
|
||||
for (LocalEntity weEnt : entities) {
|
||||
SpoutEntity entity = (SpoutEntity) weEnt;
|
||||
Entity spoutEntity = world.getEntity(entity.getEntityId());
|
||||
if (spoutEntity != null) {
|
||||
spoutEntity.kill();
|
||||
++amount;
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user