2020import net .minecraft .item .ItemStack ;
2121import net .minecraftforge .fluids .FluidStack ;
2222import net .minecraftforge .fluids .capability .CapabilityFluidHandler ;
23+ import net .minecraftforge .fml .common .Optional ;
2324import net .minecraftforge .items .ItemHandlerHelper ;
2425import org .spongepowered .asm .mixin .Final ;
2526import org .spongepowered .asm .mixin .Intrinsic ;
2627import org .spongepowered .asm .mixin .Mixin ;
2728import org .spongepowered .asm .mixin .Shadow ;
29+ import org .spongepowered .asm .mixin .Unique ;
2830
2931@ Mixin (value = ContainerCellWorkbench .class , remap = false )
3032public abstract class MixinContainerCellWorkbench extends ContainerUpgradeable {
@@ -39,58 +41,66 @@ public MixinContainerCellWorkbench(final InventoryPlayer ip, final IUpgradeableH
3941
4042 @ Intrinsic
4143 public void doAction (final EntityPlayerMP player , final InventoryAction action , final int slotId , final long id ) {
42- if (this .workBench .getCell () instanceof ItemViewCell ) {
43- final Slot slot = getSlot (slotId );
44- final ItemStack stack = player .inventory .getItemStack ();
45- if (slot instanceof SlotFake && !stack .isEmpty ()
46- && stack .hasCapability (CapabilityFluidHandler .FLUID_HANDLER_ITEM_CAPABILITY , null ) && Util .getFluidFromItem (stack ) != null ) {
47- FluidStack fluid = null ;
48- switch (action ) {
49- case PICKUP_OR_SET_DOWN :
50- fluid = Util .getFluidFromItem (stack );
51- slot .putStack (FakeFluids .packFluid2Drops (fluid ));
52- break ;
53- case SPLIT_OR_PLACE_SINGLE :
54- fluid = Util .getFluidFromItem (ItemHandlerHelper .copyStackWithSize (stack , 1 ));
55- final FluidStack origin = FakeItemRegister .getStack (slot .getStack ());
56- if (fluid != null && fluid .equals (origin )) {
57- fluid .amount += origin .amount ;
58- if (fluid .amount <= 0 ) fluid = null ;
59- }
60- slot .putStack (FakeFluids .packFluid2Drops (fluid ));
61- break ;
44+ if (id != 0 || slotId < 0 || slotId >= this .inventorySlots .size ()
45+ || !(this .workBench .getCell () instanceof ItemViewCell )) {
46+ super .doAction (player , action , slotId , id );
47+ return ;
48+ }
49+ final Slot slot = getSlot (slotId );
50+ final ItemStack stack = player .inventory .getItemStack ();
51+ if (slot instanceof SlotFake && !stack .isEmpty ()
52+ && stack .hasCapability (CapabilityFluidHandler .FLUID_HANDLER_ITEM_CAPABILITY , null ) && Util .getFluidFromItem (stack ) != null ) {
53+ FluidStack fluid = null ;
54+ switch (action ) {
55+ case PICKUP_OR_SET_DOWN -> {
56+ fluid = Util .getFluidFromItem (stack );
57+ slot .putStack (FakeFluids .packFluid2Drops (fluid ));
6258 }
63- if (fluid == null ) {
64- super .doAction (player , action , slotId , id );
65- return ;
59+ case SPLIT_OR_PLACE_SINGLE -> {
60+ fluid = Util .getFluidFromItem (ItemHandlerHelper .copyStackWithSize (stack , 1 ));
61+ final FluidStack origin = FakeItemRegister .getStack (slot .getStack ());
62+ if (fluid != null && fluid .equals (origin )) {
63+ fluid .amount += origin .amount ;
64+ if (fluid .amount <= 0 ) fluid = null ;
65+ }
66+ slot .putStack (FakeFluids .packFluid2Drops (fluid ));
6667 }
67- return ;
6868 }
69- if (ModAndClassUtil .GAS && slot instanceof SlotFake && !stack .isEmpty ()
70- && stack .getItem () instanceof IGasItem && Util .getGasFromItem (stack ) != null ) {
71- GasStack gas = null ;
72- switch (action ) {
73- case PICKUP_OR_SET_DOWN :
74- gas = Util .getGasFromItem (stack );
75- slot .putStack (FakeGases .packGas2Drops (gas ));
76- break ;
77- case SPLIT_OR_PLACE_SINGLE :
78- gas = Util .getGasFromItem (ItemHandlerHelper .copyStackWithSize (stack , 1 ));
79- final GasStack origin = FakeItemRegister .getStack (slot .getStack ());
80- if (gas != null && gas .equals (origin )) {
81- gas .amount += origin .amount ;
82- if (gas .amount <= 0 ) gas = null ;
83- }
84- slot .putStack (FakeGases .packGas2Drops (gas ));
85- break ;
86- }
87- if (gas == null ) {
88- super .doAction (player , action , slotId , id );
89- return ;
90- }
69+ if (fluid == null ) {
70+ super .doAction (player , action , slotId , id );
9171 return ;
9272 }
73+ return ;
74+ }
75+ if (ModAndClassUtil .GAS && slot instanceof SlotFake && !stack .isEmpty ()
76+ && stack .getItem () instanceof IGasItem && Util .getGasFromItem (stack ) != null ) {
77+ mek$doAction (player , action , slotId , id , slot , stack );
78+ return ;
9379 }
9480 super .doAction (player , action , slotId , id );
9581 }
96- }
82+
83+ @ Unique
84+ @ Optional .Method (modid = "mekeng" )
85+ private void mek$doAction (EntityPlayerMP player , InventoryAction action , int slotId , long id , Slot slot , ItemStack stack ) {
86+ GasStack gas = null ;
87+ switch (action ) {
88+ case PICKUP_OR_SET_DOWN -> {
89+ gas = Util .getGasFromItem (stack );
90+ slot .putStack (FakeGases .packGas2Drops (gas ));
91+ }
92+ case SPLIT_OR_PLACE_SINGLE -> {
93+ gas = Util .getGasFromItem (ItemHandlerHelper .copyStackWithSize (stack , 1 ));
94+ final GasStack origin = FakeItemRegister .getStack (slot .getStack ());
95+ if (gas != null && gas .equals (origin )) {
96+ gas .amount += origin .amount ;
97+ if (gas .amount <= 0 ) gas = null ;
98+ }
99+ slot .putStack (FakeGases .packGas2Drops (gas ));
100+ }
101+ }
102+ if (gas == null ) {
103+ super .doAction (player , action , slotId , id );
104+ }
105+ }
106+ }
0 commit comments