Skip to content

Commit

Permalink
backported item filter for Rannuncarpus (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 27, 2024
1 parent af57a9f commit 5b81cbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import org.lwjgl.opengl.GL11;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void onUpdate() {

IInventory inv = InventoryHelper.getInventory(supertile.getWorldObj(), x_, y_, z_);
if(inv != null) {
List<ItemStack> filter = getFilterForInventory(inv, x_, y_, z_, true);
List<ItemStack> filter = getFilterForInventory(supertile.getWorldObj(), inv, x_, y_, z_, true);
boolean canAccept = canAcceptItem(stack, filter, filterType);
int availablePut = supertile.getWorldObj().isRemote ? 1 : InventoryHelper.testInventoryInsertion(inv, stack, dir);
canAccept &= availablePut > 0;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void onUpdate() {
mana--;
}

public boolean canAcceptItem(ItemStack stack, List<ItemStack> filter, int filterType) {
public static boolean canAcceptItem(ItemStack stack, List<ItemStack> filter, int filterType) {
if(stack == null)
return false;

Expand Down Expand Up @@ -169,17 +170,17 @@ public boolean canAcceptItem(ItemStack stack, List<ItemStack> filter, int filter
}
}

public List<ItemStack> getFilterForInventory(IInventory inv, int x, int y, int z, boolean recursiveForDoubleChests) {
public static List<ItemStack> getFilterForInventory(World world, IInventory inv, int x, int y, int z, boolean recursiveForDoubleChests) {
List<ItemStack> filter = new ArrayList();

if(recursiveForDoubleChests) {
TileEntity tileEntity = supertile.getWorldObj().getTileEntity(x, y, z);
Block chest = supertile.getWorldObj().getBlock(x, y, z);
TileEntity tileEntity = world.getTileEntity(x, y, z);
Block chest = world.getBlock(x, y, z);

if(tileEntity instanceof TileEntityChest)
for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS)
if(supertile.getWorldObj().getBlock(x + dir.offsetX, y, z + dir.offsetZ) == chest) {
filter.addAll(getFilterForInventory((IInventory) supertile.getWorldObj().getTileEntity(x + dir.offsetX, y, z + dir.offsetZ), x + dir.offsetX, y, z + dir.offsetZ, false));
if(world.getBlock(x + dir.offsetX, y, z + dir.offsetZ) == chest) {
filter.addAll(getFilterForInventory(world, (IInventory) world.getTileEntity(x + dir.offsetX, y, z + dir.offsetZ), x + dir.offsetX, y, z + dir.offsetZ, false));
break;
}
}
Expand All @@ -190,7 +191,7 @@ public List<ItemStack> getFilterForInventory(IInventory inv, int x, int y, int z

for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS) {
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, x + dir.offsetX + 1, y + dir.offsetY + 1, z + dir.offsetZ + 1);
List<EntityItemFrame> frames = supertile.getWorldObj().getEntitiesWithinAABB(EntityItemFrame.class, aabb);
List<EntityItemFrame> frames = world.getEntitiesWithinAABB(EntityItemFrame.class, aabb);
for(EntityItemFrame frame : frames) {
int orientation = frame.hangingDirection;
if(orientationToDir[orientation] == dir.ordinal())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void onUpdate() {
int z = supertile.zCoord;

List<EntityItem> items = supertile.getWorldObj().getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - RANGE, y - RANGE_Y, z - RANGE, x + RANGE + 1, y + RANGE_Y, z + RANGE + 1));
List<ItemStack> itemFilter = SubTileHopperhock.getFilterForInventory(supertile.getWorldObj(), null,x,y-(supertile instanceof IFloatingFlower?1:2),z, false);
int slowdown = getSlowdownFactor();
for(EntityItem item : items) {
if(item.age < (60 + slowdown) || item.isDead)
Expand Down

0 comments on commit 5b81cbe

Please sign in to comment.