mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Re-implement /remove and /butcher with the new entity API.
This commit is contained in:
@ -22,14 +22,14 @@ 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.entity.metadata.EntityType;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.entity.EntityHanging;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
class ForgeEntity implements Entity {
|
||||
@ -41,6 +41,15 @@ class ForgeEntity implements Entity {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the underlying entity.
|
||||
*
|
||||
* @return the underlying entity
|
||||
*/
|
||||
net.minecraft.entity.Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseEntity getState() {
|
||||
String id = EntityList.getEntityString(entity);
|
||||
@ -73,4 +82,14 @@ class ForgeEntity implements Entity {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getFacet(Class<? extends T> cls) {
|
||||
if (EntityType.class.isAssignableFrom(cls)) {
|
||||
return (T) new ForgeEntityType(entity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
138
src/forge/java/com/sk89q/worldedit/forge/ForgeEntityType.java
Normal file
138
src/forge/java/com/sk89q/worldedit/forge/ForgeEntityType.java
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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.entity.metadata.EntityType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.IMerchant;
|
||||
import net.minecraft.entity.INpc;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.item.EntityBoat;
|
||||
import net.minecraft.entity.item.EntityEnderEye;
|
||||
import net.minecraft.entity.item.EntityFallingSand;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.item.EntityPainting;
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.monster.EntityGolem;
|
||||
import net.minecraft.entity.passive.EntityAmbientCreature;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
import net.minecraft.entity.passive.IAnimals;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class ForgeEntityType implements EntityType {
|
||||
|
||||
private final Entity entity;
|
||||
|
||||
public ForgeEntityType(Entity entity) {
|
||||
checkNotNull(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerDerived() {
|
||||
return entity instanceof EntityPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProjectile() {
|
||||
return entity instanceof EntityEnderEye || entity instanceof IProjectile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem() {
|
||||
return entity instanceof EntityItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFallingBlock() {
|
||||
return entity instanceof EntityFallingSand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPainting() {
|
||||
return entity instanceof EntityPainting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemFrame() {
|
||||
return entity instanceof EntityItemFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoat() {
|
||||
return entity instanceof EntityBoat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMinecart() {
|
||||
return entity instanceof EntityMinecart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTNT() {
|
||||
return entity instanceof EntityTNTPrimed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExperienceOrb() {
|
||||
return entity instanceof EntityXPOrb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLiving() {
|
||||
return entity instanceof EntityLiving;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnimal() {
|
||||
return entity instanceof IAnimals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbient() {
|
||||
return entity instanceof EntityAmbientCreature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNPC() {
|
||||
return entity instanceof INpc || entity instanceof IMerchant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGolem() {
|
||||
return entity instanceof EntityGolem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTamed() {
|
||||
return entity instanceof EntityTameable && ((EntityTameable) entity).isTamed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTagged() {
|
||||
return entity instanceof EntityLiving && ((EntityLiving) entity).hasCustomNameTag();
|
||||
}
|
||||
}
|
@ -20,10 +20,10 @@
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldVector;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
@ -33,7 +33,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public class ForgePlayer extends LocalPlayer {
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ForgePlayer extends AbstractPlayerActor {
|
||||
|
||||
private EntityPlayerMP player;
|
||||
|
||||
protected ForgePlayer(EntityPlayerMP player) {
|
||||
@ -133,4 +136,11 @@ public class ForgePlayer extends LocalPlayer {
|
||||
public boolean hasPermission(String perm) {
|
||||
return ForgeUtil.hasPermission(this.player, perm);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getFacet(Class<? extends T> cls) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,6 @@ package com.sk89q.worldedit.forge;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.BiomeType;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.EntityType;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
@ -33,34 +32,15 @@ import com.sk89q.worldedit.blocks.LazyBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Direction.Flag;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.registry.LegacyWorldData;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
import net.minecraft.block.Block;
|
||||
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.EntityBoat;
|
||||
import net.minecraft.entity.item.EntityEnderEye;
|
||||
import net.minecraft.entity.item.EntityFallingSand;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.item.EntityPainting;
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.monster.EntityGolem;
|
||||
import net.minecraft.entity.passive.EntityAmbientCreature;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@ -224,7 +204,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
checkNotNull(position);
|
||||
checkNotNull(item);
|
||||
|
||||
if ((item == null) || (item.getType() == 0)) {
|
||||
if (item.getType() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -233,121 +213,6 @@ public class ForgeWorld extends AbstractWorld {
|
||||
getWorld().spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "ConstantConditions"})
|
||||
public int killMobs(Vector origin, double radius, int flags) {
|
||||
boolean killPets = (flags & 0x1) != 0;
|
||||
boolean killNPCs = (flags & 0x2) != 0;
|
||||
boolean killAnimals = (flags & 0x4) != 0;
|
||||
|
||||
boolean killGolems = (flags & 0x8) != 0;
|
||||
boolean killAmbient = (flags & 0x10) != 0;
|
||||
|
||||
int num = 0;
|
||||
double radiusSq = radius * radius;
|
||||
|
||||
for (net.minecraft.entity.Entity obj : (Iterable<net.minecraft.entity.Entity>) getWorld().loadedEntityList) {
|
||||
if ((obj instanceof EntityLiving)) {
|
||||
EntityLiving ent = (EntityLiving) obj;
|
||||
|
||||
if (!killAnimals && ent instanceof EntityAnimal) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!killPets && ent instanceof EntityTameable && ((EntityTameable) ent).isTamed()) {
|
||||
continue; // tamed pet
|
||||
}
|
||||
|
||||
if (!killGolems && ent instanceof EntityGolem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!killNPCs && ent instanceof EntityVillager) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!killAmbient && ent instanceof EntityAmbientCreature) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((radius < 0.0D) || (origin.distanceSq(new Vector(ent.posX, ent.posY, ent.posZ)) <= radiusSq)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int removeEntities(EntityType type, Vector origin, int radius) {
|
||||
checkNotNull(type);
|
||||
checkNotNull(origin);
|
||||
|
||||
int num = 0;
|
||||
double radiusSq = Math.pow(radius, 2.0D);
|
||||
|
||||
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;
|
||||
}
|
||||
if (type == EntityType.ALL) {
|
||||
if (((ent instanceof EntityBoat)) || ((ent instanceof EntityItem)) || ((ent instanceof EntityFallingSand)) || ((ent instanceof EntityMinecart)) || ((ent instanceof EntityHanging)) || ((ent instanceof EntityTNTPrimed)) || ((ent instanceof EntityXPOrb)) || ((ent instanceof EntityEnderEye)) || ((ent instanceof IProjectile))) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if ((type == EntityType.PROJECTILES) || (type == EntityType.ARROWS)) {
|
||||
if (((ent instanceof EntityEnderEye)) || ((ent instanceof IProjectile))) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.BOATS) {
|
||||
if ((ent instanceof EntityBoat)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.ITEMS) {
|
||||
if ((ent instanceof EntityItem)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.FALLING_BLOCKS) {
|
||||
if ((ent instanceof EntityFallingSand)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.MINECARTS) {
|
||||
if ((ent instanceof EntityMinecart)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.PAINTINGS) {
|
||||
if ((ent instanceof EntityPainting)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.ITEM_FRAMES) {
|
||||
if ((ent instanceof EntityItemFrame)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if (type == EntityType.TNT) {
|
||||
if ((ent instanceof EntityTNTPrimed)) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
} else if ((type == EntityType.XP_ORBS) && ((ent instanceof EntityXPOrb))) {
|
||||
ent.isDead = true;
|
||||
num++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerate(Region region, EditSession editSession) {
|
||||
BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];
|
||||
|
Reference in New Issue
Block a user