Skip to content

Commit

Permalink
Resolves #190
Browse files Browse the repository at this point in the history
  • Loading branch information
balugaq committed Nov 24, 2024
1 parent e322cc3 commit e3b1954
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ private static void quickTransfer(BlockMenu blockMenu, Location location, Player
PersistentQuantumStorageType.TYPE
);

if (quantumCache == null) {
quantumCache = DataTypeMethods.getCustom(
meta,
Keys.QUANTUM_STORAGE_INSTANCE2,
PersistentQuantumStorageType.TYPE
);
}

if (quantumCache == null) {
quantumCache = DataTypeMethods.getCustom(
meta,
Keys.QUANTUM_STORAGE_INSTANCE3,
PersistentQuantumStorageType.TYPE
);
}

switch (mode) {
case FROM_QUANTUM -> {
if (quantumCache == null || quantumCache.getItemStack() == null || quantumCache.getAmount() <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,28 @@ private static void updateItem(Player player) {
player.sendMessage(Networks.getLocalizationService().getString("messages.commands.cannot-update-cargo-storage-unit"));
} else if (slimefunItem instanceof NetworkQuantumStorage) {
final ItemMeta meta = itemInHand.getItemMeta();
final QuantumCache quantumCache = DataTypeMethods.getCustom(
QuantumCache quantumCache = DataTypeMethods.getCustom(
meta,
Keys.QUANTUM_STORAGE_INSTANCE,
PersistentQuantumStorageType.TYPE
);

if (quantumCache == null) {
quantumCache = DataTypeMethods.getCustom(
meta,
Keys.QUANTUM_STORAGE_INSTANCE2,
PersistentQuantumStorageType.TYPE
);
}

if (quantumCache == null) {
quantumCache = DataTypeMethods.getCustom(
meta,
Keys.QUANTUM_STORAGE_INSTANCE3,
PersistentQuantumStorageType.TYPE
);
}

if (quantumCache == null || quantumCache.getItemStack() == null) {
itemInHand.setItemMeta(SlimefunItem.getById(currentId).getItem().getItemMeta());
player.sendMessage(Networks.getLocalizationService().getString("messages.commands.updated-item"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,15 @@ protected void onBreak(@Nonnull BlockBreakEvent event) {
protected void onPlace(@Nonnull BlockPlaceEvent event) {
final ItemStack itemStack = event.getItemInHand();
final ItemMeta itemMeta = itemStack.getItemMeta();
final QuantumCache cache = DataTypeMethods.getCustom(itemMeta, Keys.QUANTUM_STORAGE_INSTANCE, PersistentQuantumStorageType.TYPE);
QuantumCache cache = DataTypeMethods.getCustom(itemMeta, Keys.QUANTUM_STORAGE_INSTANCE, PersistentQuantumStorageType.TYPE);

if (cache == null) {
cache = DataTypeMethods.getCustom(itemMeta, Keys.QUANTUM_STORAGE_INSTANCE2, PersistentQuantumStorageType.TYPE);
}

if (cache == null) {
cache = DataTypeMethods.getCustom(itemMeta, Keys.QUANTUM_STORAGE_INSTANCE3, PersistentQuantumStorageType.TYPE);
}

if (cache == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ public void craft(@Nonnull BlockMenu menu, @Nonnull Player player) {
final ItemMeta oldMeta = coreItem.getItemMeta();
final ItemMeta newMeta = crafted.getItemMeta();
final NetworkQuantumStorage newQuantum = (NetworkQuantumStorage) SlimefunItem.getByItem(crafted);
final QuantumCache oldCache = DataTypeMethods.getCustom(oldMeta, Keys.QUANTUM_STORAGE_INSTANCE, PersistentQuantumStorageType.TYPE);
QuantumCache oldCache = DataTypeMethods.getCustom(oldMeta, Keys.QUANTUM_STORAGE_INSTANCE, PersistentQuantumStorageType.TYPE);

if (oldCache == null) {
oldCache = DataTypeMethods.getCustom(oldMeta, Keys.QUANTUM_STORAGE_INSTANCE2, PersistentQuantumStorageType.TYPE);
}

if (oldCache == null) {
oldCache = DataTypeMethods.getCustom(oldMeta, Keys.QUANTUM_STORAGE_INSTANCE3, PersistentQuantumStorageType.TYPE);
}

if (oldCache != null) {
final QuantumCache newCache = new QuantumCache(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,29 @@ public NetworkCard(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recip
final SlimefunItem cardItem = SlimefunItem.getByItem(card);
if (cardItem instanceof NetworkCard networkCard) {
final ItemMeta cardMeta = card.getItemMeta();
final CardInstance cardInstance = DataTypeMethods.getCustom(
CardInstance cardInstance = DataTypeMethods.getCustom(
cardMeta,
Keys.CARD_INSTANCE,
PersistentCardInstanceType.TYPE,
new CardInstance(null, 0, networkCard.getSize())
PersistentCardInstanceType.TYPE
);

if (cardInstance == null) {
cardInstance = DataTypeMethods.getCustom(
cardMeta,
Keys.CARD_INSTANCE2,
PersistentCardInstanceType.TYPE
);
}

if (cardInstance == null) {
cardInstance = DataTypeMethods.getCustom(
cardMeta,
Keys.CARD_INSTANCE3,
PersistentCardInstanceType.TYPE,
new CardInstance(null, 0, networkCard.getSize())
);
}

if (cardInstance.getAmount() > 0) {
e.getPlayer().sendMessage(Networks.getLocalizationService().getString("messages.unsupported-operation.memory_card.not_empty"));
return;
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/io/github/sefiraat/networks/utils/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@
@Data
@UtilityClass
public class Keys {


public static final String NETWORKS_ID = "networks";
public static final String NETWORKS_CHANGED_ID = "networks-changed";
public static final NamespacedKey ON_COOLDOWN = newKey("cooldown");
public static final NamespacedKey ON_COOLDOWN2 = customNewKey(NETWORKS_ID, "cooldown");
public static final NamespacedKey ON_COOLDOWN3 = customNewKey(NETWORKS_CHANGED_ID, "cooldown");
public static final NamespacedKey CARD_INSTANCE = newKey("ntw_card");
public static final NamespacedKey CARD_INSTANCE2 = customNewKey(NETWORKS_ID, "ntw_card");
public static final NamespacedKey CARD_INSTANCE3 = customNewKey(NETWORKS_CHANGED_ID, "ntw_card");
public static final NamespacedKey QUANTUM_STORAGE_INSTANCE = newKey("quantum_storage");
public static final NamespacedKey QUANTUM_STORAGE_INSTANCE2 = customNewKey(NETWORKS_ID, "quantum_storage");
public static final NamespacedKey QUANTUM_STORAGE_INSTANCE3 = customNewKey(NETWORKS_CHANGED_ID, "quantum_storage");
public static final NamespacedKey BLUEPRINT_INSTANCE = newKey("ntw_blueprint");
public static final NamespacedKey BLUEPRINT_INSTANCE2 = customNewKey("networks", "ntw_blueprint");
public static final NamespacedKey BLUEPRINT_INSTANCE3 = customNewKey("networks-changed", "ntw_blueprint");
public static final NamespacedKey BLUEPRINT_INSTANCE2 = customNewKey(NETWORKS_ID, "ntw_blueprint");
public static final NamespacedKey BLUEPRINT_INSTANCE3 = customNewKey(NETWORKS_CHANGED_ID, "ntw_blueprint");
public static final NamespacedKey FACE = newKey("face");
public static final NamespacedKey FACE2 = customNewKey(NETWORKS_ID, "face");
public static final NamespacedKey FACE3 = customNewKey(NETWORKS_CHANGED_ID, "face");
public static final NamespacedKey ITEM = newKey("item");
public static final NamespacedKey ITEM2 = customNewKey(NETWORKS_ID, "item");
public static final NamespacedKey ITEM3 = customNewKey(NETWORKS_CHANGED_ID, "item");

public static final NamespacedKey AMOUNT = newKey("amount");
public static final NamespacedKey TRANSFER_MODE = newKey("transfer_mode");
public static final NamespacedKey STORAGE_UNIT_UPGRADE_TABLE = newKey("storage_upgrade_table");
public static final NamespacedKey STORAGE_UNIT_UPGRADE_TABLE_MODEL = newKey("storage_upgrade_table_model");
public static final NamespacedKey NETWORKSKEY = newKey("networkskey");
public static final NamespacedKey ITEM_MOVER_ITEM = newKey("item_mover_item");
public static final NamespacedKey ITEM_MOVER_AMOUNT = newKey("item_mover_amount");
public static final NamespacedKey EXPANSION_WORKBENCH = newKey("expansion_workbench");
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/io/github/sefiraat/networks/utils/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ public static void applyConfig(@Nonnull NetworkDirectional directional, @Nonnull

public static void applyConfig(@Nonnull NetworkDirectional directional, @Nonnull ItemStack itemStack, @Nonnull BlockMenu blockMenu, @Nonnull Player player) {
final ItemMeta itemMeta = itemStack.getItemMeta();
final ItemStack[] templateStacks = DataTypeMethods.getCustom(itemMeta, Keys.ITEM, DataType.ITEM_STACK_ARRAY);
final String string = DataTypeMethods.getCustom(itemMeta, Keys.FACE, DataType.STRING);
ItemStack[] templateStacks = DataTypeMethods.getCustom(itemMeta, Keys.ITEM, DataType.ITEM_STACK_ARRAY);
if (templateStacks == null) {
templateStacks = DataTypeMethods.getCustom(itemMeta, Keys.ITEM2, DataType.ITEM_STACK_ARRAY);
}

if (templateStacks == null) {
templateStacks = DataTypeMethods.getCustom(itemMeta, Keys.ITEM3, DataType.ITEM_STACK_ARRAY);
}

String string = DataTypeMethods.getCustom(itemMeta, Keys.FACE, DataType.STRING);
if (string == null) {
string = DataTypeMethods.getCustom(itemMeta, Keys.FACE2, DataType.STRING);
}

if (string == null) {
string = DataTypeMethods.getCustom(itemMeta, Keys.FACE3, DataType.STRING);
}

if (string == null) {
player.sendMessage(Networks.getLocalizationService().getString("messages.unsupported-operation.configurator.facing_not_found"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,13 @@ public static void putOnCooldown(ItemStack itemStack, int durationInSeconds) {
public static boolean isOnCooldown(ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta != null) {
long cooldownUntil = PersistentDataAPI.getLong(itemMeta, Keys.ON_COOLDOWN, 0);
long cooldownUntil = PersistentDataAPI.getLong(itemMeta, Keys.ON_COOLDOWN, -1);
if (cooldownUntil == -1) {
cooldownUntil = PersistentDataAPI.getLong(itemMeta, Keys.ON_COOLDOWN2, -1);
}
if (cooldownUntil == -1) {
cooldownUntil = PersistentDataAPI.getLong(itemMeta, Keys.ON_COOLDOWN3, 0);
}
return System.currentTimeMillis() < cooldownUntil;
}
return false;
Expand Down

0 comments on commit e3b1954

Please sign in to comment.