mirror of
https://github.com/GTNewHorizons/ThaumicEnergistics.git
synced 2026-10-25 20:32:27 +00:00
NEI Players Inventory Fix
Fixes #309: When shift clicking [?] from NEI, items will also be pulled from the players inventory if available.
This commit is contained in:
1 parent
7e54f83cd1
commit
e2ceefb8b1
8 files changed
+201
-71
No files matched your search
+4
-1
@@ -1,4 +1,7 @@
|
||||
04/21/2016 1.0.0.5 - Beta
|
||||
04/27/2016 1.0.0.6 - Beta
|
||||
Fixes #309: When shift clicking [?] from NEI, items will also be pulled from the players inventory if available.
|
||||
|
||||
04/21/2016 1.0.0.5 - Beta
|
||||
Fixes #303: A.C.T. result slot can no longer dupe items.
|
||||
Fixed issue of A.C.T. result slot improperly handling right clicks, issue was with underlying inventory, as it allowed 'partial' crafting results to be taken.
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ apply plugin: 'java'
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
version = "1.0.0.5"
|
||||
version = "1.0.0.6"
|
||||
group= "thaumicenergistics" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "thaumicenergistics"
|
||||
|
||||
|
||||
@@ -35,57 +35,57 @@ public class ThEGuiHandler
|
||||
/**
|
||||
* Singular ID of the essentia cell gui
|
||||
*/
|
||||
public static final int ESSENTIA_CELL_ID = ID_STEP_VALUE * 1;
|
||||
public static final int ESSENTIA_CELL_ID = ThEGuiHandler.ID_STEP_VALUE * 1;
|
||||
|
||||
/**
|
||||
* Base ID of the priority gui.
|
||||
* Add the ForgeDirection's side ordinal to this value.
|
||||
*/
|
||||
public static final int PRIORITY_ID = ID_STEP_VALUE * 2;
|
||||
public static final int PRIORITY_ID = ThEGuiHandler.ID_STEP_VALUE * 2;
|
||||
|
||||
/**
|
||||
* ID of the essentia cell workbench
|
||||
*/
|
||||
public static final int CELL_WORKBENCH_ID = ID_STEP_VALUE * 3;
|
||||
public static final int CELL_WORKBENCH_ID = ThEGuiHandler.ID_STEP_VALUE * 3;
|
||||
|
||||
/**
|
||||
* ID of the wireless terminal gui.
|
||||
*/
|
||||
public static final int WIRELESS_TERMINAL_ID = ID_STEP_VALUE * 4;
|
||||
public static final int WIRELESS_TERMINAL_ID = ThEGuiHandler.ID_STEP_VALUE * 4;
|
||||
|
||||
/**
|
||||
* ID of the arcane assembler gui.
|
||||
*/
|
||||
public static final int ARCANE_ASSEMBLER_ID = ID_STEP_VALUE * 5;
|
||||
public static final int ARCANE_ASSEMBLER_ID = ThEGuiHandler.ID_STEP_VALUE * 5;
|
||||
|
||||
/**
|
||||
* ID of the knowledge inscriber gui.
|
||||
*/
|
||||
public static final int KNOWLEDGE_INSCRIBER = ID_STEP_VALUE * 6;
|
||||
public static final int KNOWLEDGE_INSCRIBER = ThEGuiHandler.ID_STEP_VALUE * 6;
|
||||
|
||||
/**
|
||||
* ID of the knowledge inscriber gui.
|
||||
*/
|
||||
public static final int ESSENTIA_VIBRATION_CHAMBER = ID_STEP_VALUE * 7;
|
||||
public static final int ESSENTIA_VIBRATION_CHAMBER = ThEGuiHandler.ID_STEP_VALUE * 7;
|
||||
|
||||
/**
|
||||
* ID of the auto crafting amount bridge.
|
||||
* When calling this make sure the current container implements ICraftingIssuerContainer,
|
||||
* or extends AEBaseContainer with the target set to an ICraftingIssuerHost.
|
||||
*/
|
||||
public static final int AUTO_CRAFTING_AMOUNT = ID_STEP_VALUE * 8;
|
||||
public static final int AUTO_CRAFTING_AMOUNT = ThEGuiHandler.ID_STEP_VALUE * 8;
|
||||
|
||||
/**
|
||||
* ID of the auto crafting confirm bridge.
|
||||
* When calling this make sure the current container extends
|
||||
* AEBaseContainer with the target set to an ICraftingIssuerHost.
|
||||
*/
|
||||
public static final int AUTO_CRAFTING_CONFIRM = ID_STEP_VALUE * 9;
|
||||
public static final int AUTO_CRAFTING_CONFIRM = ThEGuiHandler.ID_STEP_VALUE * 9;
|
||||
|
||||
/**
|
||||
* ID of the distillation encoder.
|
||||
*/
|
||||
public static final int DISTILLATION_ENCODER = ID_STEP_VALUE * 10;
|
||||
public static final int DISTILLATION_ENCODER = ThEGuiHandler.ID_STEP_VALUE * 10;
|
||||
|
||||
/**
|
||||
* Extra data used for some GUI calls.
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ThaumicEnergistics
|
||||
/**
|
||||
* Current version of the mod.
|
||||
*/
|
||||
public static final String VERSION = "1.0.0.5"; // NOTE: don't forget to change the build.gradle file as well
|
||||
public static final String VERSION = "1.0.0.6"; // NOTE: don't forget to change the build.gradle file as well
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
|
||||
+14
-7
@@ -1556,19 +1556,26 @@ public class ContainerPartArcaneCraftingTerminal
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create the request stack
|
||||
// Search the players inventory
|
||||
ItemStack replenishmentPlayer = this.takeItemFromPlayer( itemStack, 1 );
|
||||
if( replenishmentPlayer != null )
|
||||
{
|
||||
return replenishmentPlayer;
|
||||
}
|
||||
|
||||
// Create the AE request stack
|
||||
IAEItemStack requestStack = AEApi.instance().storage().createItemStack( itemStack );
|
||||
|
||||
// Set the request amount to one
|
||||
requestStack.setStackSize( 1 );
|
||||
|
||||
// Attempt an extraction
|
||||
IAEItemStack replenishment = this.monitor.extractItems( requestStack, Actionable.MODULATE, this.playerSource );
|
||||
IAEItemStack replenishmentAE = this.monitor.extractItems( requestStack, Actionable.MODULATE, this.playerSource );
|
||||
|
||||
// Did we get a replenishment?
|
||||
if( replenishment != null )
|
||||
if( replenishmentAE != null )
|
||||
{
|
||||
return replenishment.getItemStack();
|
||||
return replenishmentAE.getItemStack();
|
||||
}
|
||||
|
||||
// Did not get a replenishment, search for items that match.
|
||||
@@ -1589,12 +1596,12 @@ public class ContainerPartArcaneCraftingTerminal
|
||||
requestStack.setStackSize( 1 );
|
||||
|
||||
// Attempt an extraction
|
||||
replenishment = this.monitor.extractItems( requestStack, Actionable.MODULATE, this.playerSource );
|
||||
replenishmentAE = this.monitor.extractItems( requestStack, Actionable.MODULATE, this.playerSource );
|
||||
|
||||
// Did we get a replenishment?
|
||||
if( ( replenishment != null ) && ( replenishment.getStackSize() > 0 ) )
|
||||
if( ( replenishmentAE != null ) && ( replenishmentAE.getStackSize() > 0 ) )
|
||||
{
|
||||
return replenishment.getItemStack();
|
||||
return replenishmentAE.getItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+113
-13
@@ -1,10 +1,12 @@
|
||||
package thaumicenergistics.common.container;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thaumicenergistics.common.utils.ThEUtils;
|
||||
|
||||
/**
|
||||
* Container that includes the players inventory.
|
||||
@@ -38,12 +40,12 @@ public abstract class ContainerWithPlayerInventory
|
||||
/**
|
||||
* Array of player hotbar slots
|
||||
*/
|
||||
private final Slot[] hotbarSlots = new Slot[COLUMNS];
|
||||
private final Slot[] hotbarSlots = new Slot[ContainerWithPlayerInventory.COLUMNS];
|
||||
|
||||
/**
|
||||
* Array of player inventory slots.
|
||||
*/
|
||||
private final Slot[] playerSlots = new Slot[COLUMNS * ROWS];
|
||||
private final Slot[] playerSlots = new Slot[ContainerWithPlayerInventory.COLUMNS * ContainerWithPlayerInventory.ROWS];
|
||||
|
||||
public ContainerWithPlayerInventory( final EntityPlayer player )
|
||||
{
|
||||
@@ -58,7 +60,8 @@ public abstract class ContainerWithPlayerInventory
|
||||
*/
|
||||
protected final boolean mergeSlotWithHotbarInventory( final ItemStack slotStack )
|
||||
{
|
||||
return this.mergeItemStack( slotStack, this.hotbarSlots[0].slotNumber, this.hotbarSlots[COLUMNS - 1].slotNumber + 1, false );
|
||||
return this.mergeItemStack( slotStack, this.hotbarSlots[0].slotNumber,
|
||||
this.hotbarSlots[ContainerWithPlayerInventory.COLUMNS - 1].slotNumber + 1, false );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +72,8 @@ public abstract class ContainerWithPlayerInventory
|
||||
*/
|
||||
protected final boolean mergeSlotWithPlayerInventory( final ItemStack slotStack )
|
||||
{
|
||||
return this.mergeItemStack( slotStack, this.playerSlots[0].slotNumber, this.playerSlots[( COLUMNS * ROWS ) - 1].slotNumber + 1, false );
|
||||
return this.mergeItemStack( slotStack, this.playerSlots[0].slotNumber,
|
||||
this.playerSlots[( ContainerWithPlayerInventory.COLUMNS * ContainerWithPlayerInventory.ROWS ) - 1].slotNumber + 1, false );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +84,8 @@ public abstract class ContainerWithPlayerInventory
|
||||
*/
|
||||
protected final boolean slotClickedWasInHotbarInventory( final int slotNumber )
|
||||
{
|
||||
return ( slotNumber >= this.hotbarSlots[0].slotNumber ) && ( slotNumber <= this.hotbarSlots[COLUMNS - 1].slotNumber );
|
||||
return ( slotNumber >= this.hotbarSlots[0].slotNumber ) &&
|
||||
( slotNumber <= this.hotbarSlots[ContainerWithPlayerInventory.COLUMNS - 1].slotNumber );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +96,9 @@ public abstract class ContainerWithPlayerInventory
|
||||
*/
|
||||
protected final boolean slotClickedWasInPlayerInventory( final int slotNumber )
|
||||
{
|
||||
return ( slotNumber >= this.playerSlots[0].slotNumber ) && ( slotNumber <= this.playerSlots[( COLUMNS * ROWS ) - 1].slotNumber );
|
||||
return ( slotNumber >= this.playerSlots[0].slotNumber ) &&
|
||||
( slotNumber <= this.playerSlots[( ContainerWithPlayerInventory.COLUMNS * ContainerWithPlayerInventory.ROWS ) -
|
||||
1].slotNumber );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +121,97 @@ public abstract class ContainerWithPlayerInventory
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the players inventory & hotbar for the specified stack.
|
||||
*
|
||||
* @param searchStack
|
||||
* @param amount
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
protected final ItemStack takeItemFromPlayer( final ItemStack searchStack, final int amount )
|
||||
{
|
||||
// Sanity check
|
||||
if( ( searchStack == null ) || ( amount <= 0 ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Slot matchingSlot = null;
|
||||
|
||||
// Search inventory
|
||||
for( Slot slot : this.playerSlots )
|
||||
{
|
||||
// Empty?
|
||||
if( !slot.getHasStack() )
|
||||
{
|
||||
// Skip
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for match
|
||||
if( ThEUtils.areStacksEqualIgnoreAmount( searchStack, slot.getStack() ) )
|
||||
{
|
||||
// Found match
|
||||
matchingSlot = slot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( matchingSlot == null )
|
||||
{
|
||||
// Search hotbar
|
||||
for( Slot slot : this.hotbarSlots )
|
||||
{
|
||||
// Empty?
|
||||
if( !slot.getHasStack() )
|
||||
{
|
||||
// Skip
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for match
|
||||
if( ThEUtils.areStacksEqualIgnoreAmount( searchStack, slot.getStack() ) )
|
||||
{
|
||||
// Found match
|
||||
matchingSlot = slot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( matchingSlot == null )
|
||||
{
|
||||
// No matches
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check amount
|
||||
ItemStack matchStack = matchingSlot.getStack();
|
||||
if( matchStack.stackSize < amount )
|
||||
{
|
||||
// Not enough to take
|
||||
return null;
|
||||
}
|
||||
|
||||
// Split
|
||||
ItemStack result = matchStack.splitStack( amount );
|
||||
|
||||
// Anything left in the stack?
|
||||
if( matchStack.stackSize == 0 )
|
||||
{
|
||||
// Null the slot
|
||||
matchingSlot.putStack( null );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update the slot
|
||||
matchingSlot.putStack( matchStack );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the player inventory to this container.
|
||||
*
|
||||
@@ -127,26 +225,28 @@ public abstract class ContainerWithPlayerInventory
|
||||
public final void bindPlayerInventory( final IInventory playerInventory, final int inventoryOffsetY, final int hotbarPositionY )
|
||||
{
|
||||
// Hot-bar ID's 0-8
|
||||
for( int column = 0; column < COLUMNS; column++ )
|
||||
for( int column = 0; column < ContainerWithPlayerInventory.COLUMNS; column++ )
|
||||
{
|
||||
// Create the slot
|
||||
this.hotbarSlots[column] = new Slot( playerInventory, column, INVENTORY_X_OFFSET + ( column * SLOT_SIZE ), hotbarPositionY );
|
||||
this.hotbarSlots[column] = new Slot( playerInventory, column,
|
||||
ContainerWithPlayerInventory.INVENTORY_X_OFFSET + ( column * ContainerWithPlayerInventory.SLOT_SIZE ), hotbarPositionY );
|
||||
|
||||
// Add the slot
|
||||
this.addSlotToContainer( this.hotbarSlots[column] );
|
||||
}
|
||||
|
||||
// Main inventory ID's 9-36
|
||||
for( int row = 0; row < ROWS; row++ )
|
||||
for( int row = 0; row < ContainerWithPlayerInventory.ROWS; row++ )
|
||||
{
|
||||
for( int column = 0; column < COLUMNS; column++ )
|
||||
for( int column = 0; column < ContainerWithPlayerInventory.COLUMNS; column++ )
|
||||
{
|
||||
// Calculate index
|
||||
int index = column + ( row * COLUMNS );
|
||||
int index = column + ( row * ContainerWithPlayerInventory.COLUMNS );
|
||||
|
||||
// Create the slot
|
||||
this.playerSlots[index] = new Slot( playerInventory, COLUMNS + index, INVENTORY_X_OFFSET + ( column * SLOT_SIZE ),
|
||||
( row * SLOT_SIZE ) + inventoryOffsetY );
|
||||
this.playerSlots[index] = new Slot( playerInventory, ContainerWithPlayerInventory.COLUMNS + index,
|
||||
ContainerWithPlayerInventory.INVENTORY_X_OFFSET + ( column * ContainerWithPlayerInventory.SLOT_SIZE ),
|
||||
( row * ContainerWithPlayerInventory.SLOT_SIZE ) + inventoryOffsetY );
|
||||
|
||||
// Add the slot
|
||||
this.addSlotToContainer( this.playerSlots[index] );
|
||||
|
||||
@@ -24,6 +24,7 @@ import thaumcraft.api.aspects.AspectList;
|
||||
import thaumicenergistics.api.IThEItems;
|
||||
import thaumicenergistics.api.ThEApi;
|
||||
import thaumicenergistics.common.utils.ThELog;
|
||||
import thaumicenergistics.common.utils.ThEUtils;
|
||||
|
||||
/**
|
||||
* Gives items from AE2 aspects when scanned.
|
||||
@@ -322,7 +323,7 @@ public class AEAspectRegister
|
||||
continue;
|
||||
}
|
||||
|
||||
if( this.areStacksEqualIgnoreAmount( recipeOutput, this.itemStack ) )
|
||||
if( ThEUtils.areStacksEqualIgnoreAmount( recipeOutput, this.itemStack ) )
|
||||
{
|
||||
if( this.isRecipeUsable( recipe ) )
|
||||
{
|
||||
@@ -357,7 +358,7 @@ public class AEAspectRegister
|
||||
continue;
|
||||
}
|
||||
|
||||
if( this.areStacksEqualIgnoreAmount( recipeOutput, this.itemStack ) )
|
||||
if( ThEUtils.areStacksEqualIgnoreAmount( recipeOutput, this.itemStack ) )
|
||||
{
|
||||
if( this.isRecipeUsable( recipe ) )
|
||||
{
|
||||
@@ -394,7 +395,7 @@ public class AEAspectRegister
|
||||
}
|
||||
|
||||
// Is this what we are looking for?
|
||||
if( !this.areStacksEqualIgnoreAmount( recipeOutput, this.itemStack ) )
|
||||
if( !ThEUtils.areStacksEqualIgnoreAmount( recipeOutput, this.itemStack ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -636,40 +637,6 @@ public class AEAspectRegister
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specified stacks are equal.
|
||||
*
|
||||
* @param stack1
|
||||
* @param stack2
|
||||
* @return
|
||||
*/
|
||||
public boolean areStacksEqualIgnoreAmount( final ItemStack stack1, final ItemStack stack2 )
|
||||
{
|
||||
// Nulls never match
|
||||
if( ( stack1 == null ) || ( stack2 == null ) || ( stack1.getItem() == null ) || ( stack2.getItem() == null ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( stack1.getItem().equals( stack2.getItem() ) )
|
||||
{
|
||||
if( stack1.getHasSubtypes() )
|
||||
{
|
||||
if( stack1.getItemDamage() == stack2.getItemDamage() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this item matches the specified object.
|
||||
*/
|
||||
@@ -769,7 +736,7 @@ public class AEAspectRegister
|
||||
*/
|
||||
public boolean isMatch( final ItemStack stack )
|
||||
{
|
||||
return this.areStacksEqualIgnoreAmount( stack, this.itemStack );
|
||||
return ThEUtils.areStacksEqualIgnoreAmount( stack, this.itemStack );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import thaumcraft.common.items.wands.ItemWandCasting;
|
||||
import thaumicenergistics.common.network.packet.client.Packet_C_Sync;
|
||||
|
||||
@@ -37,6 +38,58 @@ public final class ThEUtils
|
||||
.playSound( PositionedSoundRecord.func_147674_a( sound, 1.0F ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specified stacks are equal, ignoring their stack size.<br>
|
||||
* If either stack is null, returns false.
|
||||
*
|
||||
* @param stack1
|
||||
* @param stack2
|
||||
* @return
|
||||
*/
|
||||
public static boolean areStacksEqualIgnoreAmount( final ItemStack stack1, final ItemStack stack2 )
|
||||
{
|
||||
// Nulls never match
|
||||
if( ( stack1 == null ) || ( stack2 == null ) || ( stack1.getItem() == null ) || ( stack2.getItem() == null ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// NBT state must match
|
||||
if( stack1.hasTagCompound() != stack2.hasTagCompound() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Item mismatch?
|
||||
if( !( stack1.getItem().equals( stack2.getItem() ) ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check damage
|
||||
// Are either NOT wildcard?
|
||||
if( ( stack1.getItemDamage() != OreDictionary.WILDCARD_VALUE ) && ( stack2.getItemDamage() != OreDictionary.WILDCARD_VALUE ) )
|
||||
{
|
||||
// Does damage match?
|
||||
if( stack1.getItemDamage() != stack2.getItemDamage() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// NBT mismatch?
|
||||
if( stack1.hasTagCompound() )
|
||||
{
|
||||
if( !( stack1.getTagCompound().equals( stack2.getTagCompound() ) ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// All tests passed
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the tile still exists and the player is within reach range.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user