repaired hopper for itemhoarder
This commit is contained in:
@@ -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,14 +69,32 @@ 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);
|
||||
dropToHopper(level, pos, state, be);
|
||||
|
||||
Reference in New Issue
Block a user