A.C.T. result slot

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.
This commit is contained in:
Chris committed 2016-04-21 08:38:17 -04:00
1 parent ded29d286e
commit 2df2ff0729
6 files changed
+89 -101

No files matched your search

+6 -1
View File
@@ -1,4 +1,9 @@
04/18/2016 1.0.0.5 - Beta
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.
04/18/2016 1.0.0.5 - Beta
Refactored the essentia grid cache
04/17/2016 1.0.0.5 - Beta
Fixed #281: Essentia terminal no longer overlayed by NEI at certain aspect ratios.
@@ -106,7 +106,8 @@ public class ContainerPartArcaneCraftingTerminal
/**
* Total number of slots in the crafting grid
*/
public static int CRAFTING_GRID_TOTAL_SIZE = CRAFTING_GRID_SIZE * CRAFTING_GRID_SIZE;
public static int CRAFTING_GRID_TOTAL_SIZE = ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE *
ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE;
/**
* Starting position for crafting slots.
@@ -222,21 +223,21 @@ public class ContainerPartArcaneCraftingTerminal
this.playerSource = new PlayerSource( this.player, terminal );
// Bind to the players inventory
this.bindPlayerInventory( player.inventory, PLAYER_INV_POSITION_Y,
HOTBAR_INV_POSITION_Y );
this.bindPlayerInventory( player.inventory, ContainerPartArcaneCraftingTerminal.PLAYER_INV_POSITION_Y,
ContainerPartArcaneCraftingTerminal.HOTBAR_INV_POSITION_Y );
// Add crafting slots
Slot craftingSlot = null;
for( int row = 0; row < CRAFTING_GRID_SIZE; row++ )
for( int row = 0; row < ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE; row++ )
{
for( int column = 0; column < CRAFTING_GRID_SIZE; column++ )
for( int column = 0; column < ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE; column++ )
{
// Calculate the index
int slotIndex = ( row * CRAFTING_GRID_SIZE ) + column;
int slotIndex = ( row * ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE ) + column;
// Create the slot
craftingSlot = new Slot( terminal, slotIndex, CRAFTING_SLOT_X_POS +
( column * ContainerWithPlayerInventory.SLOT_SIZE ), CRAFTING_SLOT_Y_POS +
craftingSlot = new Slot( terminal, slotIndex, ContainerPartArcaneCraftingTerminal.CRAFTING_SLOT_X_POS +
( column * ContainerWithPlayerInventory.SLOT_SIZE ), ContainerPartArcaneCraftingTerminal.CRAFTING_SLOT_Y_POS +
( row * ContainerWithPlayerInventory.SLOT_SIZE ) );
// Add the slot
@@ -258,15 +259,15 @@ public class ContainerPartArcaneCraftingTerminal
// Create the result slot
this.resultSlot = new SlotArcaneCraftingResult( player, this, terminal, terminal,
PartArcaneCraftingTerminal.RESULT_SLOT_INDEX, RESULT_SLOT_X_POS,
RESULT_SLOT_Y_POS );
PartArcaneCraftingTerminal.RESULT_SLOT_INDEX, ContainerPartArcaneCraftingTerminal.RESULT_SLOT_X_POS,
ContainerPartArcaneCraftingTerminal.RESULT_SLOT_Y_POS );
// Add the result slot
this.addSlotToContainer( this.resultSlot );
// Create the wand slot
this.wandSlot = new SlotRestrictive( terminal, PartArcaneCraftingTerminal.WAND_SLOT_INDEX,
WAND_SLOT_XPOS, WAND_SLOT_YPOS );
ContainerPartArcaneCraftingTerminal.WAND_SLOT_XPOS, ContainerPartArcaneCraftingTerminal.WAND_SLOT_YPOS );
// Add the wand slot
this.addSlotToContainer( this.wandSlot );
@@ -277,10 +278,10 @@ public class ContainerPartArcaneCraftingTerminal
{
// Calculate the y position
int row = viewSlotID - PartArcaneCraftingTerminal.VIEW_SLOT_MIN;
int yPos = VIEW_SLOT_YPOS + ( row * ContainerWithPlayerInventory.SLOT_SIZE );
int yPos = ContainerPartArcaneCraftingTerminal.VIEW_SLOT_YPOS + ( row * ContainerWithPlayerInventory.SLOT_SIZE );
// Create the slot
viewSlot = new SlotRestrictive( terminal, viewSlotID, VIEW_SLOT_XPOS, yPos );
viewSlot = new SlotRestrictive( terminal, viewSlotID, ContainerPartArcaneCraftingTerminal.VIEW_SLOT_XPOS, yPos );
// Add the slot
this.addSlotToContainer( viewSlot );
@@ -299,14 +300,14 @@ public class ContainerPartArcaneCraftingTerminal
}
// Create the armor slots
for( int armorIndex = 0; armorIndex < ARMOR_SLOT_COUNT; ++armorIndex )
for( int armorIndex = 0; armorIndex < ContainerPartArcaneCraftingTerminal.ARMOR_SLOT_COUNT; ++armorIndex )
{
// Calculate y position
int yPos = ARMOR_SLOT_Y_POS + ( ContainerWithPlayerInventory.SLOT_SIZE * armorIndex );
int yPos = ContainerPartArcaneCraftingTerminal.ARMOR_SLOT_Y_POS + ( ContainerWithPlayerInventory.SLOT_SIZE * armorIndex );
// Create the slot
SlotArmor armorSlot = new SlotArmor( terminal, PartArcaneCraftingTerminal.ARMOR_SLOT_MIN + armorIndex,
ARMOR_SLOT_X_POS, yPos, armorIndex, false );
ContainerPartArcaneCraftingTerminal.ARMOR_SLOT_X_POS, yPos, armorIndex, false );
// Add to container
this.addSlotToContainer( armorSlot );
@@ -561,7 +562,7 @@ public class ContainerPartArcaneCraftingTerminal
// Is there a matching recipe?
IArcaneRecipe matchingRecipe = ArcaneRecipeHelper.INSTANCE.findMatchingArcaneResult( this.terminal, 0,
CRAFTING_GRID_TOTAL_SIZE, this.player );
ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_TOTAL_SIZE, this.player );
if( matchingRecipe != null )
{
@@ -582,17 +583,17 @@ public class ContainerPartArcaneCraftingTerminal
{
// Create a new crafting inventory
InventoryCrafting craftingInventory = new InventoryCrafting( new ContainerInternalCrafting(),
CRAFTING_GRID_SIZE, CRAFTING_GRID_SIZE );
ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE, ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_SIZE );
// Load the inventory based on what is in the part's inventory
for( int slotIndex = 0; slotIndex < ( CRAFTING_GRID_TOTAL_SIZE ); slotIndex++ )
for( int slotIndex = 0; slotIndex < ( ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_TOTAL_SIZE ); slotIndex++ )
{
// Set the slot
craftingInventory.setInventorySlotContents( slotIndex, this.terminal.getStackInSlot( slotIndex ) );
}
// Return the result
return CRAFT_MANAGER.findMatchingRecipe( craftingInventory, this.terminal.getWorldObj() );
return ContainerPartArcaneCraftingTerminal.CRAFT_MANAGER.findMatchingRecipe( craftingInventory, this.terminal.getWorldObj() );
}
/**
@@ -764,7 +765,7 @@ public class ContainerPartArcaneCraftingTerminal
// Get the cost
this.requiredAspects = ArcaneRecipeHelper.INSTANCE.getRecipeAspectCost( this.terminal, 0,
CRAFTING_GRID_TOTAL_SIZE, forRecipe );
ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_TOTAL_SIZE, forRecipe );
// Ensure there is a cost
if( this.requiredAspects == null )
@@ -822,7 +823,7 @@ public class ContainerPartArcaneCraftingTerminal
{
// Get the result of the recipe.
return ArcaneRecipeHelper.INSTANCE.getRecipeOutput( this.terminal, 0,
CRAFTING_GRID_TOTAL_SIZE, forRecipe );
ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_TOTAL_SIZE, forRecipe );
}
return null;
@@ -1603,23 +1604,6 @@ public class ContainerPartArcaneCraftingTerminal
return null;
}
/**
* Called when a slot is clicked by the player.
*/
@Override
public ItemStack slotClick( final int slotNumber, final int button, final int flag, final EntityPlayer player )
{
if( ( slotNumber == this.resultSlot.slotNumber ) && ( button == ThEGuiHelper.MOUSE_BUTTON_RIGHT ) )
{
// If right clicking on result slot, change it to left click
return super.slotClick( slotNumber, ThEGuiHelper.MOUSE_BUTTON_LEFT, flag, player );
}
// Pass to super
return super.slotClick( slotNumber, button, flag, player );
}
/**
* Called when the player shift+clicks on a slot
*/
@@ -79,18 +79,6 @@ public abstract class TheContainerBase
return false;
}
/**
* Returns the slot with the specified slot number or null.
*
* @param slotNumber
* @return
*/
@Nullable
protected Slot getSlotOrNull( final int slotNumber )
{
return this.slotMap.getOrDefault( slotNumber, null );
}
@Override
public void detectAndSendChanges()
{
@@ -120,6 +108,18 @@ public abstract class TheContainerBase
return super.getSlot( slotNumber );
}
/**
* Returns the slot with the specified slot number or null.
*
* @param slotNumber
* @return
*/
@Nullable
public Slot getSlotOrNull( final int slotNumber )
{
return this.slotMap.getOrDefault( slotNumber, null );
}
/**
* Clears the slot map.
*/
@@ -11,6 +11,7 @@ import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.items.wands.ItemWandCasting;
import thaumicenergistics.common.container.ContainerPartArcaneCraftingTerminal;
import thaumicenergistics.common.utils.EffectiveSide;
import thaumicenergistics.common.utils.ThELog;
/**
* Slot that holds the result of an arcane crafting recipe.
@@ -93,26 +94,28 @@ public class SlotArcaneCraftingResult
*/
public void onPickupFromSlotViaTransfer( final EntityPlayer player, final ItemStack itemStack )
{
// Not really sure what this does, but "SlotCrafting" does it, so I shall also!
// Fire crafting event
FMLCommonHandler.instance().firePlayerCraftingEvent( player, itemStack, this.terminalInventory );
// Seems to fire achievements, and handles the item creation
this.onCrafting( itemStack );
// Is this an arcane recipe?
if( this.craftingAspects != null )
if( EffectiveSide.isClientSide() )
{
// No more work on the client side.
return;
}
ThELog.info( "%d", itemStack.stackSize );
// Arcane recipe?
if( ( this.craftingAspects != null ) )
{
// Consume wand vis
this.wandItem.consumeAllVisCrafting( this.wand, player, this.craftingAspects, true );
}
// From here on the server will handle the rest
if( EffectiveSide.isClientSide() )
{
return;
}
// Loop over all crafting slots
for( int slotIndex = 0; slotIndex < ContainerPartArcaneCraftingTerminal.CRAFTING_GRID_TOTAL_SIZE; slotIndex++ )
{
@@ -129,39 +132,38 @@ public class SlotArcaneCraftingResult
// Checked at the end to see if we need to decrement the slot
boolean shouldDecrement = true;
// Does the item in the slotstack have a container?
// Does the item have a container?
if( slotStack.getItem().hasContainerItem( slotStack ) )
{
// Get the container item
ItemStack slotContainerItem = slotStack.getItem().getContainerItem( slotStack );
ItemStack slotContainerStack = slotStack.getItem().getContainerItem( slotStack );
// Is the container item damage-able?
if( slotContainerItem.isItemStackDamageable() )
if( slotContainerStack.isItemStackDamageable() )
{
// Did we kill it?
if( slotContainerItem.getItemDamage() >= slotContainerItem.getMaxDamage() )
if( slotContainerStack.getItemDamage() >= slotContainerStack.getMaxDamage() )
{
// Still not sure about these forge events, really need to read up on them
// But again "SlotCrafting" does this, so shall I
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, slotContainerItem ) );
// Fire forge event
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, slotContainerStack ) );
// Null out the container item
slotContainerItem = null;
// Null the container stack
slotContainerStack = null;
}
}
// Did we not kill the container item?
if( slotContainerItem != null )
if( slotContainerStack != null )
{
/*
* Should the item stay in the crafting grid, or if it is supposed to go back to the
* players inventory but can't?
*/
if( !slotStack.getItem().doesContainerItemLeaveCraftingGrid( slotStack ) ||
!player.inventory.addItemStackToInventory( slotContainerItem ) )
!player.inventory.addItemStackToInventory( slotContainerStack ) )
{
// Place it back in the grid
this.terminalInventory.setInventorySlotContents( slotIndex, slotContainerItem );
this.terminalInventory.setInventorySlotContents( slotIndex, slotContainerStack );
// Set NOT to decrement
shouldDecrement = false;
@@ -169,37 +171,33 @@ public class SlotArcaneCraftingResult
}
}
// Should we decrement the inventory stack?
if( shouldDecrement )
// If decrementing it would result in it being empty, ask the ME system for a replenishment.
if( shouldDecrement && ( slotStack.stackSize == 1 ) )
{
// Would decrementing it result in it being empty?
if( slotStack.stackSize == 1 )
{
// First check if we can replenish it from the ME network
ItemStack replenishment = this.hostContianer.requestCraftingReplenishment( slotStack );
// First check if we can replenish it from the ME network
ItemStack replenishment = this.hostContianer.requestCraftingReplenishment( slotStack );
// Did we get a replenishment?
if( replenishment != null )
// Did we get a replenishment?
if( replenishment != null )
{
// Did the item change?
if( !ItemStack.areItemStacksEqual( replenishment, slotStack ) )
{
// Did the item change?
if( !ItemStack.areItemStacksEqual( replenishment, slotStack ) )
{
// Set the slot contents to the replenishment
this.terminalInventory.setInventorySlotContents( slotIndex, replenishment );
}
// And mark not to decrement
shouldDecrement = false;
// Set the slot contents to the replenishment
this.terminalInventory.setInventorySlotContents( slotIndex, replenishment );
}
}
// Check again, should we decrement?
if( shouldDecrement )
{
// Decrease it's size by 1
this.terminalInventory.decrStackSize( slotIndex, 1 );
// And mark not to decrement
shouldDecrement = false;
}
}
// Decrement the stack?
if( shouldDecrement )
{
this.terminalInventory.decrStackSize( slotIndex, 1 );
}
}
}
@@ -57,7 +57,7 @@ public class Packet_C_Sync
public static void sendPlayerHeldItem( final EntityPlayer player, final ItemStack heldItem )
{
// Create the packet
Packet_C_Sync packet = newPacket( player, MODE_PLAYER_HELD );
Packet_C_Sync packet = Packet_C_Sync.newPacket( player, Packet_C_Sync.MODE_PLAYER_HELD );
// Set the held item
packet.syncStack = heldItem;
@@ -78,7 +78,7 @@ public class Packet_C_Sync
public static void sendPlaySound( final EntityPlayer player, final String soundLocation )
{
// Create the packet
Packet_C_Sync packet = newPacket( player, MODE_SOUND );
Packet_C_Sync packet = Packet_C_Sync.newPacket( player, Packet_C_Sync.MODE_SOUND );
// Set the sound location
packet.syncString = soundLocation;
@@ -239,7 +239,8 @@ public class PartArcaneCraftingTerminal
{
// Is the amount for more than or all of the slot?
if( amount >= slotStack.stackSize )
// If is it the results stack, the whole stack must be returned, can not 'partially' take the crafting result.
if( ( amount >= slotStack.stackSize ) || ( slotIndex == PartArcaneCraftingTerminal.RESULT_SLOT_INDEX ) )
{
// Set the return to a copy of the stack
returnStack = slotStack.copy();
@@ -906,7 +907,7 @@ public class PartArcaneCraftingTerminal
}
// Get the wand slot
ItemStack stack = this.getStackInSlot( WAND_SLOT_INDEX );
ItemStack stack = this.getStackInSlot( PartArcaneCraftingTerminal.WAND_SLOT_INDEX );
// Do we have a wand?
if( ( stack == null ) )