Skip to content

Commit

Permalink
Initial work on new inventory system
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Jan 4, 2025
1 parent 3fbd521 commit ce0fab9
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cn.nukkit.network.protocol.types;

import lombok.ToString;

@ToString
public class ItemStackRequest {
public int requestId;
public ItemStackRequestAction[] actions;
public String[] filterStrings;
public int filterStringCause;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cn.nukkit.network.protocol.types;

public interface ItemStackRequestAction {
ItemStackRequestActionType getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.nukkit.network.protocol.types;

public enum ItemStackRequestActionType {
TAKE,
PLACE,
SWAP,
DROP,
DESTROY,
CONSUME,
CREATE,
PLACE_IN_ITEM_CONTAINER,
TAKE_FROM_ITEM_CONTAINER,
LAB_TABLE_COMBINE,
BEACON_PAYMENT,
MINE_BLOCK,
CRAFT_RECIPE,
CRAFT_RECIPE_AUTO,
CRAFT_CREATIVE,
CRAFT_RECIPE_OPTIONAL,
CRAFT_REPAIR_AND_DISENCHANT,
CRAFT_LOOM,
CRAFT_NON_IMPLEMENTED_DEPRECATED,
CRAFT_RESULTS_DEPRECATED,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cn.nukkit.network.protocol.types;

import lombok.ToString;

@ToString
public class ItemStackResponse {
public static final int RESULT_OK = 0;
public static final int RESULT_ERROR = 1;

private static final ItemStackResponseContainerInfo[] EMPTY_CONTAINERS = new ItemStackResponseContainerInfo[0];

public int result = RESULT_OK;
public int requestId;
public ItemStackResponseContainerInfo[] containerInfos = EMPTY_CONTAINERS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cn.nukkit.network.protocol.types;

import lombok.ToString;

import javax.annotation.Nullable;

@ToString
public class ItemStackResponseContainerInfo {
private static final ItemStackResponseSlotInfo[] EMPTY_SLOTS = new ItemStackResponseSlotInfo[0];

public int containerId;
/**
* @since 1.21.20
*/
@Nullable
public Integer dynamicContainerId;
public ItemStackResponseSlotInfo[] slots = EMPTY_SLOTS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.nukkit.network.protocol.types;

import lombok.ToString;

@ToString
public class ItemStackResponseSlotInfo {
public int slot;
public int hotbarSlot;
public int count;
public int itemStackId;
/**
* @since 1.16.200
*/
public String customName = "";
/**
* @since 1.21.50
*/
public String filteredCustomName = "";
/**
* @since 1.16.210
*/
public int durabilityCorrection;
}
12 changes: 10 additions & 2 deletions src/main/java/cn/nukkit/utils/BinaryStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import cn.nukkit.nbt.tag.Tag;
import cn.nukkit.network.protocol.BossEventPacket.BossBarColor;
import cn.nukkit.network.protocol.types.EntityLink;
import cn.nukkit.network.protocol.types.ItemStackRequest;
import cn.nukkit.network.protocol.types.ItemStackResponse;
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
Expand Down Expand Up @@ -1349,8 +1351,14 @@ public int getItemNetworkId(BinaryStream stream, Item item) {
/**
* @since 1.16.0
*/
public int getItemStackRequest(BinaryStream stream) { //TODO: server authoritative inventory
return -1;
public ItemStackRequest getItemStackRequest(BinaryStream stream) {
return null;
}

/**
* @since 1.16.0
*/
public void putItemStackResponse(BinaryStream stream, ItemStackResponse response) {
}

public final int getCommandParameterTypeId(CommandParamType type) {
Expand Down

0 comments on commit ce0fab9

Please sign in to comment.