Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backported item filter for Rannuncarpus #60

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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