Fix farm picking up items off Immersive Engineering conveyors

This commit is contained in:
mezz committed 2016-11-25 12:24:15 -08:00
1 parent 098b739dca
commit 43a2f0ae76
2 files changed
+12 -49

No files matched your search

@@ -1,38 +0,0 @@
/*******************************************************************************
* 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 com.google.common.base.Predicate;
import net.minecraft.entity.Entity;
public abstract class EntitySelector<T extends Entity> implements Predicate<T> {
private final Class<T> entityClass;
protected EntitySelector(Class<T> entityClass) {
this.entityClass = entityClass;
}
public Class<T> getEntityClass() {
return entityClass;
}
@Override
public boolean apply(Entity entity) {
if (entity == null) {
return false;
}
T castEntity = entityClass.cast(entity);
return isEntityApplicableTyped(castEntity);
}
protected abstract boolean isEntityApplicableTyped(T entity);
}
@@ -14,6 +14,11 @@ import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Predicate;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmLogic;
import forestry.core.utils.VectUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureMap;
@@ -25,16 +30,9 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmLogic;
import forestry.core.entities.EntitySelector;
import forestry.core.utils.VectUtil;
public abstract class FarmLogic implements IFarmLogic {
private final EntitySelectorFarm entitySelectorFarm = new EntitySelectorFarm(this);
protected boolean isManual;
@@ -90,7 +88,7 @@ public abstract class FarmLogic implements IFarmLogic {
protected List<ItemStack> collectEntityItems(World world, IFarmHousing farmHousing, boolean toWorldHeight) {
AxisAlignedBB harvestBox = getHarvestBox(world, farmHousing, toWorldHeight);
List<EntityItem> entityItems = world.getEntitiesWithinAABB(entitySelectorFarm.getEntityClass(), harvestBox, entitySelectorFarm);
List<EntityItem> entityItems = world.getEntitiesWithinAABB(EntityItem.class, harvestBox, entitySelectorFarm);
List<ItemStack> stacks = new ArrayList<>();
for (EntityItem entity : entityItems) {
ItemStack contained = entity.getEntityItem();
@@ -100,20 +98,23 @@ public abstract class FarmLogic implements IFarmLogic {
return stacks;
}
private static class EntitySelectorFarm extends EntitySelector<EntityItem> {
private static class EntitySelectorFarm implements Predicate<EntityItem> {
private final FarmLogic farmLogic;
public EntitySelectorFarm(FarmLogic farmLogic) {
super(EntityItem.class);
this.farmLogic = farmLogic;
}
@Override
protected boolean isEntityApplicableTyped(EntityItem entity) {
public boolean apply(EntityItem entity) {
if (entity.isDead) {
return false;
}
if (entity.getEntityData().getBoolean("PreventRemoteMovement")) {
return false;
}
ItemStack contained = entity.getEntityItem();
return farmLogic.isAcceptedGermling(contained) || farmLogic.isAcceptedWindfall(contained);
}