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

Implement Ender Dropper pushing into inventories #333

Merged
merged 1 commit into from
Jan 29, 2024
Merged
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
@@ -1,6 +1,11 @@
package de.dafuqs.spectrum.blocks.ender;

import de.dafuqs.spectrum.inventories.*;
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.block.*;
import net.minecraft.block.dispenser.*;
import net.minecraft.block.entity.*;
Expand Down Expand Up @@ -74,6 +79,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}
}

@SuppressWarnings("UnstableApiUsage")
@Override
protected void dispense(ServerWorld world, BlockPos pos) {
BlockPointerImpl blockPointerImpl = new BlockPointerImpl(world, pos);
Expand All @@ -90,6 +96,20 @@ protected void dispense(ServerWorld world, BlockPos pos) {
ItemStack itemStack3 = BEHAVIOR.dispense(blockPointerImpl, itemStack);
enderDropperBlockEntity.setStack(i, itemStack3);
} else {
Storage<ItemVariant> target = ItemStorage.SIDED.find(world, pos.offset(direction), direction.getOpposite());
if (target != null) {
// getting inv will always work since .chooseNonEmptySlot() and others would fail otherwise
Inventory inv = enderDropperBlockEntity.getOwnerIfOnline().getEnderChestInventory();
long moved = StorageUtil.move(
InventoryStorage.of(inv, direction).getSlot(i),
target,
iv -> true,
1,
null
);
// return without triggering fail event if successfully moved
if (moved == 1) return;
}
world.syncWorldEvent(WorldEvents.DISPENSER_FAILS, pos, 0); // no room to dispense to
}
}
Expand Down
Loading