repaired hopper for itemhoarder

This commit is contained in:
Jottyfan
2025-12-30 19:19:03 +01:00
parent 0aa12478b4
commit 84b3779af2

View File

@@ -8,6 +8,7 @@ import com.mojang.serialization.Codec;
import de.jottyfan.minecraft.Quickly;
import de.jottyfan.minecraft.block.QuicklyBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.Container;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
@@ -16,6 +17,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.ValueInput;
import net.minecraft.world.level.storage.ValueOutput;
@@ -51,10 +53,8 @@ public class ItemHoarderBlockEntity extends BlockEntity implements Container {
ItemStack s = stacks.get(key);
if (s == null) {
stacks.put(key, stack);
Quickly.LOGGER.info("stored {} x {}", stack.getCount(), key);
} else {
stacks.get(key).grow(stack.getCount());
Quickly.LOGGER.info("added {} x {}", stack.getCount(), key);
}
return true;
}
@@ -69,13 +69,31 @@ public class ItemHoarderBlockEntity extends BlockEntity implements Container {
}
}
private static final void dropToHopper(Level level, BlockPos pos, BlockState state, ItemHoarderBlockEntity be) {
// TODO: export by hopper
private static final void dropToHopper(Level level, BlockPos pos, BlockState state,
ItemHoarderBlockEntity blockEntity) {
BlockEntity beBelow = level.getBlockEntity(pos.below());
if (beBelow instanceof Container targetInventory) {
// TODO: fill hopper beyond with item stack if space is left
for (String stackKey : blockEntity.getStacks().keySet()) {
ItemStack stackInSlot = blockEntity.getStack(stackKey);
if (!stackInSlot.isEmpty()) {
ItemStack toInsert = stackInSlot.copy();
int oldCount = toInsert.getCount();
ItemStack remainder = HopperBlockEntity.addItem(blockEntity, targetInventory, toInsert, Direction.UP);
int movedAmount = oldCount - remainder.getCount();
if (movedAmount > 0) {
stackInSlot.shrink(movedAmount);
blockEntity.setChanged();
targetInventory.setChanged();
return;
}
}
}
}
}
private ItemStack getStack(String stackKey) {
return stacks.get(stackKey);
}
public static void tick(Level level, BlockPos pos, BlockState state, ItemHoarderBlockEntity be) {
suck(level, pos, be);