Skip to content
This repository was archived by the owner on Nov 18, 2023. It is now read-only.

Commit 97c8f24

Browse files
committed
Add shift clicking for extractor attachment container
1 parent 0871ed7 commit 97c8f24

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

src/main/java/com/raoulvdberge/refinedpipes/container/BaseContainer.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ protected BaseContainer(@Nullable ContainerType<?> type, int windowId, PlayerEnt
2929
}
3030

3131
protected void addPlayerInventory(int xInventory, int yInventory) {
32-
int id = 0;
32+
int id = 9;
33+
34+
for (int y = 0; y < 3; y++) {
35+
for (int x = 0; x < 9; x++) {
36+
addSlot(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18));
37+
38+
id++;
39+
}
40+
}
41+
42+
id = 0;
3343

3444
for (int i = 0; i < 9; i++) {
3545
int x = xInventory + i * 18;
@@ -39,14 +49,6 @@ protected void addPlayerInventory(int xInventory, int yInventory) {
3949

4050
id++;
4151
}
42-
43-
for (int y = 0; y < 3; y++) {
44-
for (int x = 0; x < 9; x++) {
45-
addSlot(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18));
46-
47-
id++;
48-
}
49-
}
5052
}
5153

5254
@Override

src/main/java/com/raoulvdberge/refinedpipes/container/ExtractorAttachmentContainer.java

+62
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachmentType;
1111
import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.RedstoneMode;
1212
import com.raoulvdberge.refinedpipes.network.pipe.attachment.extractor.RoutingMode;
13+
import com.raoulvdberge.refinedpipes.util.FluidUtil;
1314
import net.minecraft.entity.player.PlayerEntity;
15+
import net.minecraft.inventory.container.Slot;
16+
import net.minecraft.item.ItemStack;
1417
import net.minecraft.util.Direction;
1518
import net.minecraft.util.math.BlockPos;
19+
import net.minecraftforge.fluids.FluidStack;
20+
import net.minecraftforge.items.ItemHandlerHelper;
1621
import net.minecraftforge.items.ItemStackHandler;
22+
import net.minecraftforge.items.SlotItemHandler;
1723

1824
public class ExtractorAttachmentContainer extends BaseContainer {
1925
private final BlockPos pos;
@@ -131,4 +137,60 @@ public void setExactMode(boolean exactMode) {
131137

132138
RefinedPipes.NETWORK.sendToServer(new ChangeExactModeMessage(pos, dir, exactMode));
133139
}
140+
141+
@Override
142+
public ItemStack transferStackInSlot(PlayerEntity player, int index) {
143+
Slot slot = inventorySlots.get(index);
144+
if (slot != null && slot.getHasStack() && index < 9 * 4) {
145+
for (int i = 9 * 4; i < inventorySlots.size(); ++i) {
146+
Slot filterSlot = inventorySlots.get(i);
147+
148+
if (filterSlot instanceof FluidFilterSlot) {
149+
FluidFilterSlot fluidSlot = (FluidFilterSlot) filterSlot;
150+
151+
if (fluidSlot.getFluidInventory().getFluid(fluidSlot.getSlotIndex()).isEmpty()) {
152+
FluidStack toInsert = FluidUtil.getFromStack(slot.getStack(), true).getValue();
153+
154+
boolean foundExistingFluid = false;
155+
156+
for (int j = 0; j < fluidSlot.getFluidInventory().getSlots(); ++j) {
157+
if (fluidSlot.getFluidInventory().getFluid(j).isFluidEqual(toInsert)) {
158+
foundExistingFluid = true;
159+
break;
160+
}
161+
}
162+
163+
if (!foundExistingFluid) {
164+
fluidSlot.onContainerClicked(slot.getStack());
165+
}
166+
167+
break;
168+
}
169+
} else if (filterSlot instanceof SlotItemHandler) {
170+
SlotItemHandler itemSlot = (SlotItemHandler) filterSlot;
171+
172+
if (!itemSlot.getHasStack()) {
173+
ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot.getStack(), 1);
174+
175+
boolean foundExistingItem = false;
176+
177+
for (int j = 0; j < itemSlot.getItemHandler().getSlots(); ++j) {
178+
if (ItemStack.areItemStacksEqual(itemSlot.getItemHandler().getStackInSlot(j), toInsert)) {
179+
foundExistingItem = true;
180+
break;
181+
}
182+
}
183+
184+
if (!foundExistingItem) {
185+
itemSlot.putStack(toInsert);
186+
}
187+
188+
break;
189+
}
190+
}
191+
}
192+
}
193+
194+
return ItemStack.EMPTY;
195+
}
134196
}

0 commit comments

Comments
 (0)