joekaiser / practicalities

1 stars 3 forks source link

Fuzzy cards and shift clicks #17

Closed thecodewarrior closed 8 years ago

thecodewarrior commented 8 years ago

Added fuzzy option to cards, showing as a blue box for precise matching and a blurry green box for fuzzy.

Fixed shift clicking in storage crate. Fixes #7 And in the process:

Created a shift clicking library. Simply specify regions, what regions will try to move items to what other regions, and call one simple function, and you're done!

Library has JavaDocs and there are examples in ContainerShippingCrate.

thecodewarrior commented 8 years ago

Here's some documentation on the shift clicking library. Can you maybe set up a wiki on github? That seems like the logical place to put this.

Creating regions

To create a region, simply create a new SlotRegion and give it a name (which isn't used as of yet) and one of the following:

Here are some examples:

mainInv = new SlotRegion("mainInventory", 0, 26);
hotbar  = new SlotRegion("hotbar", 27, 35);
int[][] indexColumns = new int[colCount][rowCount]; // initialized to slot indexes at those positions

SlotRegion[] cols = new SlotRegion[9];
for (int i = 0; i < indexColumns.length; i++) {
    cols[i] = new SlotRegion("crate_column-"+i, indexColumns[i]);
}
crate = new SlotRegion("crate", cols); // any Object... parameter can just be passed an array
playerInventory = new SlotRegion("player", armor, hotbar, mainInv);

Parameter order does matter, as this changes the searching order.

Now we need to tell the regions where the items should go when you shift-click in them. To do that we need to add a list of regions to search, in order of first searched to last searched.

mainInv.addShiftTargets(myChestRegion, hotbar);
hotbar.addShiftTargets(myChestRegion, mainInv);

myChestRegion.addShiftTargets(hotbar, mainInv);

These rules mean that when you shift-click on an item in the main inventory, it will try to go into the main chest inventory, and if it can't fit, it will try to go into the hotbar.

Also, if you shift-click on an item in the chest inventory, it will first try to go to the hotbar, and if that fails it will go to the player's main inventory.

To use these shiny new Slot Regions, you will override transferStackInSlot You did do this already right? You will crash when right-clicking if you don't override this method.

Simply call SlotRegion.shiftClick and pass it the container (this) the slot that was clicked, the player, and all of the regions.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
    return SlotRegion.shiftClick(this, slotIndex, player, mainInv, hotbar, myChestThing, myChestUpgradeSlot);
}
thecodewarrior commented 8 years ago

Also, this pull request has the polarity negator commit in it, that should be ignored if it's already been pulled, but in the future I'm going to have several branches off of master for all the separate parts I work on.

joekaiser commented 8 years ago

! You are on fire :)

I'm not home today and tomorrow, will get to this asap

joekaiser commented 8 years ago

Had a few extra minutes before I left. When I get back we should sync and divide the work so you aren't doing it all