Feature: #0675 - Drag'n'Drop functionality when making patterns

Fixed a bug where pattern would not properly re-populate the pattern terminal when they were re-inserted.
Shift clicking into the inscriber is more intelligent.
This commit is contained in:
AlgorithmX2
2014-07-19 14:33:28 -05:00
parent e2288dafc7
commit 1747204928
7 changed files with 181 additions and 17 deletions
+22 -1
View File
@@ -351,6 +351,27 @@ public abstract class AEBaseGui extends GuiContainer
super.handleMouseClick( slot, slotIdx, ctrlDown, key );
}
protected void mouseClickMove(int x, int y, int c, long d)
{
Slot slot = this.getSlot( x, y );
ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
if ( slot instanceof SlotFake && itemstack != null )
{
try
{
PacketInventoryAction p = new PacketInventoryAction( InventoryAction.PICKUP_OR_SETDOWN, slot.slotNumber, 0 );
NetworkHandler.instance.sendToServer( p );
}
catch (IOException e)
{
AELog.error( e );
}
}
else
super.mouseClickMove( x, y, c, d );
}
protected boolean enableSpaceClicking()
{
return true;
@@ -749,7 +770,7 @@ public abstract class AEBaseGui extends GuiContainer
try
{
ItemStack is = s.getStack();
if ( s instanceof AppEngSlot && (((AppEngSlot) s).renderIconWithItem() || is == null) && (((AppEngSlot) s).isEnabled()) )
if ( s instanceof AppEngSlot && (((AppEngSlot) s).renderIconWithItem() || is == null) && (((AppEngSlot) s).shouldDisplay()) )
{
AppEngSlot aes = (AppEngSlot) s;
if ( aes.getIcon() >= 0 )
+14
View File
@@ -301,7 +301,11 @@ public abstract class AEBaseContainer extends Container
protected Slot addSlotToContainer(Slot newSlot)
{
if ( newSlot instanceof AppEngSlot )
{
AppEngSlot s = (AppEngSlot) newSlot;
s.myContainer = this;
return super.addSlotToContainer( newSlot );
}
else
throw new RuntimeException( "Invalid Slot for AE Container." );
}
@@ -1073,4 +1077,14 @@ public abstract class AEBaseContainer extends Container
}
public void onSlotChange(Slot s)
{
}
public boolean isValidForSlot(Slot s, ItemStack i)
{
return true;
}
}
@@ -1,11 +1,16 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.recipes.handlers.Inscribe;
import appeng.recipes.handlers.Inscribe.InscriberRecipe;
import appeng.tile.misc.TileInscriber;
import appeng.util.Platform;
@@ -14,6 +19,10 @@ public class ContainerInscriber extends AEBaseContainer
TileInscriber myte;
Slot top;
Slot middle;
Slot bottom;
@GuiSync(0)
public int maxProessingTime = -1;
@@ -24,15 +33,92 @@ public class ContainerInscriber extends AEBaseContainer
super( ip, te, null );
myte = te;
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.INSCRIBER_PLATE, myte, 0, 45, 16, invPlayer ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.INSCRIBER_INPUT, myte, 2, 63, 39, invPlayer ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.INSCRIBER_PLATE, myte, 1, 45, 62, invPlayer ) );
addSlotToContainer( top = new SlotRestrictedInput( PlaceableItemType.INSCRIBER_PLATE, myte, 0, 45, 16, invPlayer ) );
addSlotToContainer( bottom = new SlotRestrictedInput( PlaceableItemType.INSCRIBER_PLATE, myte, 1, 45, 62, invPlayer ) );
addSlotToContainer( middle = new SlotRestrictedInput( PlaceableItemType.INSCRIBER_INPUT, myte, 2, 63, 39, invPlayer ) );
addSlotToContainer( new SlotOutput( myte, 3, 113, 40, -1 ) );
bindPlayerInventory( ip, 0, 176 - /* height of playerinventory */82 );
}
public boolean isValidForSlot(Slot s, ItemStack is)
{
ItemStack PlateA = myte.getStackInSlot( 0 );
ItemStack PlateB = myte.getStackInSlot( 1 );
ItemStack MiddleIS = myte.getStackInSlot( 2 );
if ( s == middle )
{
for (ItemStack i : Inscribe.plates)
{
if ( Platform.isSameItemPrecise( i, is ) )
return false;
}
boolean matches = false;
boolean found = false;
for (InscriberRecipe i : Inscribe.recipes)
{
boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and...
(PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB ));
boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and...
(PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB ));
if ( matchA || matchB )
{
matches = true;
for (ItemStack option : i.imprintable)
{
if ( Platform.isSameItemPrecise( is, option ) )
found = true;
}
}
}
if ( matches && found == false )
return false;
}
if ( (s == top && PlateB != null) || (s == bottom && PlateA != null) )
{
boolean isValid = false;
ItemStack otherSlot = null;
if ( s == top )
otherSlot = bottom.getStack();
else
otherSlot = top.getStack();
// name presse
if ( AEApi.instance().materials().materialNamePress.sameAsStack( otherSlot ) )
return AEApi.instance().materials().materialNamePress.sameAsStack( is );
// everything else
for (InscriberRecipe i : Inscribe.recipes)
{
if ( Platform.isSameItemPrecise( i.plateA, otherSlot ) )
{
isValid = Platform.isSameItemPrecise( is, i.plateB );
}
else if ( Platform.isSameItemPrecise( i.plateB, otherSlot ) )
{
isValid = Platform.isSameItemPrecise( is, i.plateA );
}
if ( isValid )
break;
}
if ( !isValid )
return false;
}
return true;
}
@Override
public void detectAndSendChanges()
{
@@ -6,6 +6,7 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
@@ -29,6 +30,7 @@ import appeng.container.guisync.GuiSync;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternOutputs;
import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
@@ -76,7 +78,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
for (int y = 0; y < 3; y++)
{
addSlotToContainer( outputSlots[y] = new OptionalSlotFake( output, this, y, 110, -76 + y * 18, 0, 0, 1 ) );
addSlotToContainer( outputSlots[y] = new SlotPatternOutputs( output, this, y, 110, -76 + y * 18, 0, 0, 1 ) );
outputSlots[y].renderDisabled = false;
outputSlots[y].IIcon = -1;
}
@@ -389,23 +391,26 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
}
@Override
public ItemStack slotClick(int slotNum, int p_75144_2_, int p_75144_3_, EntityPlayer p_75144_4_)
public void onSlotChange(Slot s)
{
Slot s = null;
for (Object g : inventorySlots)
if ( s == patternSlotOUT && Platform.isServer() )
{
if ( g instanceof Slot )
for (int i = 0; i < this.crafters.size(); ++i)
{
Slot gg = (Slot) g;
if ( gg.slotNumber == slotNum )
s = gg;
}
}
ICrafting icrafting = (ICrafting) this.crafters.get( i );
ItemStack is = super.slotClick( slotNum, p_75144_2_, p_75144_3_, p_75144_4_ );
if ( s == patternSlotOUT )
for (Object g : inventorySlots)
{
if ( g instanceof OptionalSlotFake || g instanceof SlotFakeCraftingMatrix )
{
Slot sri = (Slot) g;
icrafting.sendSlotContents( this, sri.slotNumber, sri.getStack() );
}
}
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
}
detectAndSendChanges();
return is;
}
}
public void clear()
+12
View File
@@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import appeng.container.AEBaseContainer;
import appeng.tile.inventory.AppEngInternalInventory;
public class AppEngSlot extends Slot
@@ -16,6 +17,7 @@ public class AppEngSlot extends Slot
public boolean isDraggable = true;
public boolean isPlayerSide = false;
public AEBaseContainer myContainer = null;
public Slot setNotDraggable()
{
@@ -90,7 +92,12 @@ public class AppEngSlot extends Slot
public void putStack(ItemStack par1ItemStack)
{
if ( isEnabled() )
{
super.putStack( par1ItemStack );
if ( myContainer != null )
myContainer.onSlotChange( this );
}
}
public void clearStack()
@@ -139,4 +146,9 @@ public class AppEngSlot extends Slot
return isPlayerSide;
}
public boolean shouldDisplay()
{
return isEnabled();
}
}
+23
View File
@@ -0,0 +1,23 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotPatternOutputs extends OptionalSlotFake
{
public SlotPatternOutputs(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@Override
public boolean isEnabled()
{
return true;
}
@Override
public boolean shouldDisplay()
{
return super.isEnabled();
}
}
+3
View File
@@ -111,6 +111,9 @@ public class SlotRestrictedInput extends AppEngSlot
@Override
public boolean isItemValid(ItemStack i)
{
if ( !myContainer.isValidForSlot( this, i ) )
return false;
if ( i == null )
return false;
if ( i.getItem() == null )