use of com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable in project AgriCraft by AgriCraft.
the class MessageGuiSeedStorageClearSeed method processMessage.
@Override
protected void processMessage(MessageContext ctx) {
final Container container = this.player.openContainer;
if (container instanceof ContainerSeedStorageBase) {
final ContainerSeedStorageBase storage = ((ContainerSeedStorageBase) container);
final TileEntity tileEntity = storage.getTile();
if (tileEntity instanceof ISeedStorageControllable) {
((ISeedStorageControllable) tileEntity).clearLockedSeed();
}
}
}
use of com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable in project AgriCraft by AgriCraft.
the class ContainerSeedStorageBase method transferStackInSlot.
/**
* Handles shift clicking in the inventory, return the stack that was
* transferred
*/
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int clickedSlot) {
ItemStack originalStackInSlot = null;
Slot slot = this.inventorySlots.get(clickedSlot);
if (slot != null && slot.getHasStack()) {
ItemStack notMergedStack = slot.getStack();
originalStackInSlot = notMergedStack.copy();
//try to move item from the player's inventory into the container
AgriSeed seed = AgriApi.getSeedRegistry().valueOf(notMergedStack).orElse(null);
if (seed != null && seed.getStat().isAnalyzed()) {
ISeedStorageControllable controllable = this.getControllable(notMergedStack).orElse(null);
if (controllable != null && controllable.hasLockedSeed()) {
ItemStack locked = controllable.getLockedSeed().map(s -> s.toStack()).orElse(null);
if (notMergedStack.getItem() != locked.getItem() || notMergedStack.getItemDamage() != locked.getItemDamage()) {
return null;
}
}
if (this.addSeedToStorage(notMergedStack)) {
notMergedStack.stackSize = 0;
} else {
return null;
}
}
if (notMergedStack.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
if (notMergedStack.stackSize == originalStackInSlot.stackSize) {
return null;
}
slot.onPickupFromSlot(player, notMergedStack);
}
return originalStackInSlot;
}
use of com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable in project AgriCraft by AgriCraft.
the class ContainerSeedStorageBase method moveStackFromTileEntityToPlayer.
/**
* Tries to move an item stack form the correct tile entity to the player's
* inventory
*/
public void moveStackFromTileEntityToPlayer(int slotId, ItemStack stack) {
ISeedStorageControllable controllable = this.getControllable(stack).orElse(null);
if (controllable == null) {
return;
}
ItemStack stackToMove = controllable.getStackForSlotId(slotId);
if (stack == null) {
return;
}
if (stackToMove == null || stackToMove.getItem() == null) {
return;
}
stackToMove.stackSize = stack.stackSize > stackToMove.stackSize ? stackToMove.stackSize : stack.stackSize;
stackToMove.setTagCompound(controllable.getStackForSlotId(slotId).getTagCompound());
if (this.mergeItemStack(stackToMove, 0, PLAYER_INVENTORY_SIZE, false)) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
//this method is only called form the gui client side, so we need to manually tell the server to execute it there
new MessageContainerSeedStorage(stack, slotId).sendToServer();
} else {
//on the server decrease the size of the stack, where it is synced to the client
controllable.decreaseStackSizeInSlot(slotId, stack.stackSize - stackToMove.stackSize);
}
}
}
Aggregations