blockstacker works
This commit is contained in:
parent
0df9614d08
commit
9e36a08660
@ -7,6 +7,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -36,16 +37,49 @@ public class BlockStackerEntity extends BlockEntity {
|
||||
}
|
||||
}
|
||||
|
||||
private static void transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest) {
|
||||
Integer sourceCounter = findItemStackPos(source, false);
|
||||
Integer destCounter = findItemStackPos(dest, true);
|
||||
// TODO: if stack.getItem().equals(source.getStack(sourceCounter).getItem() and stacksize < maxStackSize...
|
||||
if (sourceCounter != null && destCounter != null) {
|
||||
dest.setStack(destCounter, source.removeStack(sourceCounter));
|
||||
private static final void transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest) {
|
||||
Integer sourceSlot = findItemStackPos(source, false);
|
||||
if (sourceSlot != null && !Items.AIR.equals(source.getStack(sourceSlot).getItem())) {
|
||||
ItemStack sourceStack = source.getStack(sourceSlot);
|
||||
Integer destSlot = findItemStackPos(dest, sourceStack);
|
||||
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();
|
||||
while (counter > 0) {
|
||||
counter--;
|
||||
|
@ -11,6 +11,6 @@ import net.minecraft.item.Item;
|
||||
*/
|
||||
public class ItemCarrotstack extends Item {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import net.minecraft.item.Item;
|
||||
*/
|
||||
public class ItemCotton extends Item {
|
||||
public ItemCotton() {
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99));
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import net.minecraft.world.World;
|
||||
*/
|
||||
public class ItemCottonseed extends Item {
|
||||
public ItemCottonseed() {
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99));
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,6 @@ import net.minecraft.item.Item;
|
||||
*/
|
||||
public class ItemLevelup extends Item {
|
||||
public ItemLevelup() {
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99));
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import net.minecraft.item.Item;
|
||||
*/
|
||||
public class ItemRottenFleshStripes extends Item {
|
||||
public ItemRottenFleshStripes() {
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99));
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import net.minecraft.item.Item;
|
||||
*/
|
||||
public class ItemStub extends Item {
|
||||
public ItemStub() {
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(99));
|
||||
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(64));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"parent": "block/cube_bottom_top",
|
||||
"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 |
Loading…
x
Reference in New Issue
Block a user