mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-24 22:04:34 +00:00
Add typed methods for getting entities from the world
This commit is contained in:
1 parent
efd9cd06f6
commit
eaad349b74
2 files changed
+49
No files matched your search
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.entities;
|
||||
|
||||
import net.minecraft.command.IEntitySelector;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public abstract class EntitySelector<T extends Entity> implements IEntitySelector {
|
||||
private final Class<T> entityClass;
|
||||
|
||||
protected EntitySelector(Class<T> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
public Class<T> getEntityClass() {
|
||||
return entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isEntityApplicable(Entity entity) {
|
||||
T castEntity = entityClass.cast(entity);
|
||||
return isEntityApplicableTyped(castEntity);
|
||||
}
|
||||
|
||||
protected abstract boolean isEntityApplicableTyped(T entity);
|
||||
}
|
||||
@@ -10,15 +10,20 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.command.IEntitySelector;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.entities.EntitySelector;
|
||||
|
||||
public abstract class EntityUtil {
|
||||
public static <E extends EntityLiving> E spawnEntity(World world, Class<E> entityClass, double x, double y, double z) {
|
||||
@@ -48,6 +53,16 @@ public abstract class EntityUtil {
|
||||
Log.finer("Registered entity %s (%s) with id %s.", ident, entityClass.toString(), id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Entity> List<T> getEntitiesWithinAABB(World world, Class<T> entityClass, AxisAlignedBB boundingBox) {
|
||||
return world.getEntitiesWithinAABB(entityClass, boundingBox);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Entity> List<T> selectEntitiesWithinAABB(World world, EntitySelector<T> entitySelector, AxisAlignedBB boundingBox) {
|
||||
return world.selectEntitiesWithinAABB(entitySelector.getEntityClass(), boundingBox, entitySelector);
|
||||
}
|
||||
|
||||
private static <E extends EntityLiving> E createEntity(World world, Class<E> entityClass) {
|
||||
if (!EntityList.classToStringMapping.containsKey(entityClass)) {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user