generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Right click slots to save their positions
- Loading branch information
1 parent
4bb43a4
commit ef8cf94
Showing
7 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/direwolf20/justdirethings/common/containers/slots/InventoryHolderSlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.direwolf20.justdirethings.common.containers.slots; | ||
|
||
import net.neoforged.neoforge.items.IItemHandler; | ||
import net.neoforged.neoforge.items.SlotItemHandler; | ||
|
||
public class InventoryHolderSlot extends SlotItemHandler { | ||
public InventoryHolderSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition) { | ||
super(itemHandler, index, xPosition, yPosition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ava/com/direwolf20/justdirethings/common/network/data/InventoryHolderSaveSlotPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.direwolf20.justdirethings.common.network.data; | ||
|
||
import com.direwolf20.justdirethings.JustDireThings; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public record InventoryHolderSaveSlotPayload( | ||
int slot | ||
) implements CustomPacketPayload { | ||
public static final Type<InventoryHolderSaveSlotPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "inventory_holder_save_slot")); | ||
|
||
@Override | ||
public Type<InventoryHolderSaveSlotPayload> type() { | ||
return TYPE; | ||
} | ||
|
||
public static final StreamCodec<FriendlyByteBuf, InventoryHolderSaveSlotPayload> STREAM_CODEC = StreamCodec.composite( | ||
ByteBufCodecs.INT, InventoryHolderSaveSlotPayload::slot, | ||
InventoryHolderSaveSlotPayload::new | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
...a/com/direwolf20/justdirethings/common/network/handler/InventoryHolderSaveSlotPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.direwolf20.justdirethings.common.network.handler; | ||
|
||
import com.direwolf20.justdirethings.common.blockentities.InventoryHolderBE; | ||
import com.direwolf20.justdirethings.common.containers.basecontainers.BaseMachineContainer; | ||
import com.direwolf20.justdirethings.common.network.data.InventoryHolderSaveSlotPayload; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.neoforged.neoforge.network.handling.IPayloadContext; | ||
|
||
public class InventoryHolderSaveSlotPacket { | ||
public static final InventoryHolderSaveSlotPacket INSTANCE = new InventoryHolderSaveSlotPacket(); | ||
|
||
public static InventoryHolderSaveSlotPacket get() { | ||
return INSTANCE; | ||
} | ||
|
||
public void handle(final InventoryHolderSaveSlotPayload payload, final IPayloadContext context) { | ||
context.enqueueWork(() -> { | ||
Player sender = context.player(); | ||
AbstractContainerMenu container = sender.containerMenu; | ||
|
||
if (container instanceof BaseMachineContainer baseMachineContainer && baseMachineContainer.baseMachineBE instanceof InventoryHolderBE inventoryHolderBE) { | ||
inventoryHolderBE.addSavedItem(payload.slot()); | ||
} | ||
}); | ||
} | ||
} |