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
*/
public static Entity clientConstructInInventoryItem(Entity parentContainer, String type){
//sanity checks
boolean hasInventory = InventoryUtils.hasNaturalInventory(parentContainer);
if(hasInventory){
if(!InventoryUtils.hasNaturalInventory(parentContainer)){
return null;
}
//if we pass sanity checks, actually perform transform
//get inventory
//for the moment we're just gonna get natural inventory
@ -392,9 +392,6 @@ public class ClientInventoryState implements BehaviorTree {
//return
return inventoryItem;
}
//if we fail, return null
return null;
}
/**
* 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
*/
public static Entity serverAddToNatural(Entity creature, Entity item){
boolean itemIsItem = ItemUtils.isItem(item);
boolean hasInventory = InventoryUtils.hasNaturalInventory(creature);
//check if the item is already in an inventory
boolean itemIsInInventory = ItemUtils.itemIsInInventory(item);
if(itemIsItem && hasInventory){
if(!ItemUtils.isItem(item)){
return null;
}
if(InventoryUtils.hasNaturalInventory(creature)){
return null;
}
//get 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
@ -438,7 +439,7 @@ public class ServerInventoryState implements BehaviorTree {
//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
Entity inventoryItem = item;
if(!itemIsInInventory){
if(!ItemUtils.itemIsInInventory(item)){
inventoryItem = ItemUtils.serverRecreateContainerItem(item, creature);
ServerEntityUtils.destroyEntity(item);
}
@ -473,8 +474,6 @@ public class ServerInventoryState implements BehaviorTree {
ServerScriptUtils.fireSignalOnEntity(creature, "itemAddToNatural", item.getId(), inventoryItem.getId());
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
@ -488,20 +487,19 @@ public class ServerInventoryState implements BehaviorTree {
if(item == null){
throw new Error("Provided null item!");
}
//verify creature is creature, item is item, inventory exists, and item is in inventory
boolean itemIsItem = ItemUtils.isItem(item);
boolean hasNaturalInventory = InventoryUtils.hasNaturalInventory(creature);
boolean hasEquipInventory = InventoryUtils.hasEquipInventory(creature);
//check if the item is in an inventory
boolean itemIsInInventory = ItemUtils.itemIsInInventory(item);
if(itemIsItem && itemIsInInventory){
if(hasNaturalInventory){
if(!ItemUtils.isItem(item)){
return;
}
if(!ItemUtils.itemIsInInventory(item)){
return;
}
if(InventoryUtils.hasNaturalInventory(creature)){
//get inventory
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(creature);
//remove item from inventory
inventory.removeItem(item);
}
if(hasEquipInventory){
if(InventoryUtils.hasEquipInventory(creature)){
//get inventory
RelationalInventoryState inventory = InventoryUtils.getEquipInventory(creature);
//get inventory slot
@ -554,7 +552,6 @@ public class ServerInventoryState implements BehaviorTree {
//activate gravity
GravityUtils.serverAttemptActivateGravity(inWorldItem);
}
}
//need creature so we can figure out where to drop the item
public static void serverAttemptEjectItem(Entity creature, Entity item){