Merge pull request #101 from DeadlyMC/patch

Fix ctrlQCrafting and autoCrafting duplicating items
This commit is contained in:
gnembon authored and GitHub committed 2019-11-09 12:48:24 -04:00
commit 65a2ae263c
1 file changed
+9 -33
@@ -16,10 +16,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.List; import java.util.List;
@Mixin(Container.class) @Mixin(Container.class)
public class ContainerMixin public abstract class ContainerMixin
{ {
@Shadow @Final public List<Slot> slotList; @Shadow @Final public List<Slot> slotList;
@Shadow public abstract ItemStack onSlotClick(int int_1, int int_2, SlotActionType slotActionType_1, PlayerEntity playerEntity_1);
@Shadow public abstract void sendContentUpdates();
@Inject( method = "onSlotClick", at = @At(value = "HEAD"), cancellable = true) @Inject( method = "onSlotClick", at = @At(value = "HEAD"), cancellable = true)
private void onThrowClick( private void onThrowClick(
int int_1, int int_1,
@@ -33,47 +37,19 @@ public class ContainerMixin
{ {
ItemStack itemStack_1 = ItemStack.EMPTY; ItemStack itemStack_1 = ItemStack.EMPTY;
Slot slot_4 = slotList.get(int_1); Slot slot_4 = slotList.get(int_1);
if (slot_4 != null && slot_4.canTakeItems(playerEntity_1)) if (slot_4 != null && slot_4.hasStack() && slot_4.canTakeItems(playerEntity_1))
{ {
if(int_1 == 0 && int_2 == 1) if(int_1 == 0 && int_2 == 1)
{ {
ItemStack itemStackDropAll = dropAllCrafting(playerEntity_1, int_1, slotList); while(slot_4.hasStack())
while (!itemStackDropAll.isEmpty() && ItemStack.areItemsEqual(slot_4.getStack(), itemStackDropAll))
{ {
itemStack_1 = itemStackDropAll.copy(); this.onSlotClick(int_1, 0, SlotActionType.THROW, playerEntity_1);
itemStackDropAll = dropAllCrafting(playerEntity_1, int_1, slotList);
} }
this.sendContentUpdates();
cir.setReturnValue(itemStack_1); cir.setReturnValue(itemStack_1);
cir.cancel(); cir.cancel();
} }
} }
} }
} }
private ItemStack dropAllCrafting(PlayerEntity playerIn, int index, List<Slot> invSlotParam)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = invSlotParam.get(index);
if (slot != null && slot.hasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 0)
{
playerIn.dropItem(itemstack, true);
itemstack1.setCount(0);
slot.onStackChanged(itemstack1, itemstack);
}
if (itemstack.getCount() == itemstack1.getCount())
{
return ItemStack.EMPTY;
}
ItemStack itemstack2 = slot.onTakeItem(playerIn, itemstack1);
if (index == 0)
{
playerIn.dropItem(itemstack2, false);
}
}
return itemstack;
}
} }