flip inventory util error checking paradigm
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-14 11:41:56 -04:00
parent 0cb08e3d42
commit 2173f96b0b
2 changed files with 130 additions and 136 deletions

View File

@ -369,9 +369,9 @@ public class ClientInventoryState implements BehaviorTree {
* @return The in-inventory item entity * @return The in-inventory item entity
*/ */
public static Entity clientConstructInInventoryItem(Entity parentContainer, String type){ public static Entity clientConstructInInventoryItem(Entity parentContainer, String type){
//sanity checks if(!InventoryUtils.hasNaturalInventory(parentContainer)){
boolean hasInventory = InventoryUtils.hasNaturalInventory(parentContainer); return null;
if(hasInventory){ }
//if we pass sanity checks, actually perform transform //if we pass sanity checks, actually perform transform
//get inventory //get inventory
//for the moment we're just gonna get natural inventory //for the moment we're just gonna get natural inventory
@ -392,9 +392,6 @@ public class ClientInventoryState implements BehaviorTree {
//return //return
return inventoryItem; return inventoryItem;
} }
//if we fail, return null
return null;
}
/** /**
* Attempts ejecting an item from a client's inventory * Attempts ejecting an item from a client's inventory

View File

@ -426,11 +426,12 @@ public class ServerInventoryState implements BehaviorTree {
* @return The in-inventory item * @return The in-inventory item
*/ */
public static Entity serverAddToNatural(Entity creature, Entity item){ public static Entity serverAddToNatural(Entity creature, Entity item){
boolean itemIsItem = ItemUtils.isItem(item); if(!ItemUtils.isItem(item)){
boolean hasInventory = InventoryUtils.hasNaturalInventory(creature); return null;
//check if the item is already in an inventory }
boolean itemIsInInventory = ItemUtils.itemIsInInventory(item); if(InventoryUtils.hasNaturalInventory(creature)){
if(itemIsItem && hasInventory){ return null;
}
//get inventory //get inventory
//for the moment we're just gonna get natural inventory //for the moment we're just gonna get natural inventory
//later we'll need to search through all creature inventories to find the item //later we'll need to search through all creature inventories to find the item
@ -438,7 +439,7 @@ public class ServerInventoryState implements BehaviorTree {
//destroy in-world entity and create in-inventory item //destroy in-world entity and create in-inventory item
//we're doing this so that we're not constantly sending networking messages for invisible entities attached to the player //we're doing this so that we're not constantly sending networking messages for invisible entities attached to the player
Entity inventoryItem = item; Entity inventoryItem = item;
if(!itemIsInInventory){ if(!ItemUtils.itemIsInInventory(item)){
inventoryItem = ItemUtils.serverRecreateContainerItem(item, creature); inventoryItem = ItemUtils.serverRecreateContainerItem(item, creature);
ServerEntityUtils.destroyEntity(item); ServerEntityUtils.destroyEntity(item);
} }
@ -473,8 +474,6 @@ public class ServerInventoryState implements BehaviorTree {
ServerScriptUtils.fireSignalOnEntity(creature, "itemAddToNatural", item.getId(), inventoryItem.getId()); ServerScriptUtils.fireSignalOnEntity(creature, "itemAddToNatural", item.getId(), inventoryItem.getId());
return inventoryItem; return inventoryItem;
} }
return null;
}
/** /**
* Attempts the transform to eject an item from an inventory, if this is the server it has added side effect of sending packets on success * Attempts the transform to eject an item from an inventory, if this is the server it has added side effect of sending packets on success
@ -488,20 +487,19 @@ public class ServerInventoryState implements BehaviorTree {
if(item == null){ if(item == null){
throw new Error("Provided null item!"); throw new Error("Provided null item!");
} }
//verify creature is creature, item is item, inventory exists, and item is in inventory if(!ItemUtils.isItem(item)){
boolean itemIsItem = ItemUtils.isItem(item); return;
boolean hasNaturalInventory = InventoryUtils.hasNaturalInventory(creature); }
boolean hasEquipInventory = InventoryUtils.hasEquipInventory(creature); if(!ItemUtils.itemIsInInventory(item)){
//check if the item is in an inventory return;
boolean itemIsInInventory = ItemUtils.itemIsInInventory(item); }
if(itemIsItem && itemIsInInventory){ if(InventoryUtils.hasNaturalInventory(creature)){
if(hasNaturalInventory){
//get inventory //get inventory
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(creature); UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(creature);
//remove item from inventory //remove item from inventory
inventory.removeItem(item); inventory.removeItem(item);
} }
if(hasEquipInventory){ if(InventoryUtils.hasEquipInventory(creature)){
//get inventory //get inventory
RelationalInventoryState inventory = InventoryUtils.getEquipInventory(creature); RelationalInventoryState inventory = InventoryUtils.getEquipInventory(creature);
//get inventory slot //get inventory slot
@ -554,7 +552,6 @@ public class ServerInventoryState implements BehaviorTree {
//activate gravity //activate gravity
GravityUtils.serverAttemptActivateGravity(inWorldItem); GravityUtils.serverAttemptActivateGravity(inWorldItem);
} }
}
//need creature so we can figure out where to drop the item //need creature so we can figure out where to drop the item
public static void serverAttemptEjectItem(Entity creature, Entity item){ public static void serverAttemptEjectItem(Entity creature, Entity item){