blockstacker works

This commit is contained in:
Jottyfan 2022-08-20 16:55:30 +02:00
parent 0df9614d08
commit 9e36a08660
11 changed files with 59 additions and 23 deletions

View File

@ -7,6 +7,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -36,16 +37,49 @@ public class BlockStackerEntity extends BlockEntity {
} }
} }
private static void transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest) { private static final void transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest) {
Integer sourceCounter = findItemStackPos(source, false); Integer sourceSlot = findItemStackPos(source, false);
Integer destCounter = findItemStackPos(dest, true); if (sourceSlot != null && !Items.AIR.equals(source.getStack(sourceSlot).getItem())) {
// TODO: if stack.getItem().equals(source.getStack(sourceCounter).getItem() and stacksize < maxStackSize... ItemStack sourceStack = source.getStack(sourceSlot);
if (sourceCounter != null && destCounter != null) { Integer destSlot = findItemStackPos(dest, sourceStack);
dest.setStack(destCounter, source.removeStack(sourceCounter)); if (destSlot != null) {
Integer occupied = dest.getStack(destSlot).getCount();
Integer free = dest.getStack(destSlot).getMaxCount() - occupied;
Integer candidates = source.getStack(sourceSlot).getCount();
Integer travellers = candidates > free ? free : candidates;
if (travellers > 0) {
LOGGER.debug("transfer {}/{} of {} from slot {} to slot {} on top of {} ones", travellers, candidates, source.getStack(sourceSlot).getItem().toString(), sourceSlot, destSlot, occupied);
source.getStack(sourceSlot).decrement(travellers);
if (source.getStack(sourceSlot).getCount() < 1) {
source.removeStack(sourceSlot); // make empty slots really empty
}
dest.getStack(destSlot).increment(travellers);
}
} else {
Integer destFreeSlot = findItemStackPos(dest, true);
if (destFreeSlot != null) {
LOGGER.debug("transfer all of {} from slot {} to slot {}", source.getStack(sourceSlot).getItem().toString(), sourceSlot, destSlot);
dest.setStack(destFreeSlot, source.removeStack(sourceSlot));
}
}
} }
} }
private static Integer findItemStackPos(LootableContainerBlockEntity lcbe, Boolean empty) { private static final Integer findItemStackPos(LootableContainerBlockEntity lcbe, ItemStack sourceStack) {
Integer counter = lcbe.size();
while (counter > 0) {
counter--;
ItemStack stack = lcbe.getStack(counter);
if (stack.getItem().equals(sourceStack.getItem())) {
if (stack.getCount() < stack.getMaxCount()) {
return counter;
}
}
}
return null;
}
private static final Integer findItemStackPos(LootableContainerBlockEntity lcbe, Boolean empty) {
Integer counter = lcbe.size(); Integer counter = lcbe.size();
while (counter > 0) { while (counter > 0) {
counter--; counter--;

View File

@ -11,6 +11,6 @@ import net.minecraft.item.Item;
*/ */
public class ItemCarrotstack extends Item { public class ItemCarrotstack extends Item {
public ItemCarrotstack() { public ItemCarrotstack() {
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99).food(new FoodComponent.Builder().hunger(12).saturationModifier(0.6F).build())); super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64).food(new FoodComponent.Builder().hunger(12).saturationModifier(0.6F).build()));
} }
} }

View File

@ -10,6 +10,6 @@ import net.minecraft.item.Item;
*/ */
public class ItemCotton extends Item { public class ItemCotton extends Item {
public ItemCotton() { public ItemCotton() {
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99)); super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
} }
} }

View File

@ -17,7 +17,7 @@ import net.minecraft.world.World;
*/ */
public class ItemCottonseed extends Item { public class ItemCottonseed extends Item {
public ItemCottonseed() { public ItemCottonseed() {
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99)); super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
} }
@Override @Override

View File

@ -10,6 +10,6 @@ import net.minecraft.item.Item;
*/ */
public class ItemLevelup extends Item { public class ItemLevelup extends Item {
public ItemLevelup() { public ItemLevelup() {
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99)); super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
} }
} }

View File

@ -10,6 +10,6 @@ import net.minecraft.item.Item;
*/ */
public class ItemRottenFleshStripes extends Item { public class ItemRottenFleshStripes extends Item {
public ItemRottenFleshStripes() { public ItemRottenFleshStripes() {
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99)); super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
} }
} }

View File

@ -10,6 +10,6 @@ import net.minecraft.item.Item;
*/ */
public class ItemStub extends Item { public class ItemStub extends Item {
public ItemStub() { public ItemStub() {
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99)); super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
} }
} }

View File

@ -1,6 +1,8 @@
{ {
"parent": "block/cube_all", "parent": "block/cube_bottom_top",
"textures": { "textures": {
"all": "quickiefabric:block/blockstacker" "bottom": "quickiefabric:block/blockstackerbottom",
"side": "quickiefabric:block/blockstacker",
"top": "quickiefabric:block/blockstackertop"
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB