mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 11:40:29 +00:00
Fix Pocket API working outside of player inventory
This makes Pocket API not equip/unequip upgrades when the pocket computer is outside of the player inventory (e.g. dragging, dropped, placed in a chest).
This commit is contained in:
parent
1290a4402c
commit
ba823bae13
@ -12,6 +12,7 @@ import dan200.computercraft.api.lua.LuaException;
|
|||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
import dan200.computercraft.shared.PocketUpgrades;
|
import dan200.computercraft.shared.PocketUpgrades;
|
||||||
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
||||||
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@ -66,6 +67,12 @@ public class PocketAPI implements ILuaAPI
|
|||||||
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
|
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
|
||||||
InventoryPlayer inventory = player.inventory;
|
InventoryPlayer inventory = player.inventory;
|
||||||
|
|
||||||
|
int computerID = m_computer.getID();
|
||||||
|
if ( !pocketComputerExists( inventory.mainInventory, computerID ) && !pocketComputerExists( inventory.offHandInventory, computerID ) )
|
||||||
|
{
|
||||||
|
throw new LuaException( "Cannot find pocket computer" );
|
||||||
|
}
|
||||||
|
|
||||||
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
|
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
|
||||||
|
|
||||||
// Attempt to find the upgrade, starting in the main segment, and then looking in the opposite
|
// Attempt to find the upgrade, starting in the main segment, and then looking in the opposite
|
||||||
@ -109,6 +116,12 @@ public class PocketAPI implements ILuaAPI
|
|||||||
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
|
EntityPlayer player = (EntityPlayer) m_computer.getEntity();
|
||||||
InventoryPlayer inventory = player.inventory;
|
InventoryPlayer inventory = player.inventory;
|
||||||
|
|
||||||
|
int computerID = m_computer.getID();
|
||||||
|
if ( !pocketComputerExists( inventory.mainInventory, computerID ) && !pocketComputerExists( inventory.offHandInventory, computerID ) )
|
||||||
|
{
|
||||||
|
throw new LuaException( "Cannot find pocket computer" );
|
||||||
|
}
|
||||||
|
|
||||||
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
|
IPocketUpgrade previousUpgrade = m_computer.getUpgrade();
|
||||||
|
|
||||||
if( previousUpgrade == null ) throw new LuaException( "Nothing to unequip" );
|
if( previousUpgrade == null ) throw new LuaException( "Nothing to unequip" );
|
||||||
@ -155,4 +168,20 @@ public class PocketAPI implements ILuaAPI
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean pocketComputerExists( NonNullList<ItemStack> inv, int computerID )
|
||||||
|
{
|
||||||
|
for( ItemStack invStack : inv )
|
||||||
|
{
|
||||||
|
if( !invStack.isEmpty() && invStack.getItem() instanceof ItemPocketComputer )
|
||||||
|
{
|
||||||
|
if( ComputerCraft.Items.pocketComputer.getComputerID( invStack ) == computerID )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user