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

溜槽更改 #126

Merged
merged 2 commits into from
Apr 1, 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 @@ -22,6 +22,7 @@
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -112,12 +113,18 @@ protected boolean insertOrDropItem(Direction direction, Level level, @NotNull Bl
if (HopperBlockEntity.getContainerAt(level, curPos) != null) return false;
if (ItemStorage.SIDED.find(level, curPos, direction.getOpposite()) != null) return false;
}
if (!needEmpty || level.isEmptyBlock(curPos)) {
if (!needEmpty || this.canDropItem(level, curPos)) {
flag = this.dropItem(direction, level, pos, container, slot, momentum);
}
return flag;
}

private boolean canDropItem(@NotNull Level level, @NotNull BlockPos pos) {
Vec3 vec3 = pos.getCenter();
ItemEntity entity = new ItemEntity(level, vec3.x, vec3.y, vec3.z, ItemStack.EMPTY);
return level.noCollision(entity);
}

@SuppressWarnings("UnstableApiUsage")
private boolean insertItem(Direction direction, Level level, @NotNull BlockPos pos, @NotNull Container container, int slot) {
ItemStack item = container.getItem(slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import dev.dubhe.anvilcraft.inventory.ChuteMenu;
import lombok.Getter;
import lombok.Setter;
import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
Expand Down Expand Up @@ -116,6 +121,7 @@ private static boolean tryMoveItems(@NotNull Level level, BlockPos pos, BlockSta
return false;
}

@SuppressWarnings("UnstableApiUsage")
public static boolean suckInItems(Level level, Hopper hopper) {
Container container = HopperBlockEntity.getSourceContainer(level, hopper);
if (container != null) {
Expand All @@ -124,6 +130,19 @@ public static boolean suckInItems(Level level, Hopper hopper) {
return false;
}
return HopperBlockEntity.getSlots(container, direction).anyMatch(i -> ChuteBlockEntity.tryTakeInItemFromSlot(hopper, container, i, direction));
} else {
BlockPos sourcePos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0D, hopper.getLevelZ());
Storage<ItemVariant> source = ItemStorage.SIDED.find(level, sourcePos, Direction.DOWN);
if (source != null) {
long moved = StorageUtil.move(
source,
InventoryStorage.of(hopper, Direction.UP),
iv -> true,
64,
null
);
return moved >= 1;
}
}
for (ItemEntity itemEntity : HopperBlockEntity.getItemsAtAndAbove(level, hopper)) {
if (!HopperBlockEntity.addItem(hopper, itemEntity)) continue;
Expand Down
Loading