|
| 1 | +package com.amronos.createaddoncompatibility.mixin; |
| 2 | + |
| 3 | +import com.amronos.createaddoncompatibility.data.tags.ForgeTags; |
| 4 | +import com.drmangotea.tfmg.blocks.machines.metal_processing.blast_furnace.BlastFurnaceOutputBlockEntity; |
| 5 | +import com.drmangotea.tfmg.registry.TFMGItems; |
| 6 | +import com.simibubi.create.foundation.item.SmartInventory; |
| 7 | +import net.minecraft.world.entity.item.ItemEntity; |
| 8 | +import net.minecraft.world.item.ItemStack; |
| 9 | +import org.spongepowered.asm.mixin.Mixin; |
| 10 | +import org.spongepowered.asm.mixin.Pseudo; |
| 11 | +import org.spongepowered.asm.mixin.Shadow; |
| 12 | +import org.spongepowered.asm.mixin.Unique; |
| 13 | +import org.spongepowered.asm.mixin.injection.At; |
| 14 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 15 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +@Pseudo |
| 21 | +@Mixin(BlastFurnaceOutputBlockEntity.class) |
| 22 | +public class MixinBlastFurnaceOutputBlockEntity { |
| 23 | + @Shadow |
| 24 | + public SmartInventory fuelInventory; |
| 25 | + @Shadow |
| 26 | + public SmartInventory inputInventory; |
| 27 | + |
| 28 | + @Unique |
| 29 | + public SmartInventory createaddoncompatibility$previousFuelInventory; |
| 30 | + @Unique |
| 31 | + public SmartInventory createaddoncompatibility$previousInputInventory; |
| 32 | + |
| 33 | + @Inject(remap = false, method = "acceptInsertedItems", at = @At(value = "HEAD")) |
| 34 | + private void savePreviousInventory(CallbackInfo info){ |
| 35 | + createaddoncompatibility$previousFuelInventory = fuelInventory; |
| 36 | + createaddoncompatibility$previousInputInventory = inputInventory; |
| 37 | + } |
| 38 | + |
| 39 | + @Inject(remap = false, method = "acceptInsertedItems", at = @At(value = "TAIL"), locals = LocalCapture.CAPTURE_FAILSOFT) |
| 40 | + private void acceptInsertedItems(CallbackInfo info, List<ItemEntity> itemsToPick) { |
| 41 | + fuelInventory = createaddoncompatibility$previousFuelInventory; |
| 42 | + inputInventory = createaddoncompatibility$previousInputInventory; |
| 43 | + for (ItemEntity itemEntity : itemsToPick) { |
| 44 | + ItemStack itemStack = itemEntity.getItem(); |
| 45 | + int count; |
| 46 | + int freeSpace2; |
| 47 | + if (itemStack.is(ForgeTags.Items.COKE_DUST)) { |
| 48 | + freeSpace2 = this.fuelInventory.getStackInSlot(0).getMaxStackSize() - this.fuelInventory.getStackInSlot(0).getCount(); |
| 49 | + count = itemStack.getCount(); |
| 50 | + if (count > freeSpace2) { |
| 51 | + itemStack.setCount(itemStack.getCount() - freeSpace2); |
| 52 | + this.fuelInventory.setItem(0, new ItemStack(TFMGItems.COAL_COKE_DUST.get(), this.fuelInventory.getStackInSlot(0).getCount() + freeSpace2)); |
| 53 | + } else { |
| 54 | + this.fuelInventory.setItem(0, new ItemStack(TFMGItems.COAL_COKE_DUST.get(), this.fuelInventory.getStackInSlot(0).getCount() + itemStack.getCount())); |
| 55 | + itemEntity.discard(); |
| 56 | + } |
| 57 | + } else { |
| 58 | + if (itemStack.getCount() == 1) { |
| 59 | + itemStack.setCount(2); |
| 60 | + itemEntity.setItem(itemStack); |
| 61 | + } |
| 62 | + |
| 63 | + freeSpace2 = this.inputInventory.getStackInSlot(0).getMaxStackSize() - this.inputInventory.getStackInSlot(0).getCount(); |
| 64 | + count = itemStack.getCount(); |
| 65 | + if (this.inputInventory.isEmpty() || this.inputInventory.getItem(0).is(itemStack.getItem())) { |
| 66 | + if (count > freeSpace2) { |
| 67 | + itemStack.setCount(itemStack.getCount() - freeSpace2); |
| 68 | + this.inputInventory.setItem(0, new ItemStack(itemStack.getItem(), this.inputInventory.getStackInSlot(0).getCount() + freeSpace2)); |
| 69 | + } else { |
| 70 | + this.inputInventory.setItem(0, new ItemStack(itemStack.getItem(), this.inputInventory.getStackInSlot(0).getCount() + itemStack.getCount())); |
| 71 | + itemEntity.discard(); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments